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>
89 #include "rust-lang.h"
90 #include "common/pathstuff.h"
92 /* When == 1, print basic high level tracing messages.
93 When > 1, be more verbose.
94 This is in contrast to the low level DIE reading of dwarf_die_debug. */
95 static unsigned int dwarf_read_debug
= 0;
97 /* When non-zero, dump DIEs after they are read in. */
98 static unsigned int dwarf_die_debug
= 0;
100 /* When non-zero, dump line number entries as they are read in. */
101 static unsigned int dwarf_line_debug
= 0;
103 /* When non-zero, cross-check physname against demangler. */
104 static int check_physname
= 0;
106 /* When non-zero, do not reject deprecated .gdb_index sections. */
107 static int use_deprecated_index_sections
= 0;
109 static const struct objfile_data
*dwarf2_objfile_data_key
;
111 /* The "aclass" indices for various kinds of computed DWARF symbols. */
113 static int dwarf2_locexpr_index
;
114 static int dwarf2_loclist_index
;
115 static int dwarf2_locexpr_block_index
;
116 static int dwarf2_loclist_block_index
;
118 /* A descriptor for dwarf sections.
120 S.ASECTION, SIZE are typically initialized when the objfile is first
121 scanned. BUFFER, READIN are filled in later when the section is read.
122 If the section contained compressed data then SIZE is updated to record
123 the uncompressed size of the section.
125 DWP file format V2 introduces a wrinkle that is easiest to handle by
126 creating the concept of virtual sections contained within a real section.
127 In DWP V2 the sections of the input DWO files are concatenated together
128 into one section, but section offsets are kept relative to the original
130 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
131 the real section this "virtual" section is contained in, and BUFFER,SIZE
132 describe the virtual section. */
134 struct dwarf2_section_info
138 /* If this is a real section, the bfd section. */
140 /* If this is a virtual section, pointer to the containing ("real")
142 struct dwarf2_section_info
*containing_section
;
144 /* Pointer to section data, only valid if readin. */
145 const gdb_byte
*buffer
;
146 /* The size of the section, real or virtual. */
148 /* If this is a virtual section, the offset in the real section.
149 Only valid if is_virtual. */
150 bfd_size_type virtual_offset
;
151 /* True if we have tried to read this section. */
153 /* True if this is a virtual section, False otherwise.
154 This specifies which of s.section and s.containing_section to use. */
158 typedef struct dwarf2_section_info dwarf2_section_info_def
;
159 DEF_VEC_O (dwarf2_section_info_def
);
161 /* All offsets in the index are of this type. It must be
162 architecture-independent. */
163 typedef uint32_t offset_type
;
165 DEF_VEC_I (offset_type
);
167 /* Ensure only legit values are used. */
168 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
170 gdb_assert ((unsigned int) (value) <= 1); \
171 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
174 /* Ensure only legit values are used. */
175 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
177 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
178 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
179 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
182 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
183 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
185 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
186 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
191 /* Convert VALUE between big- and little-endian. */
194 byte_swap (offset_type value
)
198 result
= (value
& 0xff) << 24;
199 result
|= (value
& 0xff00) << 8;
200 result
|= (value
& 0xff0000) >> 8;
201 result
|= (value
& 0xff000000) >> 24;
205 #define MAYBE_SWAP(V) byte_swap (V)
208 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
209 #endif /* WORDS_BIGENDIAN */
211 /* An index into a (C++) symbol name component in a symbol name as
212 recorded in the mapped_index's symbol table. For each C++ symbol
213 in the symbol table, we record one entry for the start of each
214 component in the symbol in a table of name components, and then
215 sort the table, in order to be able to binary search symbol names,
216 ignoring leading namespaces, both completion and regular look up.
217 For example, for symbol "A::B::C", we'll have an entry that points
218 to "A::B::C", another that points to "B::C", and another for "C".
219 Note that function symbols in GDB index have no parameter
220 information, just the function/method names. You can convert a
221 name_component to a "const char *" using the
222 'mapped_index::symbol_name_at(offset_type)' method. */
224 struct name_component
226 /* Offset in the symbol name where the component starts. Stored as
227 a (32-bit) offset instead of a pointer to save memory and improve
228 locality on 64-bit architectures. */
229 offset_type name_offset
;
231 /* The symbol's index in the symbol and constant pool tables of a
236 /* Base class containing bits shared by both .gdb_index and
237 .debug_name indexes. */
239 struct mapped_index_base
241 /* The name_component table (a sorted vector). See name_component's
242 description above. */
243 std::vector
<name_component
> name_components
;
245 /* How NAME_COMPONENTS is sorted. */
246 enum case_sensitivity name_components_casing
;
248 /* Return the number of names in the symbol table. */
249 virtual size_t symbol_name_count () const = 0;
251 /* Get the name of the symbol at IDX in the symbol table. */
252 virtual const char *symbol_name_at (offset_type idx
) const = 0;
254 /* Return whether the name at IDX in the symbol table should be
256 virtual bool symbol_name_slot_invalid (offset_type idx
) const
261 /* Build the symbol name component sorted vector, if we haven't
263 void build_name_components ();
265 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
266 possible matches for LN_NO_PARAMS in the name component
268 std::pair
<std::vector
<name_component
>::const_iterator
,
269 std::vector
<name_component
>::const_iterator
>
270 find_name_components_bounds (const lookup_name_info
&ln_no_params
) const;
272 /* Prevent deleting/destroying via a base class pointer. */
274 ~mapped_index_base() = default;
277 /* A description of the mapped index. The file format is described in
278 a comment by the code that writes the index. */
279 struct mapped_index final
: public mapped_index_base
281 /* A slot/bucket in the symbol table hash. */
282 struct symbol_table_slot
284 const offset_type name
;
285 const offset_type vec
;
288 /* Index data format version. */
291 /* The total length of the buffer. */
294 /* The address table data. */
295 gdb::array_view
<const gdb_byte
> address_table
;
297 /* The symbol table, implemented as a hash table. */
298 gdb::array_view
<symbol_table_slot
> symbol_table
;
300 /* A pointer to the constant pool. */
301 const char *constant_pool
;
303 bool symbol_name_slot_invalid (offset_type idx
) const override
305 const auto &bucket
= this->symbol_table
[idx
];
306 return bucket
.name
== 0 && bucket
.vec
;
309 /* Convenience method to get at the name of the symbol at IDX in the
311 const char *symbol_name_at (offset_type idx
) const override
312 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
314 size_t symbol_name_count () const override
315 { return this->symbol_table
.size (); }
318 /* A description of the mapped .debug_names.
319 Uninitialized map has CU_COUNT 0. */
320 struct mapped_debug_names final
: public mapped_index_base
322 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
323 : dwarf2_per_objfile (dwarf2_per_objfile_
)
326 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
327 bfd_endian dwarf5_byte_order
;
328 bool dwarf5_is_dwarf64
;
329 bool augmentation_is_gdb
;
331 uint32_t cu_count
= 0;
332 uint32_t tu_count
, bucket_count
, name_count
;
333 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
334 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
335 const gdb_byte
*name_table_string_offs_reordered
;
336 const gdb_byte
*name_table_entry_offs_reordered
;
337 const gdb_byte
*entry_pool
;
344 /* Attribute name DW_IDX_*. */
347 /* Attribute form DW_FORM_*. */
350 /* Value if FORM is DW_FORM_implicit_const. */
351 LONGEST implicit_const
;
353 std::vector
<attr
> attr_vec
;
356 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
358 const char *namei_to_name (uint32_t namei
) const;
360 /* Implementation of the mapped_index_base virtual interface, for
361 the name_components cache. */
363 const char *symbol_name_at (offset_type idx
) const override
364 { return namei_to_name (idx
); }
366 size_t symbol_name_count () const override
367 { return this->name_count
; }
370 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
371 DEF_VEC_P (dwarf2_per_cu_ptr
);
375 int nr_uniq_abbrev_tables
;
377 int nr_symtab_sharers
;
378 int nr_stmt_less_type_units
;
379 int nr_all_type_units_reallocs
;
382 /* Collection of data recorded per objfile.
383 This hangs off of dwarf2_objfile_data_key. */
385 struct dwarf2_per_objfile
: public allocate_on_obstack
387 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
388 dwarf2 section names, or is NULL if the standard ELF names are
390 dwarf2_per_objfile (struct objfile
*objfile
,
391 const dwarf2_debug_sections
*names
);
393 ~dwarf2_per_objfile ();
395 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
397 /* Free all cached compilation units. */
398 void free_cached_comp_units ();
400 /* This function is mapped across the sections and remembers the
401 offset and size of each of the debugging sections we are
403 void locate_sections (bfd
*abfd
, asection
*sectp
,
404 const dwarf2_debug_sections
&names
);
407 dwarf2_section_info info
{};
408 dwarf2_section_info abbrev
{};
409 dwarf2_section_info line
{};
410 dwarf2_section_info loc
{};
411 dwarf2_section_info loclists
{};
412 dwarf2_section_info macinfo
{};
413 dwarf2_section_info macro
{};
414 dwarf2_section_info str
{};
415 dwarf2_section_info line_str
{};
416 dwarf2_section_info ranges
{};
417 dwarf2_section_info rnglists
{};
418 dwarf2_section_info addr
{};
419 dwarf2_section_info frame
{};
420 dwarf2_section_info eh_frame
{};
421 dwarf2_section_info gdb_index
{};
422 dwarf2_section_info debug_names
{};
423 dwarf2_section_info debug_aranges
{};
425 VEC (dwarf2_section_info_def
) *types
= NULL
;
428 struct objfile
*objfile
= NULL
;
430 /* Table of all the compilation units. This is used to locate
431 the target compilation unit of a particular reference. */
432 struct dwarf2_per_cu_data
**all_comp_units
= NULL
;
434 /* The number of compilation units in ALL_COMP_UNITS. */
435 int n_comp_units
= 0;
437 /* The number of .debug_types-related CUs. */
438 int n_type_units
= 0;
440 /* The number of elements allocated in all_type_units.
441 If there are skeleton-less TUs, we add them to all_type_units lazily. */
442 int n_allocated_type_units
= 0;
444 /* The .debug_types-related CUs (TUs).
445 This is stored in malloc space because we may realloc it. */
446 struct signatured_type
**all_type_units
= NULL
;
448 /* Table of struct type_unit_group objects.
449 The hash key is the DW_AT_stmt_list value. */
450 htab_t type_unit_groups
{};
452 /* A table mapping .debug_types signatures to its signatured_type entry.
453 This is NULL if the .debug_types section hasn't been read in yet. */
454 htab_t signatured_types
{};
456 /* Type unit statistics, to see how well the scaling improvements
458 struct tu_stats tu_stats
{};
460 /* A chain of compilation units that are currently read in, so that
461 they can be freed later. */
462 dwarf2_per_cu_data
*read_in_chain
= NULL
;
464 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
465 This is NULL if the table hasn't been allocated yet. */
468 /* True if we've checked for whether there is a DWP file. */
469 bool dwp_checked
= false;
471 /* The DWP file if there is one, or NULL. */
472 struct dwp_file
*dwp_file
= NULL
;
474 /* The shared '.dwz' file, if one exists. This is used when the
475 original data was compressed using 'dwz -m'. */
476 struct dwz_file
*dwz_file
= NULL
;
478 /* A flag indicating whether this objfile has a section loaded at a
480 bool has_section_at_zero
= false;
482 /* True if we are using the mapped index,
483 or we are faking it for OBJF_READNOW's sake. */
484 bool using_index
= false;
486 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
487 mapped_index
*index_table
= NULL
;
489 /* The mapped index, or NULL if .debug_names is missing or not being used. */
490 std::unique_ptr
<mapped_debug_names
> debug_names_table
;
492 /* When using index_table, this keeps track of all quick_file_names entries.
493 TUs typically share line table entries with a CU, so we maintain a
494 separate table of all line table entries to support the sharing.
495 Note that while there can be way more TUs than CUs, we've already
496 sorted all the TUs into "type unit groups", grouped by their
497 DW_AT_stmt_list value. Therefore the only sharing done here is with a
498 CU and its associated TU group if there is one. */
499 htab_t quick_file_names_table
{};
501 /* Set during partial symbol reading, to prevent queueing of full
503 bool reading_partial_symbols
= false;
505 /* Table mapping type DIEs to their struct type *.
506 This is NULL if not allocated yet.
507 The mapping is done via (CU/TU + DIE offset) -> type. */
508 htab_t die_type_hash
{};
510 /* The CUs we recently read. */
511 VEC (dwarf2_per_cu_ptr
) *just_read_cus
= NULL
;
513 /* Table containing line_header indexed by offset and offset_in_dwz. */
514 htab_t line_header_hash
{};
516 /* Table containing all filenames. This is an optional because the
517 table is lazily constructed on first access. */
518 gdb::optional
<filename_seen_cache
> filenames_cache
;
521 /* Get the dwarf2_per_objfile associated to OBJFILE. */
523 struct dwarf2_per_objfile
*
524 get_dwarf2_per_objfile (struct objfile
*objfile
)
526 return ((struct dwarf2_per_objfile
*)
527 objfile_data (objfile
, dwarf2_objfile_data_key
));
530 /* Set the dwarf2_per_objfile associated to OBJFILE. */
533 set_dwarf2_per_objfile (struct objfile
*objfile
,
534 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
536 gdb_assert (get_dwarf2_per_objfile (objfile
) == NULL
);
537 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
540 /* Default names of the debugging sections. */
542 /* Note that if the debugging section has been compressed, it might
543 have a name like .zdebug_info. */
545 static const struct dwarf2_debug_sections dwarf2_elf_names
=
547 { ".debug_info", ".zdebug_info" },
548 { ".debug_abbrev", ".zdebug_abbrev" },
549 { ".debug_line", ".zdebug_line" },
550 { ".debug_loc", ".zdebug_loc" },
551 { ".debug_loclists", ".zdebug_loclists" },
552 { ".debug_macinfo", ".zdebug_macinfo" },
553 { ".debug_macro", ".zdebug_macro" },
554 { ".debug_str", ".zdebug_str" },
555 { ".debug_line_str", ".zdebug_line_str" },
556 { ".debug_ranges", ".zdebug_ranges" },
557 { ".debug_rnglists", ".zdebug_rnglists" },
558 { ".debug_types", ".zdebug_types" },
559 { ".debug_addr", ".zdebug_addr" },
560 { ".debug_frame", ".zdebug_frame" },
561 { ".eh_frame", NULL
},
562 { ".gdb_index", ".zgdb_index" },
563 { ".debug_names", ".zdebug_names" },
564 { ".debug_aranges", ".zdebug_aranges" },
568 /* List of DWO/DWP sections. */
570 static const struct dwop_section_names
572 struct dwarf2_section_names abbrev_dwo
;
573 struct dwarf2_section_names info_dwo
;
574 struct dwarf2_section_names line_dwo
;
575 struct dwarf2_section_names loc_dwo
;
576 struct dwarf2_section_names loclists_dwo
;
577 struct dwarf2_section_names macinfo_dwo
;
578 struct dwarf2_section_names macro_dwo
;
579 struct dwarf2_section_names str_dwo
;
580 struct dwarf2_section_names str_offsets_dwo
;
581 struct dwarf2_section_names types_dwo
;
582 struct dwarf2_section_names cu_index
;
583 struct dwarf2_section_names tu_index
;
587 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
588 { ".debug_info.dwo", ".zdebug_info.dwo" },
589 { ".debug_line.dwo", ".zdebug_line.dwo" },
590 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
591 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
592 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
593 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
594 { ".debug_str.dwo", ".zdebug_str.dwo" },
595 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
596 { ".debug_types.dwo", ".zdebug_types.dwo" },
597 { ".debug_cu_index", ".zdebug_cu_index" },
598 { ".debug_tu_index", ".zdebug_tu_index" },
601 /* local data types */
603 /* The data in a compilation unit header, after target2host
604 translation, looks like this. */
605 struct comp_unit_head
609 unsigned char addr_size
;
610 unsigned char signed_addr_p
;
611 sect_offset abbrev_sect_off
;
613 /* Size of file offsets; either 4 or 8. */
614 unsigned int offset_size
;
616 /* Size of the length field; either 4 or 12. */
617 unsigned int initial_length_size
;
619 enum dwarf_unit_type unit_type
;
621 /* Offset to the first byte of this compilation unit header in the
622 .debug_info section, for resolving relative reference dies. */
623 sect_offset sect_off
;
625 /* Offset to first die in this cu from the start of the cu.
626 This will be the first byte following the compilation unit header. */
627 cu_offset first_die_cu_offset
;
629 /* 64-bit signature of this type unit - it is valid only for
630 UNIT_TYPE DW_UT_type. */
633 /* For types, offset in the type's DIE of the type defined by this TU. */
634 cu_offset type_cu_offset_in_tu
;
637 /* Type used for delaying computation of method physnames.
638 See comments for compute_delayed_physnames. */
639 struct delayed_method_info
641 /* The type to which the method is attached, i.e., its parent class. */
644 /* The index of the method in the type's function fieldlists. */
647 /* The index of the method in the fieldlist. */
650 /* The name of the DIE. */
653 /* The DIE associated with this method. */
654 struct die_info
*die
;
657 /* Internal state when decoding a particular compilation unit. */
660 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
663 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
665 /* The header of the compilation unit. */
666 struct comp_unit_head header
{};
668 /* Base address of this compilation unit. */
669 CORE_ADDR base_address
= 0;
671 /* Non-zero if base_address has been set. */
674 /* The language we are debugging. */
675 enum language language
= language_unknown
;
676 const struct language_defn
*language_defn
= nullptr;
678 const char *producer
= nullptr;
680 /* The generic symbol table building routines have separate lists for
681 file scope symbols and all all other scopes (local scopes). So
682 we need to select the right one to pass to add_symbol_to_list().
683 We do it by keeping a pointer to the correct list in list_in_scope.
685 FIXME: The original dwarf code just treated the file scope as the
686 first local scope, and all other local scopes as nested local
687 scopes, and worked fine. Check to see if we really need to
688 distinguish these in buildsym.c. */
689 struct pending
**list_in_scope
= nullptr;
691 /* Hash table holding all the loaded partial DIEs
692 with partial_die->offset.SECT_OFF as hash. */
693 htab_t partial_dies
= nullptr;
695 /* Storage for things with the same lifetime as this read-in compilation
696 unit, including partial DIEs. */
697 auto_obstack comp_unit_obstack
;
699 /* When multiple dwarf2_cu structures are living in memory, this field
700 chains them all together, so that they can be released efficiently.
701 We will probably also want a generation counter so that most-recently-used
702 compilation units are cached... */
703 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
705 /* Backlink to our per_cu entry. */
706 struct dwarf2_per_cu_data
*per_cu
;
708 /* How many compilation units ago was this CU last referenced? */
711 /* A hash table of DIE cu_offset for following references with
712 die_info->offset.sect_off as hash. */
713 htab_t die_hash
= nullptr;
715 /* Full DIEs if read in. */
716 struct die_info
*dies
= nullptr;
718 /* A set of pointers to dwarf2_per_cu_data objects for compilation
719 units referenced by this one. Only set during full symbol processing;
720 partial symbol tables do not have dependencies. */
721 htab_t dependencies
= nullptr;
723 /* Header data from the line table, during full symbol processing. */
724 struct line_header
*line_header
= nullptr;
725 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
726 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
727 this is the DW_TAG_compile_unit die for this CU. We'll hold on
728 to the line header as long as this DIE is being processed. See
729 process_die_scope. */
730 die_info
*line_header_die_owner
= nullptr;
732 /* A list of methods which need to have physnames computed
733 after all type information has been read. */
734 std::vector
<delayed_method_info
> method_list
;
736 /* To be copied to symtab->call_site_htab. */
737 htab_t call_site_htab
= nullptr;
739 /* Non-NULL if this CU came from a DWO file.
740 There is an invariant here that is important to remember:
741 Except for attributes copied from the top level DIE in the "main"
742 (or "stub") file in preparation for reading the DWO file
743 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
744 Either there isn't a DWO file (in which case this is NULL and the point
745 is moot), or there is and either we're not going to read it (in which
746 case this is NULL) or there is and we are reading it (in which case this
748 struct dwo_unit
*dwo_unit
= nullptr;
750 /* The DW_AT_addr_base attribute if present, zero otherwise
751 (zero is a valid value though).
752 Note this value comes from the Fission stub CU/TU's DIE. */
753 ULONGEST addr_base
= 0;
755 /* The DW_AT_ranges_base attribute if present, zero otherwise
756 (zero is a valid value though).
757 Note this value comes from the Fission stub CU/TU's DIE.
758 Also note that the value is zero in the non-DWO case so this value can
759 be used without needing to know whether DWO files are in use or not.
760 N.B. This does not apply to DW_AT_ranges appearing in
761 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
762 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
763 DW_AT_ranges_base *would* have to be applied, and we'd have to care
764 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
765 ULONGEST ranges_base
= 0;
767 /* When reading debug info generated by older versions of rustc, we
768 have to rewrite some union types to be struct types with a
769 variant part. This rewriting must be done after the CU is fully
770 read in, because otherwise at the point of rewriting some struct
771 type might not have been fully processed. So, we keep a list of
772 all such types here and process them after expansion. */
773 std::vector
<struct type
*> rust_unions
;
775 /* Mark used when releasing cached dies. */
776 unsigned int mark
: 1;
778 /* This CU references .debug_loc. See the symtab->locations_valid field.
779 This test is imperfect as there may exist optimized debug code not using
780 any location list and still facing inlining issues if handled as
781 unoptimized code. For a future better test see GCC PR other/32998. */
782 unsigned int has_loclist
: 1;
784 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
785 if all the producer_is_* fields are valid. This information is cached
786 because profiling CU expansion showed excessive time spent in
787 producer_is_gxx_lt_4_6. */
788 unsigned int checked_producer
: 1;
789 unsigned int producer_is_gxx_lt_4_6
: 1;
790 unsigned int producer_is_gcc_lt_4_3
: 1;
791 unsigned int producer_is_icc_lt_14
: 1;
793 /* When set, the file that we're processing is known to have
794 debugging info for C++ namespaces. GCC 3.3.x did not produce
795 this information, but later versions do. */
797 unsigned int processing_has_namespace_info
: 1;
799 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
802 /* Persistent data held for a compilation unit, even when not
803 processing it. We put a pointer to this structure in the
804 read_symtab_private field of the psymtab. */
806 struct dwarf2_per_cu_data
808 /* The start offset and length of this compilation unit.
809 NOTE: Unlike comp_unit_head.length, this length includes
811 If the DIE refers to a DWO file, this is always of the original die,
813 sect_offset sect_off
;
816 /* DWARF standard version this data has been read from (such as 4 or 5). */
819 /* Flag indicating this compilation unit will be read in before
820 any of the current compilation units are processed. */
821 unsigned int queued
: 1;
823 /* This flag will be set when reading partial DIEs if we need to load
824 absolutely all DIEs for this compilation unit, instead of just the ones
825 we think are interesting. It gets set if we look for a DIE in the
826 hash table and don't find it. */
827 unsigned int load_all_dies
: 1;
829 /* Non-zero if this CU is from .debug_types.
830 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
832 unsigned int is_debug_types
: 1;
834 /* Non-zero if this CU is from the .dwz file. */
835 unsigned int is_dwz
: 1;
837 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
838 This flag is only valid if is_debug_types is true.
839 We can't read a CU directly from a DWO file: There are required
840 attributes in the stub. */
841 unsigned int reading_dwo_directly
: 1;
843 /* Non-zero if the TU has been read.
844 This is used to assist the "Stay in DWO Optimization" for Fission:
845 When reading a DWO, it's faster to read TUs from the DWO instead of
846 fetching them from random other DWOs (due to comdat folding).
847 If the TU has already been read, the optimization is unnecessary
848 (and unwise - we don't want to change where gdb thinks the TU lives
850 This flag is only valid if is_debug_types is true. */
851 unsigned int tu_read
: 1;
853 /* The section this CU/TU lives in.
854 If the DIE refers to a DWO file, this is always the original die,
856 struct dwarf2_section_info
*section
;
858 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
859 of the CU cache it gets reset to NULL again. This is left as NULL for
860 dummy CUs (a CU header, but nothing else). */
861 struct dwarf2_cu
*cu
;
863 /* The corresponding dwarf2_per_objfile. */
864 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
866 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
867 is active. Otherwise, the 'psymtab' field is active. */
870 /* The partial symbol table associated with this compilation unit,
871 or NULL for unread partial units. */
872 struct partial_symtab
*psymtab
;
874 /* Data needed by the "quick" functions. */
875 struct dwarf2_per_cu_quick_data
*quick
;
878 /* The CUs we import using DW_TAG_imported_unit. This is filled in
879 while reading psymtabs, used to compute the psymtab dependencies,
880 and then cleared. Then it is filled in again while reading full
881 symbols, and only deleted when the objfile is destroyed.
883 This is also used to work around a difference between the way gold
884 generates .gdb_index version <=7 and the way gdb does. Arguably this
885 is a gold bug. For symbols coming from TUs, gold records in the index
886 the CU that includes the TU instead of the TU itself. This breaks
887 dw2_lookup_symbol: It assumes that if the index says symbol X lives
888 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
889 will find X. Alas TUs live in their own symtab, so after expanding CU Y
890 we need to look in TU Z to find X. Fortunately, this is akin to
891 DW_TAG_imported_unit, so we just use the same mechanism: For
892 .gdb_index version <=7 this also records the TUs that the CU referred
893 to. Concurrently with this change gdb was modified to emit version 8
894 indices so we only pay a price for gold generated indices.
895 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
896 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
899 /* Entry in the signatured_types hash table. */
901 struct signatured_type
903 /* The "per_cu" object of this type.
904 This struct is used iff per_cu.is_debug_types.
905 N.B.: This is the first member so that it's easy to convert pointers
907 struct dwarf2_per_cu_data per_cu
;
909 /* The type's signature. */
912 /* Offset in the TU of the type's DIE, as read from the TU header.
913 If this TU is a DWO stub and the definition lives in a DWO file
914 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
915 cu_offset type_offset_in_tu
;
917 /* Offset in the section of the type's DIE.
918 If the definition lives in a DWO file, this is the offset in the
919 .debug_types.dwo section.
920 The value is zero until the actual value is known.
921 Zero is otherwise not a valid section offset. */
922 sect_offset type_offset_in_section
;
924 /* Type units are grouped by their DW_AT_stmt_list entry so that they
925 can share them. This points to the containing symtab. */
926 struct type_unit_group
*type_unit_group
;
929 The first time we encounter this type we fully read it in and install it
930 in the symbol tables. Subsequent times we only need the type. */
933 /* Containing DWO unit.
934 This field is valid iff per_cu.reading_dwo_directly. */
935 struct dwo_unit
*dwo_unit
;
938 typedef struct signatured_type
*sig_type_ptr
;
939 DEF_VEC_P (sig_type_ptr
);
941 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
942 This includes type_unit_group and quick_file_names. */
944 struct stmt_list_hash
946 /* The DWO unit this table is from or NULL if there is none. */
947 struct dwo_unit
*dwo_unit
;
949 /* Offset in .debug_line or .debug_line.dwo. */
950 sect_offset line_sect_off
;
953 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
954 an object of this type. */
956 struct type_unit_group
958 /* dwarf2read.c's main "handle" on a TU symtab.
959 To simplify things we create an artificial CU that "includes" all the
960 type units using this stmt_list so that the rest of the code still has
961 a "per_cu" handle on the symtab.
962 This PER_CU is recognized by having no section. */
963 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
964 struct dwarf2_per_cu_data per_cu
;
966 /* The TUs that share this DW_AT_stmt_list entry.
967 This is added to while parsing type units to build partial symtabs,
968 and is deleted afterwards and not used again. */
969 VEC (sig_type_ptr
) *tus
;
971 /* The compunit symtab.
972 Type units in a group needn't all be defined in the same source file,
973 so we create an essentially anonymous symtab as the compunit symtab. */
974 struct compunit_symtab
*compunit_symtab
;
976 /* The data used to construct the hash key. */
977 struct stmt_list_hash hash
;
979 /* The number of symtabs from the line header.
980 The value here must match line_header.num_file_names. */
981 unsigned int num_symtabs
;
983 /* The symbol tables for this TU (obtained from the files listed in
985 WARNING: The order of entries here must match the order of entries
986 in the line header. After the first TU using this type_unit_group, the
987 line header for the subsequent TUs is recreated from this. This is done
988 because we need to use the same symtabs for each TU using the same
989 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
990 there's no guarantee the line header doesn't have duplicate entries. */
991 struct symtab
**symtabs
;
994 /* These sections are what may appear in a (real or virtual) DWO file. */
998 struct dwarf2_section_info abbrev
;
999 struct dwarf2_section_info line
;
1000 struct dwarf2_section_info loc
;
1001 struct dwarf2_section_info loclists
;
1002 struct dwarf2_section_info macinfo
;
1003 struct dwarf2_section_info macro
;
1004 struct dwarf2_section_info str
;
1005 struct dwarf2_section_info str_offsets
;
1006 /* In the case of a virtual DWO file, these two are unused. */
1007 struct dwarf2_section_info info
;
1008 VEC (dwarf2_section_info_def
) *types
;
1011 /* CUs/TUs in DWP/DWO files. */
1015 /* Backlink to the containing struct dwo_file. */
1016 struct dwo_file
*dwo_file
;
1018 /* The "id" that distinguishes this CU/TU.
1019 .debug_info calls this "dwo_id", .debug_types calls this "signature".
1020 Since signatures came first, we stick with it for consistency. */
1023 /* The section this CU/TU lives in, in the DWO file. */
1024 struct dwarf2_section_info
*section
;
1026 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
1027 sect_offset sect_off
;
1028 unsigned int length
;
1030 /* For types, offset in the type's DIE of the type defined by this TU. */
1031 cu_offset type_offset_in_tu
;
1034 /* include/dwarf2.h defines the DWP section codes.
1035 It defines a max value but it doesn't define a min value, which we
1036 use for error checking, so provide one. */
1038 enum dwp_v2_section_ids
1043 /* Data for one DWO file.
1045 This includes virtual DWO files (a virtual DWO file is a DWO file as it
1046 appears in a DWP file). DWP files don't really have DWO files per se -
1047 comdat folding of types "loses" the DWO file they came from, and from
1048 a high level view DWP files appear to contain a mass of random types.
1049 However, to maintain consistency with the non-DWP case we pretend DWP
1050 files contain virtual DWO files, and we assign each TU with one virtual
1051 DWO file (generally based on the line and abbrev section offsets -
1052 a heuristic that seems to work in practice). */
1056 /* The DW_AT_GNU_dwo_name attribute.
1057 For virtual DWO files the name is constructed from the section offsets
1058 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
1059 from related CU+TUs. */
1060 const char *dwo_name
;
1062 /* The DW_AT_comp_dir attribute. */
1063 const char *comp_dir
;
1065 /* The bfd, when the file is open. Otherwise this is NULL.
1066 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
1069 /* The sections that make up this DWO file.
1070 Remember that for virtual DWO files in DWP V2, these are virtual
1071 sections (for lack of a better name). */
1072 struct dwo_sections sections
;
1074 /* The CUs in the file.
1075 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
1076 an extension to handle LLVM's Link Time Optimization output (where
1077 multiple source files may be compiled into a single object/dwo pair). */
1080 /* Table of TUs in the file.
1081 Each element is a struct dwo_unit. */
1085 /* These sections are what may appear in a DWP file. */
1089 /* These are used by both DWP version 1 and 2. */
1090 struct dwarf2_section_info str
;
1091 struct dwarf2_section_info cu_index
;
1092 struct dwarf2_section_info tu_index
;
1094 /* These are only used by DWP version 2 files.
1095 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
1096 sections are referenced by section number, and are not recorded here.
1097 In DWP version 2 there is at most one copy of all these sections, each
1098 section being (effectively) comprised of the concatenation of all of the
1099 individual sections that exist in the version 1 format.
1100 To keep the code simple we treat each of these concatenated pieces as a
1101 section itself (a virtual section?). */
1102 struct dwarf2_section_info abbrev
;
1103 struct dwarf2_section_info info
;
1104 struct dwarf2_section_info line
;
1105 struct dwarf2_section_info loc
;
1106 struct dwarf2_section_info macinfo
;
1107 struct dwarf2_section_info macro
;
1108 struct dwarf2_section_info str_offsets
;
1109 struct dwarf2_section_info types
;
1112 /* These sections are what may appear in a virtual DWO file in DWP version 1.
1113 A virtual DWO file is a DWO file as it appears in a DWP file. */
1115 struct virtual_v1_dwo_sections
1117 struct dwarf2_section_info abbrev
;
1118 struct dwarf2_section_info line
;
1119 struct dwarf2_section_info loc
;
1120 struct dwarf2_section_info macinfo
;
1121 struct dwarf2_section_info macro
;
1122 struct dwarf2_section_info str_offsets
;
1123 /* Each DWP hash table entry records one CU or one TU.
1124 That is recorded here, and copied to dwo_unit.section. */
1125 struct dwarf2_section_info info_or_types
;
1128 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
1129 In version 2, the sections of the DWO files are concatenated together
1130 and stored in one section of that name. Thus each ELF section contains
1131 several "virtual" sections. */
1133 struct virtual_v2_dwo_sections
1135 bfd_size_type abbrev_offset
;
1136 bfd_size_type abbrev_size
;
1138 bfd_size_type line_offset
;
1139 bfd_size_type line_size
;
1141 bfd_size_type loc_offset
;
1142 bfd_size_type loc_size
;
1144 bfd_size_type macinfo_offset
;
1145 bfd_size_type macinfo_size
;
1147 bfd_size_type macro_offset
;
1148 bfd_size_type macro_size
;
1150 bfd_size_type str_offsets_offset
;
1151 bfd_size_type str_offsets_size
;
1153 /* Each DWP hash table entry records one CU or one TU.
1154 That is recorded here, and copied to dwo_unit.section. */
1155 bfd_size_type info_or_types_offset
;
1156 bfd_size_type info_or_types_size
;
1159 /* Contents of DWP hash tables. */
1161 struct dwp_hash_table
1163 uint32_t version
, nr_columns
;
1164 uint32_t nr_units
, nr_slots
;
1165 const gdb_byte
*hash_table
, *unit_table
;
1170 const gdb_byte
*indices
;
1174 /* This is indexed by column number and gives the id of the section
1176 #define MAX_NR_V2_DWO_SECTIONS \
1177 (1 /* .debug_info or .debug_types */ \
1178 + 1 /* .debug_abbrev */ \
1179 + 1 /* .debug_line */ \
1180 + 1 /* .debug_loc */ \
1181 + 1 /* .debug_str_offsets */ \
1182 + 1 /* .debug_macro or .debug_macinfo */)
1183 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
1184 const gdb_byte
*offsets
;
1185 const gdb_byte
*sizes
;
1190 /* Data for one DWP file. */
1194 /* Name of the file. */
1197 /* File format version. */
1203 /* Section info for this file. */
1204 struct dwp_sections sections
;
1206 /* Table of CUs in the file. */
1207 const struct dwp_hash_table
*cus
;
1209 /* Table of TUs in the file. */
1210 const struct dwp_hash_table
*tus
;
1212 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1216 /* Table to map ELF section numbers to their sections.
1217 This is only needed for the DWP V1 file format. */
1218 unsigned int num_sections
;
1219 asection
**elf_sections
;
1222 /* This represents a '.dwz' file. */
1226 /* A dwz file can only contain a few sections. */
1227 struct dwarf2_section_info abbrev
;
1228 struct dwarf2_section_info info
;
1229 struct dwarf2_section_info str
;
1230 struct dwarf2_section_info line
;
1231 struct dwarf2_section_info macro
;
1232 struct dwarf2_section_info gdb_index
;
1233 struct dwarf2_section_info debug_names
;
1235 /* The dwz's BFD. */
1239 /* Struct used to pass misc. parameters to read_die_and_children, et
1240 al. which are used for both .debug_info and .debug_types dies.
1241 All parameters here are unchanging for the life of the call. This
1242 struct exists to abstract away the constant parameters of die reading. */
1244 struct die_reader_specs
1246 /* The bfd of die_section. */
1249 /* The CU of the DIE we are parsing. */
1250 struct dwarf2_cu
*cu
;
1252 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1253 struct dwo_file
*dwo_file
;
1255 /* The section the die comes from.
1256 This is either .debug_info or .debug_types, or the .dwo variants. */
1257 struct dwarf2_section_info
*die_section
;
1259 /* die_section->buffer. */
1260 const gdb_byte
*buffer
;
1262 /* The end of the buffer. */
1263 const gdb_byte
*buffer_end
;
1265 /* The value of the DW_AT_comp_dir attribute. */
1266 const char *comp_dir
;
1268 /* The abbreviation table to use when reading the DIEs. */
1269 struct abbrev_table
*abbrev_table
;
1272 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1273 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1274 const gdb_byte
*info_ptr
,
1275 struct die_info
*comp_unit_die
,
1279 /* A 1-based directory index. This is a strong typedef to prevent
1280 accidentally using a directory index as a 0-based index into an
1282 enum class dir_index
: unsigned int {};
1284 /* Likewise, a 1-based file name index. */
1285 enum class file_name_index
: unsigned int {};
1289 file_entry () = default;
1291 file_entry (const char *name_
, dir_index d_index_
,
1292 unsigned int mod_time_
, unsigned int length_
)
1295 mod_time (mod_time_
),
1299 /* Return the include directory at D_INDEX stored in LH. Returns
1300 NULL if D_INDEX is out of bounds. */
1301 const char *include_dir (const line_header
*lh
) const;
1303 /* The file name. Note this is an observing pointer. The memory is
1304 owned by debug_line_buffer. */
1305 const char *name
{};
1307 /* The directory index (1-based). */
1308 dir_index d_index
{};
1310 unsigned int mod_time
{};
1312 unsigned int length
{};
1314 /* True if referenced by the Line Number Program. */
1317 /* The associated symbol table, if any. */
1318 struct symtab
*symtab
{};
1321 /* The line number information for a compilation unit (found in the
1322 .debug_line section) begins with a "statement program header",
1323 which contains the following information. */
1330 /* Add an entry to the include directory table. */
1331 void add_include_dir (const char *include_dir
);
1333 /* Add an entry to the file name table. */
1334 void add_file_name (const char *name
, dir_index d_index
,
1335 unsigned int mod_time
, unsigned int length
);
1337 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1338 is out of bounds. */
1339 const char *include_dir_at (dir_index index
) const
1341 /* Convert directory index number (1-based) to vector index
1343 size_t vec_index
= to_underlying (index
) - 1;
1345 if (vec_index
>= include_dirs
.size ())
1347 return include_dirs
[vec_index
];
1350 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1351 is out of bounds. */
1352 file_entry
*file_name_at (file_name_index index
)
1354 /* Convert file name index number (1-based) to vector index
1356 size_t vec_index
= to_underlying (index
) - 1;
1358 if (vec_index
>= file_names
.size ())
1360 return &file_names
[vec_index
];
1363 /* Const version of the above. */
1364 const file_entry
*file_name_at (unsigned int index
) const
1366 if (index
>= file_names
.size ())
1368 return &file_names
[index
];
1371 /* Offset of line number information in .debug_line section. */
1372 sect_offset sect_off
{};
1374 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1375 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1377 unsigned int total_length
{};
1378 unsigned short version
{};
1379 unsigned int header_length
{};
1380 unsigned char minimum_instruction_length
{};
1381 unsigned char maximum_ops_per_instruction
{};
1382 unsigned char default_is_stmt
{};
1384 unsigned char line_range
{};
1385 unsigned char opcode_base
{};
1387 /* standard_opcode_lengths[i] is the number of operands for the
1388 standard opcode whose value is i. This means that
1389 standard_opcode_lengths[0] is unused, and the last meaningful
1390 element is standard_opcode_lengths[opcode_base - 1]. */
1391 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1393 /* The include_directories table. Note these are observing
1394 pointers. The memory is owned by debug_line_buffer. */
1395 std::vector
<const char *> include_dirs
;
1397 /* The file_names table. */
1398 std::vector
<file_entry
> file_names
;
1400 /* The start and end of the statement program following this
1401 header. These point into dwarf2_per_objfile->line_buffer. */
1402 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1405 typedef std::unique_ptr
<line_header
> line_header_up
;
1408 file_entry::include_dir (const line_header
*lh
) const
1410 return lh
->include_dir_at (d_index
);
1413 /* When we construct a partial symbol table entry we only
1414 need this much information. */
1415 struct partial_die_info
: public allocate_on_obstack
1417 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1419 /* Disable assign but still keep copy ctor, which is needed
1420 load_partial_dies. */
1421 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1423 /* Adjust the partial die before generating a symbol for it. This
1424 function may set the is_external flag or change the DIE's
1426 void fixup (struct dwarf2_cu
*cu
);
1428 /* Read a minimal amount of information into the minimal die
1430 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1431 const struct abbrev_info
&abbrev
,
1432 const gdb_byte
*info_ptr
);
1434 /* Offset of this DIE. */
1435 const sect_offset sect_off
;
1437 /* DWARF-2 tag for this DIE. */
1438 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1440 /* Assorted flags describing the data found in this DIE. */
1441 const unsigned int has_children
: 1;
1443 unsigned int is_external
: 1;
1444 unsigned int is_declaration
: 1;
1445 unsigned int has_type
: 1;
1446 unsigned int has_specification
: 1;
1447 unsigned int has_pc_info
: 1;
1448 unsigned int may_be_inlined
: 1;
1450 /* This DIE has been marked DW_AT_main_subprogram. */
1451 unsigned int main_subprogram
: 1;
1453 /* Flag set if the SCOPE field of this structure has been
1455 unsigned int scope_set
: 1;
1457 /* Flag set if the DIE has a byte_size attribute. */
1458 unsigned int has_byte_size
: 1;
1460 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1461 unsigned int has_const_value
: 1;
1463 /* Flag set if any of the DIE's children are template arguments. */
1464 unsigned int has_template_arguments
: 1;
1466 /* Flag set if fixup has been called on this die. */
1467 unsigned int fixup_called
: 1;
1469 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1470 unsigned int is_dwz
: 1;
1472 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1473 unsigned int spec_is_dwz
: 1;
1475 /* The name of this DIE. Normally the value of DW_AT_name, but
1476 sometimes a default name for unnamed DIEs. */
1477 const char *name
= nullptr;
1479 /* The linkage name, if present. */
1480 const char *linkage_name
= nullptr;
1482 /* The scope to prepend to our children. This is generally
1483 allocated on the comp_unit_obstack, so will disappear
1484 when this compilation unit leaves the cache. */
1485 const char *scope
= nullptr;
1487 /* Some data associated with the partial DIE. The tag determines
1488 which field is live. */
1491 /* The location description associated with this DIE, if any. */
1492 struct dwarf_block
*locdesc
;
1493 /* The offset of an import, for DW_TAG_imported_unit. */
1494 sect_offset sect_off
;
1497 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1498 CORE_ADDR lowpc
= 0;
1499 CORE_ADDR highpc
= 0;
1501 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1502 DW_AT_sibling, if any. */
1503 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1504 could return DW_AT_sibling values to its caller load_partial_dies. */
1505 const gdb_byte
*sibling
= nullptr;
1507 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1508 DW_AT_specification (or DW_AT_abstract_origin or
1509 DW_AT_extension). */
1510 sect_offset spec_offset
{};
1512 /* Pointers to this DIE's parent, first child, and next sibling,
1514 struct partial_die_info
*die_parent
= nullptr;
1515 struct partial_die_info
*die_child
= nullptr;
1516 struct partial_die_info
*die_sibling
= nullptr;
1518 friend struct partial_die_info
*
1519 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1522 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1523 partial_die_info (sect_offset sect_off
)
1524 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1528 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1530 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1535 has_specification
= 0;
1538 main_subprogram
= 0;
1541 has_const_value
= 0;
1542 has_template_arguments
= 0;
1549 /* This data structure holds the information of an abbrev. */
1552 unsigned int number
; /* number identifying abbrev */
1553 enum dwarf_tag tag
; /* dwarf tag */
1554 unsigned short has_children
; /* boolean */
1555 unsigned short num_attrs
; /* number of attributes */
1556 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1557 struct abbrev_info
*next
; /* next in chain */
1562 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1563 ENUM_BITFIELD(dwarf_form
) form
: 16;
1565 /* It is valid only if FORM is DW_FORM_implicit_const. */
1566 LONGEST implicit_const
;
1569 /* Size of abbrev_table.abbrev_hash_table. */
1570 #define ABBREV_HASH_SIZE 121
1572 /* Top level data structure to contain an abbreviation table. */
1576 explicit abbrev_table (sect_offset off
)
1580 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1581 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1584 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1586 /* Allocate space for a struct abbrev_info object in
1588 struct abbrev_info
*alloc_abbrev ();
1590 /* Add an abbreviation to the table. */
1591 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1593 /* Look up an abbrev in the table.
1594 Returns NULL if the abbrev is not found. */
1596 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1599 /* Where the abbrev table came from.
1600 This is used as a sanity check when the table is used. */
1601 const sect_offset sect_off
;
1603 /* Storage for the abbrev table. */
1604 auto_obstack abbrev_obstack
;
1608 /* Hash table of abbrevs.
1609 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1610 It could be statically allocated, but the previous code didn't so we
1612 struct abbrev_info
**m_abbrevs
;
1615 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1617 /* Attributes have a name and a value. */
1620 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1621 ENUM_BITFIELD(dwarf_form
) form
: 15;
1623 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1624 field should be in u.str (existing only for DW_STRING) but it is kept
1625 here for better struct attribute alignment. */
1626 unsigned int string_is_canonical
: 1;
1631 struct dwarf_block
*blk
;
1640 /* This data structure holds a complete die structure. */
1643 /* DWARF-2 tag for this DIE. */
1644 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1646 /* Number of attributes */
1647 unsigned char num_attrs
;
1649 /* True if we're presently building the full type name for the
1650 type derived from this DIE. */
1651 unsigned char building_fullname
: 1;
1653 /* True if this die is in process. PR 16581. */
1654 unsigned char in_process
: 1;
1657 unsigned int abbrev
;
1659 /* Offset in .debug_info or .debug_types section. */
1660 sect_offset sect_off
;
1662 /* The dies in a compilation unit form an n-ary tree. PARENT
1663 points to this die's parent; CHILD points to the first child of
1664 this node; and all the children of a given node are chained
1665 together via their SIBLING fields. */
1666 struct die_info
*child
; /* Its first child, if any. */
1667 struct die_info
*sibling
; /* Its next sibling, if any. */
1668 struct die_info
*parent
; /* Its parent, if any. */
1670 /* An array of attributes, with NUM_ATTRS elements. There may be
1671 zero, but it's not common and zero-sized arrays are not
1672 sufficiently portable C. */
1673 struct attribute attrs
[1];
1676 /* Get at parts of an attribute structure. */
1678 #define DW_STRING(attr) ((attr)->u.str)
1679 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1680 #define DW_UNSND(attr) ((attr)->u.unsnd)
1681 #define DW_BLOCK(attr) ((attr)->u.blk)
1682 #define DW_SND(attr) ((attr)->u.snd)
1683 #define DW_ADDR(attr) ((attr)->u.addr)
1684 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1686 /* Blocks are a bunch of untyped bytes. */
1691 /* Valid only if SIZE is not zero. */
1692 const gdb_byte
*data
;
1695 #ifndef ATTR_ALLOC_CHUNK
1696 #define ATTR_ALLOC_CHUNK 4
1699 /* Allocate fields for structs, unions and enums in this size. */
1700 #ifndef DW_FIELD_ALLOC_CHUNK
1701 #define DW_FIELD_ALLOC_CHUNK 4
1704 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1705 but this would require a corresponding change in unpack_field_as_long
1707 static int bits_per_byte
= 8;
1709 /* When reading a variant or variant part, we track a bit more
1710 information about the field, and store it in an object of this
1713 struct variant_field
1715 /* If we see a DW_TAG_variant, then this will be the discriminant
1717 ULONGEST discriminant_value
;
1718 /* If we see a DW_TAG_variant, then this will be set if this is the
1720 bool default_branch
;
1721 /* While reading a DW_TAG_variant_part, this will be set if this
1722 field is the discriminant. */
1723 bool is_discriminant
;
1728 int accessibility
= 0;
1730 /* Extra information to describe a variant or variant part. */
1731 struct variant_field variant
{};
1732 struct field field
{};
1737 const char *name
= nullptr;
1738 std::vector
<struct fn_field
> fnfields
;
1741 /* The routines that read and process dies for a C struct or C++ class
1742 pass lists of data member fields and lists of member function fields
1743 in an instance of a field_info structure, as defined below. */
1746 /* List of data member and baseclasses fields. */
1747 std::vector
<struct nextfield
> fields
;
1748 std::vector
<struct nextfield
> baseclasses
;
1750 /* Number of fields (including baseclasses). */
1753 /* Set if the accesibility of one of the fields is not public. */
1754 int non_public_fields
= 0;
1756 /* Member function fieldlist array, contains name of possibly overloaded
1757 member function, number of overloaded member functions and a pointer
1758 to the head of the member function field chain. */
1759 std::vector
<struct fnfieldlist
> fnfieldlists
;
1761 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1762 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1763 std::vector
<struct decl_field
> typedef_field_list
;
1765 /* Nested types defined by this class and the number of elements in this
1767 std::vector
<struct decl_field
> nested_types_list
;
1770 /* One item on the queue of compilation units to read in full symbols
1772 struct dwarf2_queue_item
1774 struct dwarf2_per_cu_data
*per_cu
;
1775 enum language pretend_language
;
1776 struct dwarf2_queue_item
*next
;
1779 /* The current queue. */
1780 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1782 /* Loaded secondary compilation units are kept in memory until they
1783 have not been referenced for the processing of this many
1784 compilation units. Set this to zero to disable caching. Cache
1785 sizes of up to at least twenty will improve startup time for
1786 typical inter-CU-reference binaries, at an obvious memory cost. */
1787 static int dwarf_max_cache_age
= 5;
1789 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1790 struct cmd_list_element
*c
, const char *value
)
1792 fprintf_filtered (file
, _("The upper bound on the age of cached "
1793 "DWARF compilation units is %s.\n"),
1797 /* local function prototypes */
1799 static const char *get_section_name (const struct dwarf2_section_info
*);
1801 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1803 static void dwarf2_find_base_address (struct die_info
*die
,
1804 struct dwarf2_cu
*cu
);
1806 static struct partial_symtab
*create_partial_symtab
1807 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1809 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1810 const gdb_byte
*info_ptr
,
1811 struct die_info
*type_unit_die
,
1812 int has_children
, void *data
);
1814 static void dwarf2_build_psymtabs_hard
1815 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1817 static void scan_partial_symbols (struct partial_die_info
*,
1818 CORE_ADDR
*, CORE_ADDR
*,
1819 int, struct dwarf2_cu
*);
1821 static void add_partial_symbol (struct partial_die_info
*,
1822 struct dwarf2_cu
*);
1824 static void add_partial_namespace (struct partial_die_info
*pdi
,
1825 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1826 int set_addrmap
, struct dwarf2_cu
*cu
);
1828 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1829 CORE_ADDR
*highpc
, int set_addrmap
,
1830 struct dwarf2_cu
*cu
);
1832 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1833 struct dwarf2_cu
*cu
);
1835 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1836 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1837 int need_pc
, struct dwarf2_cu
*cu
);
1839 static void dwarf2_read_symtab (struct partial_symtab
*,
1842 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1844 static abbrev_table_up abbrev_table_read_table
1845 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1848 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1850 static struct partial_die_info
*load_partial_dies
1851 (const struct die_reader_specs
*, const gdb_byte
*, int);
1853 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1854 struct dwarf2_cu
*);
1856 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1857 struct attribute
*, struct attr_abbrev
*,
1860 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1862 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1864 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1866 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1868 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1870 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1873 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1875 static LONGEST read_checked_initial_length_and_offset
1876 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1877 unsigned int *, unsigned int *);
1879 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1880 const struct comp_unit_head
*,
1883 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1885 static sect_offset read_abbrev_offset
1886 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1887 struct dwarf2_section_info
*, sect_offset
);
1889 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1891 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1893 static const char *read_indirect_string
1894 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1895 const struct comp_unit_head
*, unsigned int *);
1897 static const char *read_indirect_line_string
1898 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1899 const struct comp_unit_head
*, unsigned int *);
1901 static const char *read_indirect_string_at_offset
1902 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1903 LONGEST str_offset
);
1905 static const char *read_indirect_string_from_dwz
1906 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1908 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1910 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1914 static const char *read_str_index (const struct die_reader_specs
*reader
,
1915 ULONGEST str_index
);
1917 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1919 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1920 struct dwarf2_cu
*);
1922 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1925 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1926 struct dwarf2_cu
*cu
);
1928 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1929 struct dwarf2_cu
*cu
);
1931 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1933 static struct die_info
*die_specification (struct die_info
*die
,
1934 struct dwarf2_cu
**);
1936 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1937 struct dwarf2_cu
*cu
);
1939 static void dwarf_decode_lines (struct line_header
*, const char *,
1940 struct dwarf2_cu
*, struct partial_symtab
*,
1941 CORE_ADDR
, int decode_mapping
);
1943 static void dwarf2_start_subfile (const char *, const char *);
1945 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1946 const char *, const char *,
1949 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1950 struct dwarf2_cu
*, struct symbol
* = NULL
);
1952 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1953 struct dwarf2_cu
*);
1955 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1958 struct obstack
*obstack
,
1959 struct dwarf2_cu
*cu
, LONGEST
*value
,
1960 const gdb_byte
**bytes
,
1961 struct dwarf2_locexpr_baton
**baton
);
1963 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1965 static int need_gnat_info (struct dwarf2_cu
*);
1967 static struct type
*die_descriptive_type (struct die_info
*,
1968 struct dwarf2_cu
*);
1970 static void set_descriptive_type (struct type
*, struct die_info
*,
1971 struct dwarf2_cu
*);
1973 static struct type
*die_containing_type (struct die_info
*,
1974 struct dwarf2_cu
*);
1976 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1977 struct dwarf2_cu
*);
1979 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1981 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1983 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1985 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1986 const char *suffix
, int physname
,
1987 struct dwarf2_cu
*cu
);
1989 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1991 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1993 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1995 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1997 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1999 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
2001 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
2002 struct dwarf2_cu
*, struct partial_symtab
*);
2004 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
2005 values. Keep the items ordered with increasing constraints compliance. */
2008 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
2009 PC_BOUNDS_NOT_PRESENT
,
2011 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
2012 were present but they do not form a valid range of PC addresses. */
2015 /* Discontiguous range was found - that is DW_AT_ranges was found. */
2018 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
2022 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
2023 CORE_ADDR
*, CORE_ADDR
*,
2025 struct partial_symtab
*);
2027 static void get_scope_pc_bounds (struct die_info
*,
2028 CORE_ADDR
*, CORE_ADDR
*,
2029 struct dwarf2_cu
*);
2031 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
2032 CORE_ADDR
, struct dwarf2_cu
*);
2034 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
2035 struct dwarf2_cu
*);
2037 static void dwarf2_attach_fields_to_type (struct field_info
*,
2038 struct type
*, struct dwarf2_cu
*);
2040 static void dwarf2_add_member_fn (struct field_info
*,
2041 struct die_info
*, struct type
*,
2042 struct dwarf2_cu
*);
2044 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
2046 struct dwarf2_cu
*);
2048 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
2050 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
2052 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
2054 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
2056 static struct using_direct
**using_directives (enum language
);
2058 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
2060 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
2062 static struct type
*read_module_type (struct die_info
*die
,
2063 struct dwarf2_cu
*cu
);
2065 static const char *namespace_name (struct die_info
*die
,
2066 int *is_anonymous
, struct dwarf2_cu
*);
2068 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
2070 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
2072 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
2073 struct dwarf2_cu
*);
2075 static struct die_info
*read_die_and_siblings_1
2076 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
2079 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
2080 const gdb_byte
*info_ptr
,
2081 const gdb_byte
**new_info_ptr
,
2082 struct die_info
*parent
);
2084 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
2085 struct die_info
**, const gdb_byte
*,
2088 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
2089 struct die_info
**, const gdb_byte
*,
2092 static void process_die (struct die_info
*, struct dwarf2_cu
*);
2094 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
2097 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
2099 static const char *dwarf2_full_name (const char *name
,
2100 struct die_info
*die
,
2101 struct dwarf2_cu
*cu
);
2103 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
2104 struct dwarf2_cu
*cu
);
2106 static struct die_info
*dwarf2_extension (struct die_info
*die
,
2107 struct dwarf2_cu
**);
2109 static const char *dwarf_tag_name (unsigned int);
2111 static const char *dwarf_attr_name (unsigned int);
2113 static const char *dwarf_form_name (unsigned int);
2115 static const char *dwarf_bool_name (unsigned int);
2117 static const char *dwarf_type_encoding_name (unsigned int);
2119 static struct die_info
*sibling_die (struct die_info
*);
2121 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
2123 static void dump_die_for_error (struct die_info
*);
2125 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
2128 /*static*/ void dump_die (struct die_info
*, int max_level
);
2130 static void store_in_ref_table (struct die_info
*,
2131 struct dwarf2_cu
*);
2133 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
2135 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
2137 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
2138 const struct attribute
*,
2139 struct dwarf2_cu
**);
2141 static struct die_info
*follow_die_ref (struct die_info
*,
2142 const struct attribute
*,
2143 struct dwarf2_cu
**);
2145 static struct die_info
*follow_die_sig (struct die_info
*,
2146 const struct attribute
*,
2147 struct dwarf2_cu
**);
2149 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
2150 struct dwarf2_cu
*);
2152 static struct type
*get_DW_AT_signature_type (struct die_info
*,
2153 const struct attribute
*,
2154 struct dwarf2_cu
*);
2156 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
2158 static void read_signatured_type (struct signatured_type
*);
2160 static int attr_to_dynamic_prop (const struct attribute
*attr
,
2161 struct die_info
*die
, struct dwarf2_cu
*cu
,
2162 struct dynamic_prop
*prop
);
2164 /* memory allocation interface */
2166 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
2168 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
2170 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
2172 static int attr_form_is_block (const struct attribute
*);
2174 static int attr_form_is_section_offset (const struct attribute
*);
2176 static int attr_form_is_constant (const struct attribute
*);
2178 static int attr_form_is_ref (const struct attribute
*);
2180 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
2181 struct dwarf2_loclist_baton
*baton
,
2182 const struct attribute
*attr
);
2184 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
2186 struct dwarf2_cu
*cu
,
2189 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
2190 const gdb_byte
*info_ptr
,
2191 struct abbrev_info
*abbrev
);
2193 static hashval_t
partial_die_hash (const void *item
);
2195 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
2197 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
2198 (sect_offset sect_off
, unsigned int offset_in_dwz
,
2199 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2201 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
2202 struct die_info
*comp_unit_die
,
2203 enum language pretend_language
);
2205 static void free_cached_comp_units (void *);
2207 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2209 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
2211 static struct type
*set_die_type (struct die_info
*, struct type
*,
2212 struct dwarf2_cu
*);
2214 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2216 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2218 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
2221 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
2224 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
2227 static void dwarf2_add_dependence (struct dwarf2_cu
*,
2228 struct dwarf2_per_cu_data
*);
2230 static void dwarf2_mark (struct dwarf2_cu
*);
2232 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
2234 static struct type
*get_die_type_at_offset (sect_offset
,
2235 struct dwarf2_per_cu_data
*);
2237 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
2239 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
2240 enum language pretend_language
);
2242 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2244 /* Class, the destructor of which frees all allocated queue entries. This
2245 will only have work to do if an error was thrown while processing the
2246 dwarf. If no error was thrown then the queue entries should have all
2247 been processed, and freed, as we went along. */
2249 class dwarf2_queue_guard
2252 dwarf2_queue_guard () = default;
2254 /* Free any entries remaining on the queue. There should only be
2255 entries left if we hit an error while processing the dwarf. */
2256 ~dwarf2_queue_guard ()
2258 struct dwarf2_queue_item
*item
, *last
;
2260 item
= dwarf2_queue
;
2263 /* Anything still marked queued is likely to be in an
2264 inconsistent state, so discard it. */
2265 if (item
->per_cu
->queued
)
2267 if (item
->per_cu
->cu
!= NULL
)
2268 free_one_cached_comp_unit (item
->per_cu
);
2269 item
->per_cu
->queued
= 0;
2277 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2281 /* The return type of find_file_and_directory. Note, the enclosed
2282 string pointers are only valid while this object is valid. */
2284 struct file_and_directory
2286 /* The filename. This is never NULL. */
2289 /* The compilation directory. NULL if not known. If we needed to
2290 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2291 points directly to the DW_AT_comp_dir string attribute owned by
2292 the obstack that owns the DIE. */
2293 const char *comp_dir
;
2295 /* If we needed to build a new string for comp_dir, this is what
2296 owns the storage. */
2297 std::string comp_dir_storage
;
2300 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2301 struct dwarf2_cu
*cu
);
2303 static char *file_full_name (int file
, struct line_header
*lh
,
2304 const char *comp_dir
);
2306 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2307 enum class rcuh_kind
{ COMPILE
, TYPE
};
2309 static const gdb_byte
*read_and_check_comp_unit_head
2310 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2311 struct comp_unit_head
*header
,
2312 struct dwarf2_section_info
*section
,
2313 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2314 rcuh_kind section_kind
);
2316 static void init_cutu_and_read_dies
2317 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2318 int use_existing_cu
, int keep
,
2319 die_reader_func_ftype
*die_reader_func
, void *data
);
2321 static void init_cutu_and_read_dies_simple
2322 (struct dwarf2_per_cu_data
*this_cu
,
2323 die_reader_func_ftype
*die_reader_func
, void *data
);
2325 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2327 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2329 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2330 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2331 struct dwp_file
*dwp_file
, const char *comp_dir
,
2332 ULONGEST signature
, int is_debug_types
);
2334 static struct dwp_file
*get_dwp_file
2335 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2337 static struct dwo_unit
*lookup_dwo_comp_unit
2338 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2340 static struct dwo_unit
*lookup_dwo_type_unit
2341 (struct signatured_type
*, const char *, const char *);
2343 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2345 static void free_dwo_file_cleanup (void *);
2347 struct free_dwo_file_cleanup_data
2349 struct dwo_file
*dwo_file
;
2350 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
2353 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2355 static void check_producer (struct dwarf2_cu
*cu
);
2357 static void free_line_header_voidp (void *arg
);
2359 /* Various complaints about symbol reading that don't abort the process. */
2362 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2364 complaint (&symfile_complaints
,
2365 _("statement list doesn't fit in .debug_line section"));
2369 dwarf2_debug_line_missing_file_complaint (void)
2371 complaint (&symfile_complaints
,
2372 _(".debug_line section has line data without a file"));
2376 dwarf2_debug_line_missing_end_sequence_complaint (void)
2378 complaint (&symfile_complaints
,
2379 _(".debug_line section has line "
2380 "program sequence without an end"));
2384 dwarf2_complex_location_expr_complaint (void)
2386 complaint (&symfile_complaints
, _("location expression too complex"));
2390 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2393 complaint (&symfile_complaints
,
2394 _("const value length mismatch for '%s', got %d, expected %d"),
2399 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2401 complaint (&symfile_complaints
,
2402 _("debug info runs off end of %s section"
2404 get_section_name (section
),
2405 get_section_file_name (section
));
2409 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2411 complaint (&symfile_complaints
,
2412 _("macro debug info contains a "
2413 "malformed macro definition:\n`%s'"),
2418 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2420 complaint (&symfile_complaints
,
2421 _("invalid attribute class or form for '%s' in '%s'"),
2425 /* Hash function for line_header_hash. */
2428 line_header_hash (const struct line_header
*ofs
)
2430 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2433 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2436 line_header_hash_voidp (const void *item
)
2438 const struct line_header
*ofs
= (const struct line_header
*) item
;
2440 return line_header_hash (ofs
);
2443 /* Equality function for line_header_hash. */
2446 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2448 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2449 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2451 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2452 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2457 /* Read the given attribute value as an address, taking the attribute's
2458 form into account. */
2461 attr_value_as_address (struct attribute
*attr
)
2465 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2467 /* Aside from a few clearly defined exceptions, attributes that
2468 contain an address must always be in DW_FORM_addr form.
2469 Unfortunately, some compilers happen to be violating this
2470 requirement by encoding addresses using other forms, such
2471 as DW_FORM_data4 for example. For those broken compilers,
2472 we try to do our best, without any guarantee of success,
2473 to interpret the address correctly. It would also be nice
2474 to generate a complaint, but that would require us to maintain
2475 a list of legitimate cases where a non-address form is allowed,
2476 as well as update callers to pass in at least the CU's DWARF
2477 version. This is more overhead than what we're willing to
2478 expand for a pretty rare case. */
2479 addr
= DW_UNSND (attr
);
2482 addr
= DW_ADDR (attr
);
2487 /* The suffix for an index file. */
2488 #define INDEX4_SUFFIX ".gdb-index"
2489 #define INDEX5_SUFFIX ".debug_names"
2490 #define DEBUG_STR_SUFFIX ".debug_str"
2492 /* See declaration. */
2494 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2495 const dwarf2_debug_sections
*names
)
2496 : objfile (objfile_
)
2499 names
= &dwarf2_elf_names
;
2501 bfd
*obfd
= objfile
->obfd
;
2503 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2504 locate_sections (obfd
, sec
, *names
);
2507 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2509 dwarf2_per_objfile::~dwarf2_per_objfile ()
2511 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2512 free_cached_comp_units ();
2514 if (quick_file_names_table
)
2515 htab_delete (quick_file_names_table
);
2517 if (line_header_hash
)
2518 htab_delete (line_header_hash
);
2520 for (int ix
= 0; ix
< n_comp_units
; ++ix
)
2521 VEC_free (dwarf2_per_cu_ptr
, all_comp_units
[ix
]->imported_symtabs
);
2523 for (int ix
= 0; ix
< n_type_units
; ++ix
)
2524 VEC_free (dwarf2_per_cu_ptr
,
2525 all_type_units
[ix
]->per_cu
.imported_symtabs
);
2526 xfree (all_type_units
);
2528 VEC_free (dwarf2_section_info_def
, types
);
2530 if (dwo_files
!= NULL
)
2531 free_dwo_files (dwo_files
, objfile
);
2532 if (dwp_file
!= NULL
)
2533 gdb_bfd_unref (dwp_file
->dbfd
);
2535 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2536 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2538 if (index_table
!= NULL
)
2539 index_table
->~mapped_index ();
2541 /* Everything else should be on the objfile obstack. */
2544 /* See declaration. */
2547 dwarf2_per_objfile::free_cached_comp_units ()
2549 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2550 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2551 while (per_cu
!= NULL
)
2553 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2556 *last_chain
= next_cu
;
2561 /* Try to locate the sections we need for DWARF 2 debugging
2562 information and return true if we have enough to do something.
2563 NAMES points to the dwarf2 section names, or is NULL if the standard
2564 ELF names are used. */
2567 dwarf2_has_info (struct objfile
*objfile
,
2568 const struct dwarf2_debug_sections
*names
)
2570 if (objfile
->flags
& OBJF_READNEVER
)
2573 struct dwarf2_per_objfile
*dwarf2_per_objfile
2574 = get_dwarf2_per_objfile (objfile
);
2576 if (dwarf2_per_objfile
== NULL
)
2578 /* Initialize per-objfile state. */
2580 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2582 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2584 return (!dwarf2_per_objfile
->info
.is_virtual
2585 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2586 && !dwarf2_per_objfile
->abbrev
.is_virtual
2587 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2590 /* Return the containing section of virtual section SECTION. */
2592 static struct dwarf2_section_info
*
2593 get_containing_section (const struct dwarf2_section_info
*section
)
2595 gdb_assert (section
->is_virtual
);
2596 return section
->s
.containing_section
;
2599 /* Return the bfd owner of SECTION. */
2602 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2604 if (section
->is_virtual
)
2606 section
= get_containing_section (section
);
2607 gdb_assert (!section
->is_virtual
);
2609 return section
->s
.section
->owner
;
2612 /* Return the bfd section of SECTION.
2613 Returns NULL if the section is not present. */
2616 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2618 if (section
->is_virtual
)
2620 section
= get_containing_section (section
);
2621 gdb_assert (!section
->is_virtual
);
2623 return section
->s
.section
;
2626 /* Return the name of SECTION. */
2629 get_section_name (const struct dwarf2_section_info
*section
)
2631 asection
*sectp
= get_section_bfd_section (section
);
2633 gdb_assert (sectp
!= NULL
);
2634 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2637 /* Return the name of the file SECTION is in. */
2640 get_section_file_name (const struct dwarf2_section_info
*section
)
2642 bfd
*abfd
= get_section_bfd_owner (section
);
2644 return bfd_get_filename (abfd
);
2647 /* Return the id of SECTION.
2648 Returns 0 if SECTION doesn't exist. */
2651 get_section_id (const struct dwarf2_section_info
*section
)
2653 asection
*sectp
= get_section_bfd_section (section
);
2660 /* Return the flags of SECTION.
2661 SECTION (or containing section if this is a virtual section) must exist. */
2664 get_section_flags (const struct dwarf2_section_info
*section
)
2666 asection
*sectp
= get_section_bfd_section (section
);
2668 gdb_assert (sectp
!= NULL
);
2669 return bfd_get_section_flags (sectp
->owner
, sectp
);
2672 /* When loading sections, we look either for uncompressed section or for
2673 compressed section names. */
2676 section_is_p (const char *section_name
,
2677 const struct dwarf2_section_names
*names
)
2679 if (names
->normal
!= NULL
2680 && strcmp (section_name
, names
->normal
) == 0)
2682 if (names
->compressed
!= NULL
2683 && strcmp (section_name
, names
->compressed
) == 0)
2688 /* See declaration. */
2691 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2692 const dwarf2_debug_sections
&names
)
2694 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2696 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2699 else if (section_is_p (sectp
->name
, &names
.info
))
2701 this->info
.s
.section
= sectp
;
2702 this->info
.size
= bfd_get_section_size (sectp
);
2704 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2706 this->abbrev
.s
.section
= sectp
;
2707 this->abbrev
.size
= bfd_get_section_size (sectp
);
2709 else if (section_is_p (sectp
->name
, &names
.line
))
2711 this->line
.s
.section
= sectp
;
2712 this->line
.size
= bfd_get_section_size (sectp
);
2714 else if (section_is_p (sectp
->name
, &names
.loc
))
2716 this->loc
.s
.section
= sectp
;
2717 this->loc
.size
= bfd_get_section_size (sectp
);
2719 else if (section_is_p (sectp
->name
, &names
.loclists
))
2721 this->loclists
.s
.section
= sectp
;
2722 this->loclists
.size
= bfd_get_section_size (sectp
);
2724 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2726 this->macinfo
.s
.section
= sectp
;
2727 this->macinfo
.size
= bfd_get_section_size (sectp
);
2729 else if (section_is_p (sectp
->name
, &names
.macro
))
2731 this->macro
.s
.section
= sectp
;
2732 this->macro
.size
= bfd_get_section_size (sectp
);
2734 else if (section_is_p (sectp
->name
, &names
.str
))
2736 this->str
.s
.section
= sectp
;
2737 this->str
.size
= bfd_get_section_size (sectp
);
2739 else if (section_is_p (sectp
->name
, &names
.line_str
))
2741 this->line_str
.s
.section
= sectp
;
2742 this->line_str
.size
= bfd_get_section_size (sectp
);
2744 else if (section_is_p (sectp
->name
, &names
.addr
))
2746 this->addr
.s
.section
= sectp
;
2747 this->addr
.size
= bfd_get_section_size (sectp
);
2749 else if (section_is_p (sectp
->name
, &names
.frame
))
2751 this->frame
.s
.section
= sectp
;
2752 this->frame
.size
= bfd_get_section_size (sectp
);
2754 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2756 this->eh_frame
.s
.section
= sectp
;
2757 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2759 else if (section_is_p (sectp
->name
, &names
.ranges
))
2761 this->ranges
.s
.section
= sectp
;
2762 this->ranges
.size
= bfd_get_section_size (sectp
);
2764 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2766 this->rnglists
.s
.section
= sectp
;
2767 this->rnglists
.size
= bfd_get_section_size (sectp
);
2769 else if (section_is_p (sectp
->name
, &names
.types
))
2771 struct dwarf2_section_info type_section
;
2773 memset (&type_section
, 0, sizeof (type_section
));
2774 type_section
.s
.section
= sectp
;
2775 type_section
.size
= bfd_get_section_size (sectp
);
2777 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2780 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2782 this->gdb_index
.s
.section
= sectp
;
2783 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2785 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2787 this->debug_names
.s
.section
= sectp
;
2788 this->debug_names
.size
= bfd_get_section_size (sectp
);
2790 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2792 this->debug_aranges
.s
.section
= sectp
;
2793 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2796 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2797 && bfd_section_vma (abfd
, sectp
) == 0)
2798 this->has_section_at_zero
= true;
2801 /* A helper function that decides whether a section is empty,
2805 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2807 if (section
->is_virtual
)
2808 return section
->size
== 0;
2809 return section
->s
.section
== NULL
|| section
->size
== 0;
2812 /* Read the contents of the section INFO.
2813 OBJFILE is the main object file, but not necessarily the file where
2814 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2816 If the section is compressed, uncompress it before returning. */
2819 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2823 gdb_byte
*buf
, *retbuf
;
2827 info
->buffer
= NULL
;
2830 if (dwarf2_section_empty_p (info
))
2833 sectp
= get_section_bfd_section (info
);
2835 /* If this is a virtual section we need to read in the real one first. */
2836 if (info
->is_virtual
)
2838 struct dwarf2_section_info
*containing_section
=
2839 get_containing_section (info
);
2841 gdb_assert (sectp
!= NULL
);
2842 if ((sectp
->flags
& SEC_RELOC
) != 0)
2844 error (_("Dwarf Error: DWP format V2 with relocations is not"
2845 " supported in section %s [in module %s]"),
2846 get_section_name (info
), get_section_file_name (info
));
2848 dwarf2_read_section (objfile
, containing_section
);
2849 /* Other code should have already caught virtual sections that don't
2851 gdb_assert (info
->virtual_offset
+ info
->size
2852 <= containing_section
->size
);
2853 /* If the real section is empty or there was a problem reading the
2854 section we shouldn't get here. */
2855 gdb_assert (containing_section
->buffer
!= NULL
);
2856 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2860 /* If the section has relocations, we must read it ourselves.
2861 Otherwise we attach it to the BFD. */
2862 if ((sectp
->flags
& SEC_RELOC
) == 0)
2864 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2868 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2871 /* When debugging .o files, we may need to apply relocations; see
2872 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2873 We never compress sections in .o files, so we only need to
2874 try this when the section is not compressed. */
2875 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2878 info
->buffer
= retbuf
;
2882 abfd
= get_section_bfd_owner (info
);
2883 gdb_assert (abfd
!= NULL
);
2885 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2886 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2888 error (_("Dwarf Error: Can't read DWARF data"
2889 " in section %s [in module %s]"),
2890 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2894 /* A helper function that returns the size of a section in a safe way.
2895 If you are positive that the section has been read before using the
2896 size, then it is safe to refer to the dwarf2_section_info object's
2897 "size" field directly. In other cases, you must call this
2898 function, because for compressed sections the size field is not set
2899 correctly until the section has been read. */
2901 static bfd_size_type
2902 dwarf2_section_size (struct objfile
*objfile
,
2903 struct dwarf2_section_info
*info
)
2906 dwarf2_read_section (objfile
, info
);
2910 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2914 dwarf2_get_section_info (struct objfile
*objfile
,
2915 enum dwarf2_section_enum sect
,
2916 asection
**sectp
, const gdb_byte
**bufp
,
2917 bfd_size_type
*sizep
)
2919 struct dwarf2_per_objfile
*data
2920 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2921 dwarf2_objfile_data_key
);
2922 struct dwarf2_section_info
*info
;
2924 /* We may see an objfile without any DWARF, in which case we just
2935 case DWARF2_DEBUG_FRAME
:
2936 info
= &data
->frame
;
2938 case DWARF2_EH_FRAME
:
2939 info
= &data
->eh_frame
;
2942 gdb_assert_not_reached ("unexpected section");
2945 dwarf2_read_section (objfile
, info
);
2947 *sectp
= get_section_bfd_section (info
);
2948 *bufp
= info
->buffer
;
2949 *sizep
= info
->size
;
2952 /* A helper function to find the sections for a .dwz file. */
2955 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2957 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2959 /* Note that we only support the standard ELF names, because .dwz
2960 is ELF-only (at the time of writing). */
2961 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2963 dwz_file
->abbrev
.s
.section
= sectp
;
2964 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2966 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2968 dwz_file
->info
.s
.section
= sectp
;
2969 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2971 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2973 dwz_file
->str
.s
.section
= sectp
;
2974 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2976 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2978 dwz_file
->line
.s
.section
= sectp
;
2979 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2981 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2983 dwz_file
->macro
.s
.section
= sectp
;
2984 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2986 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2988 dwz_file
->gdb_index
.s
.section
= sectp
;
2989 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2991 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2993 dwz_file
->debug_names
.s
.section
= sectp
;
2994 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2998 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2999 there is no .gnu_debugaltlink section in the file. Error if there
3000 is such a section but the file cannot be found. */
3002 static struct dwz_file
*
3003 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
3005 const char *filename
;
3006 struct dwz_file
*result
;
3007 bfd_size_type buildid_len_arg
;
3011 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
3012 return dwarf2_per_objfile
->dwz_file
;
3014 bfd_set_error (bfd_error_no_error
);
3015 gdb::unique_xmalloc_ptr
<char> data
3016 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
3017 &buildid_len_arg
, &buildid
));
3020 if (bfd_get_error () == bfd_error_no_error
)
3022 error (_("could not read '.gnu_debugaltlink' section: %s"),
3023 bfd_errmsg (bfd_get_error ()));
3026 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
3028 buildid_len
= (size_t) buildid_len_arg
;
3030 filename
= data
.get ();
3032 std::string abs_storage
;
3033 if (!IS_ABSOLUTE_PATH (filename
))
3035 gdb::unique_xmalloc_ptr
<char> abs
3036 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
3038 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
3039 filename
= abs_storage
.c_str ();
3042 /* First try the file name given in the section. If that doesn't
3043 work, try to use the build-id instead. */
3044 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
3045 if (dwz_bfd
!= NULL
)
3047 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
3051 if (dwz_bfd
== NULL
)
3052 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
3054 if (dwz_bfd
== NULL
)
3055 error (_("could not find '.gnu_debugaltlink' file for %s"),
3056 objfile_name (dwarf2_per_objfile
->objfile
));
3058 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
3060 result
->dwz_bfd
= dwz_bfd
.release ();
3062 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
3064 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
3065 dwarf2_per_objfile
->dwz_file
= result
;
3069 /* DWARF quick_symbols_functions support. */
3071 /* TUs can share .debug_line entries, and there can be a lot more TUs than
3072 unique line tables, so we maintain a separate table of all .debug_line
3073 derived entries to support the sharing.
3074 All the quick functions need is the list of file names. We discard the
3075 line_header when we're done and don't need to record it here. */
3076 struct quick_file_names
3078 /* The data used to construct the hash key. */
3079 struct stmt_list_hash hash
;
3081 /* The number of entries in file_names, real_names. */
3082 unsigned int num_file_names
;
3084 /* The file names from the line table, after being run through
3086 const char **file_names
;
3088 /* The file names from the line table after being run through
3089 gdb_realpath. These are computed lazily. */
3090 const char **real_names
;
3093 /* When using the index (and thus not using psymtabs), each CU has an
3094 object of this type. This is used to hold information needed by
3095 the various "quick" methods. */
3096 struct dwarf2_per_cu_quick_data
3098 /* The file table. This can be NULL if there was no file table
3099 or it's currently not read in.
3100 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
3101 struct quick_file_names
*file_names
;
3103 /* The corresponding symbol table. This is NULL if symbols for this
3104 CU have not yet been read. */
3105 struct compunit_symtab
*compunit_symtab
;
3107 /* A temporary mark bit used when iterating over all CUs in
3108 expand_symtabs_matching. */
3109 unsigned int mark
: 1;
3111 /* True if we've tried to read the file table and found there isn't one.
3112 There will be no point in trying to read it again next time. */
3113 unsigned int no_file_data
: 1;
3116 /* Utility hash function for a stmt_list_hash. */
3119 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
3123 if (stmt_list_hash
->dwo_unit
!= NULL
)
3124 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
3125 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
3129 /* Utility equality function for a stmt_list_hash. */
3132 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
3133 const struct stmt_list_hash
*rhs
)
3135 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
3137 if (lhs
->dwo_unit
!= NULL
3138 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
3141 return lhs
->line_sect_off
== rhs
->line_sect_off
;
3144 /* Hash function for a quick_file_names. */
3147 hash_file_name_entry (const void *e
)
3149 const struct quick_file_names
*file_data
3150 = (const struct quick_file_names
*) e
;
3152 return hash_stmt_list_entry (&file_data
->hash
);
3155 /* Equality function for a quick_file_names. */
3158 eq_file_name_entry (const void *a
, const void *b
)
3160 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
3161 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
3163 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
3166 /* Delete function for a quick_file_names. */
3169 delete_file_name_entry (void *e
)
3171 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
3174 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3176 xfree ((void*) file_data
->file_names
[i
]);
3177 if (file_data
->real_names
)
3178 xfree ((void*) file_data
->real_names
[i
]);
3181 /* The space for the struct itself lives on objfile_obstack,
3182 so we don't free it here. */
3185 /* Create a quick_file_names hash table. */
3188 create_quick_file_names_table (unsigned int nr_initial_entries
)
3190 return htab_create_alloc (nr_initial_entries
,
3191 hash_file_name_entry
, eq_file_name_entry
,
3192 delete_file_name_entry
, xcalloc
, xfree
);
3195 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
3196 have to be created afterwards. You should call age_cached_comp_units after
3197 processing PER_CU->CU. dw2_setup must have been already called. */
3200 load_cu (struct dwarf2_per_cu_data
*per_cu
)
3202 if (per_cu
->is_debug_types
)
3203 load_full_type_unit (per_cu
);
3205 load_full_comp_unit (per_cu
, language_minimal
);
3207 if (per_cu
->cu
== NULL
)
3208 return; /* Dummy CU. */
3210 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
3213 /* Read in the symbols for PER_CU. */
3216 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3218 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3220 /* Skip type_unit_groups, reading the type units they contain
3221 is handled elsewhere. */
3222 if (IS_TYPE_UNIT_GROUP (per_cu
))
3225 /* The destructor of dwarf2_queue_guard frees any entries left on
3226 the queue. After this point we're guaranteed to leave this function
3227 with the dwarf queue empty. */
3228 dwarf2_queue_guard q_guard
;
3230 if (dwarf2_per_objfile
->using_index
3231 ? per_cu
->v
.quick
->compunit_symtab
== NULL
3232 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
3234 queue_comp_unit (per_cu
, language_minimal
);
3237 /* If we just loaded a CU from a DWO, and we're working with an index
3238 that may badly handle TUs, load all the TUs in that DWO as well.
3239 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
3240 if (!per_cu
->is_debug_types
3241 && per_cu
->cu
!= NULL
3242 && per_cu
->cu
->dwo_unit
!= NULL
3243 && dwarf2_per_objfile
->index_table
!= NULL
3244 && dwarf2_per_objfile
->index_table
->version
<= 7
3245 /* DWP files aren't supported yet. */
3246 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
3247 queue_and_load_all_dwo_tus (per_cu
);
3250 process_queue (dwarf2_per_objfile
);
3252 /* Age the cache, releasing compilation units that have not
3253 been used recently. */
3254 age_cached_comp_units (dwarf2_per_objfile
);
3257 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
3258 the objfile from which this CU came. Returns the resulting symbol
3261 static struct compunit_symtab
*
3262 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3264 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3266 gdb_assert (dwarf2_per_objfile
->using_index
);
3267 if (!per_cu
->v
.quick
->compunit_symtab
)
3269 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
,
3270 dwarf2_per_objfile
);
3271 scoped_restore decrementer
= increment_reading_symtab ();
3272 dw2_do_instantiate_symtab (per_cu
);
3273 process_cu_includes (dwarf2_per_objfile
);
3274 do_cleanups (back_to
);
3277 return per_cu
->v
.quick
->compunit_symtab
;
3280 /* Return the CU/TU given its index.
3282 This is intended for loops like:
3284 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3285 + dwarf2_per_objfile->n_type_units); ++i)
3287 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
3293 static struct dwarf2_per_cu_data
*
3294 dw2_get_cutu (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3297 if (index
>= dwarf2_per_objfile
->n_comp_units
)
3299 index
-= dwarf2_per_objfile
->n_comp_units
;
3300 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
3301 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
3304 return dwarf2_per_objfile
->all_comp_units
[index
];
3307 /* Return the CU given its index.
3308 This differs from dw2_get_cutu in that it's for when you know INDEX
3311 static struct dwarf2_per_cu_data
*
3312 dw2_get_cu (struct dwarf2_per_objfile
*dwarf2_per_objfile
, int index
)
3314 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
3316 return dwarf2_per_objfile
->all_comp_units
[index
];
3319 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3320 objfile_obstack, and constructed with the specified field
3323 static dwarf2_per_cu_data
*
3324 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3325 struct dwarf2_section_info
*section
,
3327 sect_offset sect_off
, ULONGEST length
)
3329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3330 dwarf2_per_cu_data
*the_cu
3331 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3332 struct dwarf2_per_cu_data
);
3333 the_cu
->sect_off
= sect_off
;
3334 the_cu
->length
= length
;
3335 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3336 the_cu
->section
= section
;
3337 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3338 struct dwarf2_per_cu_quick_data
);
3339 the_cu
->is_dwz
= is_dwz
;
3343 /* A helper for create_cus_from_index that handles a given list of
3347 create_cus_from_index_list (struct objfile
*objfile
,
3348 const gdb_byte
*cu_list
, offset_type n_elements
,
3349 struct dwarf2_section_info
*section
,
3354 struct dwarf2_per_objfile
*dwarf2_per_objfile
3355 = get_dwarf2_per_objfile (objfile
);
3357 for (i
= 0; i
< n_elements
; i
+= 2)
3359 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3361 sect_offset sect_off
3362 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3363 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3366 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2]
3367 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3372 /* Read the CU list from the mapped index, and use it to create all
3373 the CU objects for this objfile. */
3376 create_cus_from_index (struct objfile
*objfile
,
3377 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3378 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3380 struct dwz_file
*dwz
;
3381 struct dwarf2_per_objfile
*dwarf2_per_objfile
3382 = get_dwarf2_per_objfile (objfile
);
3384 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3385 dwarf2_per_objfile
->all_comp_units
=
3386 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3387 dwarf2_per_objfile
->n_comp_units
);
3389 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3390 &dwarf2_per_objfile
->info
, 0, 0);
3392 if (dwz_elements
== 0)
3395 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3396 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3397 cu_list_elements
/ 2);
3400 /* Create the signatured type hash table from the index. */
3403 create_signatured_type_table_from_index (struct objfile
*objfile
,
3404 struct dwarf2_section_info
*section
,
3405 const gdb_byte
*bytes
,
3406 offset_type elements
)
3409 htab_t sig_types_hash
;
3410 struct dwarf2_per_objfile
*dwarf2_per_objfile
3411 = get_dwarf2_per_objfile (objfile
);
3413 dwarf2_per_objfile
->n_type_units
3414 = dwarf2_per_objfile
->n_allocated_type_units
3416 dwarf2_per_objfile
->all_type_units
=
3417 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3419 sig_types_hash
= allocate_signatured_type_table (objfile
);
3421 for (i
= 0; i
< elements
; i
+= 3)
3423 struct signatured_type
*sig_type
;
3426 cu_offset type_offset_in_tu
;
3428 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3429 sect_offset sect_off
3430 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3432 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3434 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3437 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3438 struct signatured_type
);
3439 sig_type
->signature
= signature
;
3440 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3441 sig_type
->per_cu
.is_debug_types
= 1;
3442 sig_type
->per_cu
.section
= section
;
3443 sig_type
->per_cu
.sect_off
= sect_off
;
3444 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3445 sig_type
->per_cu
.v
.quick
3446 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3447 struct dwarf2_per_cu_quick_data
);
3449 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3452 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3455 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3458 /* Create the signatured type hash table from .debug_names. */
3461 create_signatured_type_table_from_debug_names
3462 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3463 const mapped_debug_names
&map
,
3464 struct dwarf2_section_info
*section
,
3465 struct dwarf2_section_info
*abbrev_section
)
3467 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3469 dwarf2_read_section (objfile
, section
);
3470 dwarf2_read_section (objfile
, abbrev_section
);
3472 dwarf2_per_objfile
->n_type_units
3473 = dwarf2_per_objfile
->n_allocated_type_units
3475 dwarf2_per_objfile
->all_type_units
3476 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3478 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3480 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3482 struct signatured_type
*sig_type
;
3485 cu_offset type_offset_in_tu
;
3487 sect_offset sect_off
3488 = (sect_offset
) (extract_unsigned_integer
3489 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3491 map
.dwarf5_byte_order
));
3493 comp_unit_head cu_header
;
3494 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3496 section
->buffer
+ to_underlying (sect_off
),
3499 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3500 struct signatured_type
);
3501 sig_type
->signature
= cu_header
.signature
;
3502 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3503 sig_type
->per_cu
.is_debug_types
= 1;
3504 sig_type
->per_cu
.section
= section
;
3505 sig_type
->per_cu
.sect_off
= sect_off
;
3506 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3507 sig_type
->per_cu
.v
.quick
3508 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3509 struct dwarf2_per_cu_quick_data
);
3511 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3514 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3517 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3520 /* Read the address map data from the mapped index, and use it to
3521 populate the objfile's psymtabs_addrmap. */
3524 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3525 struct mapped_index
*index
)
3527 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3528 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3529 const gdb_byte
*iter
, *end
;
3530 struct addrmap
*mutable_map
;
3533 auto_obstack temp_obstack
;
3535 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3537 iter
= index
->address_table
.data ();
3538 end
= iter
+ index
->address_table
.size ();
3540 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3544 ULONGEST hi
, lo
, cu_index
;
3545 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3547 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3549 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3554 complaint (&symfile_complaints
,
3555 _(".gdb_index address table has invalid range (%s - %s)"),
3556 hex_string (lo
), hex_string (hi
));
3560 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3562 complaint (&symfile_complaints
,
3563 _(".gdb_index address table has invalid CU number %u"),
3564 (unsigned) cu_index
);
3568 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3569 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3570 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3571 dw2_get_cutu (dwarf2_per_objfile
, cu_index
));
3574 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3575 &objfile
->objfile_obstack
);
3578 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3579 populate the objfile's psymtabs_addrmap. */
3582 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3583 struct dwarf2_section_info
*section
)
3585 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3586 bfd
*abfd
= objfile
->obfd
;
3587 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3588 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3589 SECT_OFF_TEXT (objfile
));
3591 auto_obstack temp_obstack
;
3592 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3594 std::unordered_map
<sect_offset
,
3595 dwarf2_per_cu_data
*,
3596 gdb::hash_enum
<sect_offset
>>
3597 debug_info_offset_to_per_cu
;
3598 for (int cui
= 0; cui
< dwarf2_per_objfile
->n_comp_units
; ++cui
)
3600 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cui
);
3601 const auto insertpair
3602 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3603 if (!insertpair
.second
)
3605 warning (_("Section .debug_aranges in %s has duplicate "
3606 "debug_info_offset %s, ignoring .debug_aranges."),
3607 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3612 dwarf2_read_section (objfile
, section
);
3614 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3616 const gdb_byte
*addr
= section
->buffer
;
3618 while (addr
< section
->buffer
+ section
->size
)
3620 const gdb_byte
*const entry_addr
= addr
;
3621 unsigned int bytes_read
;
3623 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3627 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3628 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3629 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3630 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3632 warning (_("Section .debug_aranges in %s entry at offset %zu "
3633 "length %s exceeds section length %s, "
3634 "ignoring .debug_aranges."),
3635 objfile_name (objfile
), entry_addr
- section
->buffer
,
3636 plongest (bytes_read
+ entry_length
),
3637 pulongest (section
->size
));
3641 /* The version number. */
3642 const uint16_t version
= read_2_bytes (abfd
, addr
);
3646 warning (_("Section .debug_aranges in %s entry at offset %zu "
3647 "has unsupported version %d, ignoring .debug_aranges."),
3648 objfile_name (objfile
), entry_addr
- section
->buffer
,
3653 const uint64_t debug_info_offset
3654 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3655 addr
+= offset_size
;
3656 const auto per_cu_it
3657 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3658 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3660 warning (_("Section .debug_aranges in %s entry at offset %zu "
3661 "debug_info_offset %s does not exists, "
3662 "ignoring .debug_aranges."),
3663 objfile_name (objfile
), entry_addr
- section
->buffer
,
3664 pulongest (debug_info_offset
));
3667 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3669 const uint8_t address_size
= *addr
++;
3670 if (address_size
< 1 || address_size
> 8)
3672 warning (_("Section .debug_aranges in %s entry at offset %zu "
3673 "address_size %u is invalid, ignoring .debug_aranges."),
3674 objfile_name (objfile
), entry_addr
- section
->buffer
,
3679 const uint8_t segment_selector_size
= *addr
++;
3680 if (segment_selector_size
!= 0)
3682 warning (_("Section .debug_aranges in %s entry at offset %zu "
3683 "segment_selector_size %u is not supported, "
3684 "ignoring .debug_aranges."),
3685 objfile_name (objfile
), entry_addr
- section
->buffer
,
3686 segment_selector_size
);
3690 /* Must pad to an alignment boundary that is twice the address
3691 size. It is undocumented by the DWARF standard but GCC does
3693 for (size_t padding
= ((-(addr
- section
->buffer
))
3694 & (2 * address_size
- 1));
3695 padding
> 0; padding
--)
3698 warning (_("Section .debug_aranges in %s entry at offset %zu "
3699 "padding is not zero, ignoring .debug_aranges."),
3700 objfile_name (objfile
), entry_addr
- section
->buffer
);
3706 if (addr
+ 2 * address_size
> entry_end
)
3708 warning (_("Section .debug_aranges in %s entry at offset %zu "
3709 "address list is not properly terminated, "
3710 "ignoring .debug_aranges."),
3711 objfile_name (objfile
), entry_addr
- section
->buffer
);
3714 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3716 addr
+= address_size
;
3717 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3719 addr
+= address_size
;
3720 if (start
== 0 && length
== 0)
3722 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3724 /* Symbol was eliminated due to a COMDAT group. */
3727 ULONGEST end
= start
+ length
;
3728 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3729 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3730 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3734 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3735 &objfile
->objfile_obstack
);
3738 /* The hash function for strings in the mapped index. This is the same as
3739 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3740 implementation. This is necessary because the hash function is tied to the
3741 format of the mapped index file. The hash values do not have to match with
3744 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3747 mapped_index_string_hash (int index_version
, const void *p
)
3749 const unsigned char *str
= (const unsigned char *) p
;
3753 while ((c
= *str
++) != 0)
3755 if (index_version
>= 5)
3757 r
= r
* 67 + c
- 113;
3763 /* Find a slot in the mapped index INDEX for the object named NAME.
3764 If NAME is found, set *VEC_OUT to point to the CU vector in the
3765 constant pool and return true. If NAME cannot be found, return
3769 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3770 offset_type
**vec_out
)
3773 offset_type slot
, step
;
3774 int (*cmp
) (const char *, const char *);
3776 gdb::unique_xmalloc_ptr
<char> without_params
;
3777 if (current_language
->la_language
== language_cplus
3778 || current_language
->la_language
== language_fortran
3779 || current_language
->la_language
== language_d
)
3781 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3784 if (strchr (name
, '(') != NULL
)
3786 without_params
= cp_remove_params (name
);
3788 if (without_params
!= NULL
)
3789 name
= without_params
.get ();
3793 /* Index version 4 did not support case insensitive searches. But the
3794 indices for case insensitive languages are built in lowercase, therefore
3795 simulate our NAME being searched is also lowercased. */
3796 hash
= mapped_index_string_hash ((index
->version
== 4
3797 && case_sensitivity
== case_sensitive_off
3798 ? 5 : index
->version
),
3801 slot
= hash
& (index
->symbol_table
.size () - 1);
3802 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3803 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3809 const auto &bucket
= index
->symbol_table
[slot
];
3810 if (bucket
.name
== 0 && bucket
.vec
== 0)
3813 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3814 if (!cmp (name
, str
))
3816 *vec_out
= (offset_type
*) (index
->constant_pool
3817 + MAYBE_SWAP (bucket
.vec
));
3821 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3825 /* A helper function that reads the .gdb_index from SECTION and fills
3826 in MAP. FILENAME is the name of the file containing the section;
3827 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3828 ok to use deprecated sections.
3830 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3831 out parameters that are filled in with information about the CU and
3832 TU lists in the section.
3834 Returns 1 if all went well, 0 otherwise. */
3837 read_index_from_section (struct objfile
*objfile
,
3838 const char *filename
,
3840 struct dwarf2_section_info
*section
,
3841 struct mapped_index
*map
,
3842 const gdb_byte
**cu_list
,
3843 offset_type
*cu_list_elements
,
3844 const gdb_byte
**types_list
,
3845 offset_type
*types_list_elements
)
3847 const gdb_byte
*addr
;
3848 offset_type version
;
3849 offset_type
*metadata
;
3852 if (dwarf2_section_empty_p (section
))
3855 /* Older elfutils strip versions could keep the section in the main
3856 executable while splitting it for the separate debug info file. */
3857 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3860 dwarf2_read_section (objfile
, section
);
3862 addr
= section
->buffer
;
3863 /* Version check. */
3864 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3865 /* Versions earlier than 3 emitted every copy of a psymbol. This
3866 causes the index to behave very poorly for certain requests. Version 3
3867 contained incomplete addrmap. So, it seems better to just ignore such
3871 static int warning_printed
= 0;
3872 if (!warning_printed
)
3874 warning (_("Skipping obsolete .gdb_index section in %s."),
3876 warning_printed
= 1;
3880 /* Index version 4 uses a different hash function than index version
3883 Versions earlier than 6 did not emit psymbols for inlined
3884 functions. Using these files will cause GDB not to be able to
3885 set breakpoints on inlined functions by name, so we ignore these
3886 indices unless the user has done
3887 "set use-deprecated-index-sections on". */
3888 if (version
< 6 && !deprecated_ok
)
3890 static int warning_printed
= 0;
3891 if (!warning_printed
)
3894 Skipping deprecated .gdb_index section in %s.\n\
3895 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3896 to use the section anyway."),
3898 warning_printed
= 1;
3902 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3903 of the TU (for symbols coming from TUs),
3904 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3905 Plus gold-generated indices can have duplicate entries for global symbols,
3906 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3907 These are just performance bugs, and we can't distinguish gdb-generated
3908 indices from gold-generated ones, so issue no warning here. */
3910 /* Indexes with higher version than the one supported by GDB may be no
3911 longer backward compatible. */
3915 map
->version
= version
;
3916 map
->total_size
= section
->size
;
3918 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3921 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3922 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3926 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3927 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3928 - MAYBE_SWAP (metadata
[i
]))
3932 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3933 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3935 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3938 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3939 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3941 = gdb::array_view
<mapped_index::symbol_table_slot
>
3942 ((mapped_index::symbol_table_slot
*) symbol_table
,
3943 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3946 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3951 /* Read .gdb_index. If everything went ok, initialize the "quick"
3952 elements of all the CUs and return 1. Otherwise, return 0. */
3955 dwarf2_read_index (struct objfile
*objfile
)
3957 struct mapped_index local_map
, *map
;
3958 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3959 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3960 struct dwz_file
*dwz
;
3961 struct dwarf2_per_objfile
*dwarf2_per_objfile
3962 = get_dwarf2_per_objfile (objfile
);
3964 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3965 use_deprecated_index_sections
,
3966 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3967 &cu_list
, &cu_list_elements
,
3968 &types_list
, &types_list_elements
))
3971 /* Don't use the index if it's empty. */
3972 if (local_map
.symbol_table
.empty ())
3975 /* If there is a .dwz file, read it so we can get its CU list as
3977 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3980 struct mapped_index dwz_map
;
3981 const gdb_byte
*dwz_types_ignore
;
3982 offset_type dwz_types_elements_ignore
;
3984 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3986 &dwz
->gdb_index
, &dwz_map
,
3987 &dwz_list
, &dwz_list_elements
,
3989 &dwz_types_elements_ignore
))
3991 warning (_("could not read '.gdb_index' section from %s; skipping"),
3992 bfd_get_filename (dwz
->dwz_bfd
));
3997 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
4000 if (types_list_elements
)
4002 struct dwarf2_section_info
*section
;
4004 /* We can only handle a single .debug_types when we have an
4006 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
4009 section
= VEC_index (dwarf2_section_info_def
,
4010 dwarf2_per_objfile
->types
, 0);
4012 create_signatured_type_table_from_index (objfile
, section
, types_list
,
4013 types_list_elements
);
4016 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
4018 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
4019 map
= new (map
) mapped_index ();
4022 dwarf2_per_objfile
->index_table
= map
;
4023 dwarf2_per_objfile
->using_index
= 1;
4024 dwarf2_per_objfile
->quick_file_names_table
=
4025 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4030 /* die_reader_func for dw2_get_file_names. */
4033 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
4034 const gdb_byte
*info_ptr
,
4035 struct die_info
*comp_unit_die
,
4039 struct dwarf2_cu
*cu
= reader
->cu
;
4040 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
4041 struct dwarf2_per_objfile
*dwarf2_per_objfile
4042 = cu
->per_cu
->dwarf2_per_objfile
;
4043 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4044 struct dwarf2_per_cu_data
*lh_cu
;
4045 struct attribute
*attr
;
4048 struct quick_file_names
*qfn
;
4050 gdb_assert (! this_cu
->is_debug_types
);
4052 /* Our callers never want to match partial units -- instead they
4053 will match the enclosing full CU. */
4054 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
4056 this_cu
->v
.quick
->no_file_data
= 1;
4064 sect_offset line_offset
{};
4066 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4069 struct quick_file_names find_entry
;
4071 line_offset
= (sect_offset
) DW_UNSND (attr
);
4073 /* We may have already read in this line header (TU line header sharing).
4074 If we have we're done. */
4075 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
4076 find_entry
.hash
.line_sect_off
= line_offset
;
4077 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
4078 &find_entry
, INSERT
);
4081 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
4085 lh
= dwarf_decode_line_header (line_offset
, cu
);
4089 lh_cu
->v
.quick
->no_file_data
= 1;
4093 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
4094 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
4095 qfn
->hash
.line_sect_off
= line_offset
;
4096 gdb_assert (slot
!= NULL
);
4099 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
4101 qfn
->num_file_names
= lh
->file_names
.size ();
4103 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
4104 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
4105 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
4106 qfn
->real_names
= NULL
;
4108 lh_cu
->v
.quick
->file_names
= qfn
;
4111 /* A helper for the "quick" functions which attempts to read the line
4112 table for THIS_CU. */
4114 static struct quick_file_names
*
4115 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
4117 /* This should never be called for TUs. */
4118 gdb_assert (! this_cu
->is_debug_types
);
4119 /* Nor type unit groups. */
4120 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
4122 if (this_cu
->v
.quick
->file_names
!= NULL
)
4123 return this_cu
->v
.quick
->file_names
;
4124 /* If we know there is no line data, no point in looking again. */
4125 if (this_cu
->v
.quick
->no_file_data
)
4128 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
4130 if (this_cu
->v
.quick
->no_file_data
)
4132 return this_cu
->v
.quick
->file_names
;
4135 /* A helper for the "quick" functions which computes and caches the
4136 real path for a given file name from the line table. */
4139 dw2_get_real_path (struct objfile
*objfile
,
4140 struct quick_file_names
*qfn
, int index
)
4142 if (qfn
->real_names
== NULL
)
4143 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
4144 qfn
->num_file_names
, const char *);
4146 if (qfn
->real_names
[index
] == NULL
)
4147 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
4149 return qfn
->real_names
[index
];
4152 static struct symtab
*
4153 dw2_find_last_source_symtab (struct objfile
*objfile
)
4155 struct dwarf2_per_objfile
*dwarf2_per_objfile
4156 = get_dwarf2_per_objfile (objfile
);
4157 int index
= dwarf2_per_objfile
->n_comp_units
- 1;
4158 dwarf2_per_cu_data
*dwarf_cu
= dw2_get_cutu (dwarf2_per_objfile
, index
);
4159 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
4164 return compunit_primary_filetab (cust
);
4167 /* Traversal function for dw2_forget_cached_source_info. */
4170 dw2_free_cached_file_names (void **slot
, void *info
)
4172 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
4174 if (file_data
->real_names
)
4178 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
4180 xfree ((void*) file_data
->real_names
[i
]);
4181 file_data
->real_names
[i
] = NULL
;
4189 dw2_forget_cached_source_info (struct objfile
*objfile
)
4191 struct dwarf2_per_objfile
*dwarf2_per_objfile
4192 = get_dwarf2_per_objfile (objfile
);
4194 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
4195 dw2_free_cached_file_names
, NULL
);
4198 /* Helper function for dw2_map_symtabs_matching_filename that expands
4199 the symtabs and calls the iterator. */
4202 dw2_map_expand_apply (struct objfile
*objfile
,
4203 struct dwarf2_per_cu_data
*per_cu
,
4204 const char *name
, const char *real_path
,
4205 gdb::function_view
<bool (symtab
*)> callback
)
4207 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
4209 /* Don't visit already-expanded CUs. */
4210 if (per_cu
->v
.quick
->compunit_symtab
)
4213 /* This may expand more than one symtab, and we want to iterate over
4215 dw2_instantiate_symtab (per_cu
);
4217 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
4218 last_made
, callback
);
4221 /* Implementation of the map_symtabs_matching_filename method. */
4224 dw2_map_symtabs_matching_filename
4225 (struct objfile
*objfile
, const char *name
, const char *real_path
,
4226 gdb::function_view
<bool (symtab
*)> callback
)
4229 const char *name_basename
= lbasename (name
);
4230 struct dwarf2_per_objfile
*dwarf2_per_objfile
4231 = get_dwarf2_per_objfile (objfile
);
4233 /* The rule is CUs specify all the files, including those used by
4234 any TU, so there's no need to scan TUs here. */
4236 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4239 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
4240 struct quick_file_names
*file_data
;
4242 /* We only need to look at symtabs not already expanded. */
4243 if (per_cu
->v
.quick
->compunit_symtab
)
4246 file_data
= dw2_get_file_names (per_cu
);
4247 if (file_data
== NULL
)
4250 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4252 const char *this_name
= file_data
->file_names
[j
];
4253 const char *this_real_name
;
4255 if (compare_filenames_for_search (this_name
, name
))
4257 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4263 /* Before we invoke realpath, which can get expensive when many
4264 files are involved, do a quick comparison of the basenames. */
4265 if (! basenames_may_differ
4266 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
4269 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4270 if (compare_filenames_for_search (this_real_name
, name
))
4272 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4278 if (real_path
!= NULL
)
4280 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
4281 gdb_assert (IS_ABSOLUTE_PATH (name
));
4282 if (this_real_name
!= NULL
4283 && FILENAME_CMP (real_path
, this_real_name
) == 0)
4285 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4297 /* Struct used to manage iterating over all CUs looking for a symbol. */
4299 struct dw2_symtab_iterator
4301 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
4302 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
4303 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
4304 int want_specific_block
;
4305 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
4306 Unused if !WANT_SPECIFIC_BLOCK. */
4308 /* The kind of symbol we're looking for. */
4310 /* The list of CUs from the index entry of the symbol,
4311 or NULL if not found. */
4313 /* The next element in VEC to look at. */
4315 /* The number of elements in VEC, or zero if there is no match. */
4317 /* Have we seen a global version of the symbol?
4318 If so we can ignore all further global instances.
4319 This is to work around gold/15646, inefficient gold-generated
4324 /* Initialize the index symtab iterator ITER.
4325 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
4326 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
4329 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
4330 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4331 int want_specific_block
,
4336 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
4337 iter
->want_specific_block
= want_specific_block
;
4338 iter
->block_index
= block_index
;
4339 iter
->domain
= domain
;
4341 iter
->global_seen
= 0;
4343 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
4345 /* index is NULL if OBJF_READNOW. */
4346 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
4347 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4355 /* Return the next matching CU or NULL if there are no more. */
4357 static struct dwarf2_per_cu_data
*
4358 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4360 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4362 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4364 offset_type cu_index_and_attrs
=
4365 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4366 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4367 struct dwarf2_per_cu_data
*per_cu
;
4368 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
4369 /* This value is only valid for index versions >= 7. */
4370 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4371 gdb_index_symbol_kind symbol_kind
=
4372 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4373 /* Only check the symbol attributes if they're present.
4374 Indices prior to version 7 don't record them,
4375 and indices >= 7 may elide them for certain symbols
4376 (gold does this). */
4378 (dwarf2_per_objfile
->index_table
->version
>= 7
4379 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4381 /* Don't crash on bad data. */
4382 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4383 + dwarf2_per_objfile
->n_type_units
))
4385 complaint (&symfile_complaints
,
4386 _(".gdb_index entry has bad CU index"
4388 objfile_name (dwarf2_per_objfile
->objfile
));
4392 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
4394 /* Skip if already read in. */
4395 if (per_cu
->v
.quick
->compunit_symtab
)
4398 /* Check static vs global. */
4401 if (iter
->want_specific_block
4402 && want_static
!= is_static
)
4404 /* Work around gold/15646. */
4405 if (!is_static
&& iter
->global_seen
)
4408 iter
->global_seen
= 1;
4411 /* Only check the symbol's kind if it has one. */
4414 switch (iter
->domain
)
4417 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4418 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4419 /* Some types are also in VAR_DOMAIN. */
4420 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4424 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4428 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4443 static struct compunit_symtab
*
4444 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4445 const char *name
, domain_enum domain
)
4447 struct compunit_symtab
*stab_best
= NULL
;
4448 struct dwarf2_per_objfile
*dwarf2_per_objfile
4449 = get_dwarf2_per_objfile (objfile
);
4451 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4453 struct dw2_symtab_iterator iter
;
4454 struct dwarf2_per_cu_data
*per_cu
;
4456 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4458 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4460 struct symbol
*sym
, *with_opaque
= NULL
;
4461 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4462 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4463 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4465 sym
= block_find_symbol (block
, name
, domain
,
4466 block_find_non_opaque_type_preferred
,
4469 /* Some caution must be observed with overloaded functions
4470 and methods, since the index will not contain any overload
4471 information (but NAME might contain it). */
4474 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4476 if (with_opaque
!= NULL
4477 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4480 /* Keep looking through other CUs. */
4487 dw2_print_stats (struct objfile
*objfile
)
4489 struct dwarf2_per_objfile
*dwarf2_per_objfile
4490 = get_dwarf2_per_objfile (objfile
);
4491 int total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
4494 for (int i
= 0; i
< total
; ++i
)
4496 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4498 if (!per_cu
->v
.quick
->compunit_symtab
)
4501 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4502 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4505 /* This dumps minimal information about the index.
4506 It is called via "mt print objfiles".
4507 One use is to verify .gdb_index has been loaded by the
4508 gdb.dwarf2/gdb-index.exp testcase. */
4511 dw2_dump (struct objfile
*objfile
)
4513 struct dwarf2_per_objfile
*dwarf2_per_objfile
4514 = get_dwarf2_per_objfile (objfile
);
4516 gdb_assert (dwarf2_per_objfile
->using_index
);
4517 printf_filtered (".gdb_index:");
4518 if (dwarf2_per_objfile
->index_table
!= NULL
)
4520 printf_filtered (" version %d\n",
4521 dwarf2_per_objfile
->index_table
->version
);
4524 printf_filtered (" faked for \"readnow\"\n");
4525 printf_filtered ("\n");
4529 dw2_relocate (struct objfile
*objfile
,
4530 const struct section_offsets
*new_offsets
,
4531 const struct section_offsets
*delta
)
4533 /* There's nothing to relocate here. */
4537 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4538 const char *func_name
)
4540 struct dwarf2_per_objfile
*dwarf2_per_objfile
4541 = get_dwarf2_per_objfile (objfile
);
4543 struct dw2_symtab_iterator iter
;
4544 struct dwarf2_per_cu_data
*per_cu
;
4546 /* Note: It doesn't matter what we pass for block_index here. */
4547 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4550 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4551 dw2_instantiate_symtab (per_cu
);
4556 dw2_expand_all_symtabs (struct objfile
*objfile
)
4558 struct dwarf2_per_objfile
*dwarf2_per_objfile
4559 = get_dwarf2_per_objfile (objfile
);
4560 int total_units
= (dwarf2_per_objfile
->n_comp_units
4561 + dwarf2_per_objfile
->n_type_units
);
4563 for (int i
= 0; i
< total_units
; ++i
)
4565 struct dwarf2_per_cu_data
*per_cu
4566 = dw2_get_cutu (dwarf2_per_objfile
, i
);
4568 dw2_instantiate_symtab (per_cu
);
4573 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4574 const char *fullname
)
4576 struct dwarf2_per_objfile
*dwarf2_per_objfile
4577 = get_dwarf2_per_objfile (objfile
);
4579 /* We don't need to consider type units here.
4580 This is only called for examining code, e.g. expand_line_sal.
4581 There can be an order of magnitude (or more) more type units
4582 than comp units, and we avoid them if we can. */
4584 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4587 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4588 struct quick_file_names
*file_data
;
4590 /* We only need to look at symtabs not already expanded. */
4591 if (per_cu
->v
.quick
->compunit_symtab
)
4594 file_data
= dw2_get_file_names (per_cu
);
4595 if (file_data
== NULL
)
4598 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4600 const char *this_fullname
= file_data
->file_names
[j
];
4602 if (filename_cmp (this_fullname
, fullname
) == 0)
4604 dw2_instantiate_symtab (per_cu
);
4612 dw2_map_matching_symbols (struct objfile
*objfile
,
4613 const char * name
, domain_enum domain
,
4615 int (*callback
) (struct block
*,
4616 struct symbol
*, void *),
4617 void *data
, symbol_name_match_type match
,
4618 symbol_compare_ftype
*ordered_compare
)
4620 /* Currently unimplemented; used for Ada. The function can be called if the
4621 current language is Ada for a non-Ada objfile using GNU index. As Ada
4622 does not look for non-Ada symbols this function should just return. */
4625 /* Symbol name matcher for .gdb_index names.
4627 Symbol names in .gdb_index have a few particularities:
4629 - There's no indication of which is the language of each symbol.
4631 Since each language has its own symbol name matching algorithm,
4632 and we don't know which language is the right one, we must match
4633 each symbol against all languages. This would be a potential
4634 performance problem if it were not mitigated by the
4635 mapped_index::name_components lookup table, which significantly
4636 reduces the number of times we need to call into this matcher,
4637 making it a non-issue.
4639 - Symbol names in the index have no overload (parameter)
4640 information. I.e., in C++, "foo(int)" and "foo(long)" both
4641 appear as "foo" in the index, for example.
4643 This means that the lookup names passed to the symbol name
4644 matcher functions must have no parameter information either
4645 because (e.g.) symbol search name "foo" does not match
4646 lookup-name "foo(int)" [while swapping search name for lookup
4649 class gdb_index_symbol_name_matcher
4652 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4653 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4655 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4656 Returns true if any matcher matches. */
4657 bool matches (const char *symbol_name
);
4660 /* A reference to the lookup name we're matching against. */
4661 const lookup_name_info
&m_lookup_name
;
4663 /* A vector holding all the different symbol name matchers, for all
4665 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4668 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4669 (const lookup_name_info
&lookup_name
)
4670 : m_lookup_name (lookup_name
)
4672 /* Prepare the vector of comparison functions upfront, to avoid
4673 doing the same work for each symbol. Care is taken to avoid
4674 matching with the same matcher more than once if/when multiple
4675 languages use the same matcher function. */
4676 auto &matchers
= m_symbol_name_matcher_funcs
;
4677 matchers
.reserve (nr_languages
);
4679 matchers
.push_back (default_symbol_name_matcher
);
4681 for (int i
= 0; i
< nr_languages
; i
++)
4683 const language_defn
*lang
= language_def ((enum language
) i
);
4684 symbol_name_matcher_ftype
*name_matcher
4685 = get_symbol_name_matcher (lang
, m_lookup_name
);
4687 /* Don't insert the same comparison routine more than once.
4688 Note that we do this linear walk instead of a seemingly
4689 cheaper sorted insert, or use a std::set or something like
4690 that, because relative order of function addresses is not
4691 stable. This is not a problem in practice because the number
4692 of supported languages is low, and the cost here is tiny
4693 compared to the number of searches we'll do afterwards using
4695 if (name_matcher
!= default_symbol_name_matcher
4696 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4697 == matchers
.end ()))
4698 matchers
.push_back (name_matcher
);
4703 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4705 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4706 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4712 /* Starting from a search name, return the string that finds the upper
4713 bound of all strings that start with SEARCH_NAME in a sorted name
4714 list. Returns the empty string to indicate that the upper bound is
4715 the end of the list. */
4718 make_sort_after_prefix_name (const char *search_name
)
4720 /* When looking to complete "func", we find the upper bound of all
4721 symbols that start with "func" by looking for where we'd insert
4722 the closest string that would follow "func" in lexicographical
4723 order. Usually, that's "func"-with-last-character-incremented,
4724 i.e. "fund". Mind non-ASCII characters, though. Usually those
4725 will be UTF-8 multi-byte sequences, but we can't be certain.
4726 Especially mind the 0xff character, which is a valid character in
4727 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4728 rule out compilers allowing it in identifiers. Note that
4729 conveniently, strcmp/strcasecmp are specified to compare
4730 characters interpreted as unsigned char. So what we do is treat
4731 the whole string as a base 256 number composed of a sequence of
4732 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4733 to 0, and carries 1 to the following more-significant position.
4734 If the very first character in SEARCH_NAME ends up incremented
4735 and carries/overflows, then the upper bound is the end of the
4736 list. The string after the empty string is also the empty
4739 Some examples of this operation:
4741 SEARCH_NAME => "+1" RESULT
4745 "\xff" "a" "\xff" => "\xff" "b"
4750 Then, with these symbols for example:
4756 completing "func" looks for symbols between "func" and
4757 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4758 which finds "func" and "func1", but not "fund".
4762 funcÿ (Latin1 'ÿ' [0xff])
4766 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4767 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4771 ÿÿ (Latin1 'ÿ' [0xff])
4774 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4775 the end of the list.
4777 std::string after
= search_name
;
4778 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4780 if (!after
.empty ())
4781 after
.back () = (unsigned char) after
.back () + 1;
4785 /* See declaration. */
4787 std::pair
<std::vector
<name_component
>::const_iterator
,
4788 std::vector
<name_component
>::const_iterator
>
4789 mapped_index_base::find_name_components_bounds
4790 (const lookup_name_info
&lookup_name_without_params
) const
4793 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4796 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4798 /* Comparison function object for lower_bound that matches against a
4799 given symbol name. */
4800 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4803 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4804 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4805 return name_cmp (elem_name
, name
) < 0;
4808 /* Comparison function object for upper_bound that matches against a
4809 given symbol name. */
4810 auto lookup_compare_upper
= [&] (const char *name
,
4811 const name_component
&elem
)
4813 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4814 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4815 return name_cmp (name
, elem_name
) < 0;
4818 auto begin
= this->name_components
.begin ();
4819 auto end
= this->name_components
.end ();
4821 /* Find the lower bound. */
4824 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4827 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4830 /* Find the upper bound. */
4833 if (lookup_name_without_params
.completion_mode ())
4835 /* In completion mode, we want UPPER to point past all
4836 symbols names that have the same prefix. I.e., with
4837 these symbols, and completing "func":
4839 function << lower bound
4841 other_function << upper bound
4843 We find the upper bound by looking for the insertion
4844 point of "func"-with-last-character-incremented,
4846 std::string after
= make_sort_after_prefix_name (cplus
);
4849 return std::lower_bound (lower
, end
, after
.c_str (),
4850 lookup_compare_lower
);
4853 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4856 return {lower
, upper
};
4859 /* See declaration. */
4862 mapped_index_base::build_name_components ()
4864 if (!this->name_components
.empty ())
4867 this->name_components_casing
= case_sensitivity
;
4869 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4871 /* The code below only knows how to break apart components of C++
4872 symbol names (and other languages that use '::' as
4873 namespace/module separator). If we add support for wild matching
4874 to some language that uses some other operator (E.g., Ada, Go and
4875 D use '.'), then we'll need to try splitting the symbol name
4876 according to that language too. Note that Ada does support wild
4877 matching, but doesn't currently support .gdb_index. */
4878 auto count
= this->symbol_name_count ();
4879 for (offset_type idx
= 0; idx
< count
; idx
++)
4881 if (this->symbol_name_slot_invalid (idx
))
4884 const char *name
= this->symbol_name_at (idx
);
4886 /* Add each name component to the name component table. */
4887 unsigned int previous_len
= 0;
4888 for (unsigned int current_len
= cp_find_first_component (name
);
4889 name
[current_len
] != '\0';
4890 current_len
+= cp_find_first_component (name
+ current_len
))
4892 gdb_assert (name
[current_len
] == ':');
4893 this->name_components
.push_back ({previous_len
, idx
});
4894 /* Skip the '::'. */
4896 previous_len
= current_len
;
4898 this->name_components
.push_back ({previous_len
, idx
});
4901 /* Sort name_components elements by name. */
4902 auto name_comp_compare
= [&] (const name_component
&left
,
4903 const name_component
&right
)
4905 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4906 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4908 const char *left_name
= left_qualified
+ left
.name_offset
;
4909 const char *right_name
= right_qualified
+ right
.name_offset
;
4911 return name_cmp (left_name
, right_name
) < 0;
4914 std::sort (this->name_components
.begin (),
4915 this->name_components
.end (),
4919 /* Helper for dw2_expand_symtabs_matching that works with a
4920 mapped_index_base instead of the containing objfile. This is split
4921 to a separate function in order to be able to unit test the
4922 name_components matching using a mock mapped_index_base. For each
4923 symbol name that matches, calls MATCH_CALLBACK, passing it the
4924 symbol's index in the mapped_index_base symbol table. */
4927 dw2_expand_symtabs_matching_symbol
4928 (mapped_index_base
&index
,
4929 const lookup_name_info
&lookup_name_in
,
4930 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4931 enum search_domain kind
,
4932 gdb::function_view
<void (offset_type
)> match_callback
)
4934 lookup_name_info lookup_name_without_params
4935 = lookup_name_in
.make_ignore_params ();
4936 gdb_index_symbol_name_matcher lookup_name_matcher
4937 (lookup_name_without_params
);
4939 /* Build the symbol name component sorted vector, if we haven't
4941 index
.build_name_components ();
4943 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4945 /* Now for each symbol name in range, check to see if we have a name
4946 match, and if so, call the MATCH_CALLBACK callback. */
4948 /* The same symbol may appear more than once in the range though.
4949 E.g., if we're looking for symbols that complete "w", and we have
4950 a symbol named "w1::w2", we'll find the two name components for
4951 that same symbol in the range. To be sure we only call the
4952 callback once per symbol, we first collect the symbol name
4953 indexes that matched in a temporary vector and ignore
4955 std::vector
<offset_type
> matches
;
4956 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4958 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4960 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4962 if (!lookup_name_matcher
.matches (qualified
)
4963 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4966 matches
.push_back (bounds
.first
->idx
);
4969 std::sort (matches
.begin (), matches
.end ());
4971 /* Finally call the callback, once per match. */
4973 for (offset_type idx
: matches
)
4977 match_callback (idx
);
4982 /* Above we use a type wider than idx's for 'prev', since 0 and
4983 (offset_type)-1 are both possible values. */
4984 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4989 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4991 /* A mock .gdb_index/.debug_names-like name index table, enough to
4992 exercise dw2_expand_symtabs_matching_symbol, which works with the
4993 mapped_index_base interface. Builds an index from the symbol list
4994 passed as parameter to the constructor. */
4995 class mock_mapped_index
: public mapped_index_base
4998 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4999 : m_symbol_table (symbols
)
5002 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
5004 /* Return the number of names in the symbol table. */
5005 virtual size_t symbol_name_count () const
5007 return m_symbol_table
.size ();
5010 /* Get the name of the symbol at IDX in the symbol table. */
5011 virtual const char *symbol_name_at (offset_type idx
) const
5013 return m_symbol_table
[idx
];
5017 gdb::array_view
<const char *> m_symbol_table
;
5020 /* Convenience function that converts a NULL pointer to a "<null>"
5021 string, to pass to print routines. */
5024 string_or_null (const char *str
)
5026 return str
!= NULL
? str
: "<null>";
5029 /* Check if a lookup_name_info built from
5030 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
5031 index. EXPECTED_LIST is the list of expected matches, in expected
5032 matching order. If no match expected, then an empty list is
5033 specified. Returns true on success. On failure prints a warning
5034 indicating the file:line that failed, and returns false. */
5037 check_match (const char *file
, int line
,
5038 mock_mapped_index
&mock_index
,
5039 const char *name
, symbol_name_match_type match_type
,
5040 bool completion_mode
,
5041 std::initializer_list
<const char *> expected_list
)
5043 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
5045 bool matched
= true;
5047 auto mismatch
= [&] (const char *expected_str
,
5050 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
5051 "expected=\"%s\", got=\"%s\"\n"),
5053 (match_type
== symbol_name_match_type::FULL
5055 name
, string_or_null (expected_str
), string_or_null (got
));
5059 auto expected_it
= expected_list
.begin ();
5060 auto expected_end
= expected_list
.end ();
5062 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
5064 [&] (offset_type idx
)
5066 const char *matched_name
= mock_index
.symbol_name_at (idx
);
5067 const char *expected_str
5068 = expected_it
== expected_end
? NULL
: *expected_it
++;
5070 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
5071 mismatch (expected_str
, matched_name
);
5074 const char *expected_str
5075 = expected_it
== expected_end
? NULL
: *expected_it
++;
5076 if (expected_str
!= NULL
)
5077 mismatch (expected_str
, NULL
);
5082 /* The symbols added to the mock mapped_index for testing (in
5084 static const char *test_symbols
[] = {
5093 "ns2::tmpl<int>::foo2",
5094 "(anonymous namespace)::A::B::C",
5096 /* These are used to check that the increment-last-char in the
5097 matching algorithm for completion doesn't match "t1_fund" when
5098 completing "t1_func". */
5104 /* A UTF-8 name with multi-byte sequences to make sure that
5105 cp-name-parser understands this as a single identifier ("função"
5106 is "function" in PT). */
5109 /* \377 (0xff) is Latin1 'ÿ'. */
5112 /* \377 (0xff) is Latin1 'ÿ'. */
5116 /* A name with all sorts of complications. Starts with "z" to make
5117 it easier for the completion tests below. */
5118 #define Z_SYM_NAME \
5119 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
5120 "::tuple<(anonymous namespace)::ui*, " \
5121 "std::default_delete<(anonymous namespace)::ui>, void>"
5126 /* Returns true if the mapped_index_base::find_name_component_bounds
5127 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
5128 in completion mode. */
5131 check_find_bounds_finds (mapped_index_base
&index
,
5132 const char *search_name
,
5133 gdb::array_view
<const char *> expected_syms
)
5135 lookup_name_info
lookup_name (search_name
,
5136 symbol_name_match_type::FULL
, true);
5138 auto bounds
= index
.find_name_components_bounds (lookup_name
);
5140 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
5141 if (distance
!= expected_syms
.size ())
5144 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
5146 auto nc_elem
= bounds
.first
+ exp_elem
;
5147 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
5148 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
5155 /* Test the lower-level mapped_index::find_name_component_bounds
5159 test_mapped_index_find_name_component_bounds ()
5161 mock_mapped_index
mock_index (test_symbols
);
5163 mock_index
.build_name_components ();
5165 /* Test the lower-level mapped_index::find_name_component_bounds
5166 method in completion mode. */
5168 static const char *expected_syms
[] = {
5173 SELF_CHECK (check_find_bounds_finds (mock_index
,
5174 "t1_func", expected_syms
));
5177 /* Check that the increment-last-char in the name matching algorithm
5178 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
5180 static const char *expected_syms1
[] = {
5184 SELF_CHECK (check_find_bounds_finds (mock_index
,
5185 "\377", expected_syms1
));
5187 static const char *expected_syms2
[] = {
5190 SELF_CHECK (check_find_bounds_finds (mock_index
,
5191 "\377\377", expected_syms2
));
5195 /* Test dw2_expand_symtabs_matching_symbol. */
5198 test_dw2_expand_symtabs_matching_symbol ()
5200 mock_mapped_index
mock_index (test_symbols
);
5202 /* We let all tests run until the end even if some fails, for debug
5204 bool any_mismatch
= false;
5206 /* Create the expected symbols list (an initializer_list). Needed
5207 because lists have commas, and we need to pass them to CHECK,
5208 which is a macro. */
5209 #define EXPECT(...) { __VA_ARGS__ }
5211 /* Wrapper for check_match that passes down the current
5212 __FILE__/__LINE__. */
5213 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
5214 any_mismatch |= !check_match (__FILE__, __LINE__, \
5216 NAME, MATCH_TYPE, COMPLETION_MODE, \
5219 /* Identity checks. */
5220 for (const char *sym
: test_symbols
)
5222 /* Should be able to match all existing symbols. */
5223 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
5226 /* Should be able to match all existing symbols with
5228 std::string with_params
= std::string (sym
) + "(int)";
5229 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5232 /* Should be able to match all existing symbols with
5233 parameters and qualifiers. */
5234 with_params
= std::string (sym
) + " ( int ) const";
5235 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5238 /* This should really find sym, but cp-name-parser.y doesn't
5239 know about lvalue/rvalue qualifiers yet. */
5240 with_params
= std::string (sym
) + " ( int ) &&";
5241 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5245 /* Check that the name matching algorithm for completion doesn't get
5246 confused with Latin1 'ÿ' / 0xff. */
5248 static const char str
[] = "\377";
5249 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5250 EXPECT ("\377", "\377\377123"));
5253 /* Check that the increment-last-char in the matching algorithm for
5254 completion doesn't match "t1_fund" when completing "t1_func". */
5256 static const char str
[] = "t1_func";
5257 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5258 EXPECT ("t1_func", "t1_func1"));
5261 /* Check that completion mode works at each prefix of the expected
5264 static const char str
[] = "function(int)";
5265 size_t len
= strlen (str
);
5268 for (size_t i
= 1; i
< len
; i
++)
5270 lookup
.assign (str
, i
);
5271 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5272 EXPECT ("function"));
5276 /* While "w" is a prefix of both components, the match function
5277 should still only be called once. */
5279 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
5281 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
5285 /* Same, with a "complicated" symbol. */
5287 static const char str
[] = Z_SYM_NAME
;
5288 size_t len
= strlen (str
);
5291 for (size_t i
= 1; i
< len
; i
++)
5293 lookup
.assign (str
, i
);
5294 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5295 EXPECT (Z_SYM_NAME
));
5299 /* In FULL mode, an incomplete symbol doesn't match. */
5301 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
5305 /* A complete symbol with parameters matches any overload, since the
5306 index has no overload info. */
5308 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
5309 EXPECT ("std::zfunction", "std::zfunction2"));
5310 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
5311 EXPECT ("std::zfunction", "std::zfunction2"));
5312 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
5313 EXPECT ("std::zfunction", "std::zfunction2"));
5316 /* Check that whitespace is ignored appropriately. A symbol with a
5317 template argument list. */
5319 static const char expected
[] = "ns::foo<int>";
5320 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
5322 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
5326 /* Check that whitespace is ignored appropriately. A symbol with a
5327 template argument list that includes a pointer. */
5329 static const char expected
[] = "ns::foo<char*>";
5330 /* Try both completion and non-completion modes. */
5331 static const bool completion_mode
[2] = {false, true};
5332 for (size_t i
= 0; i
< 2; i
++)
5334 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
5335 completion_mode
[i
], EXPECT (expected
));
5336 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
5337 completion_mode
[i
], EXPECT (expected
));
5339 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
5340 completion_mode
[i
], EXPECT (expected
));
5341 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
5342 completion_mode
[i
], EXPECT (expected
));
5347 /* Check method qualifiers are ignored. */
5348 static const char expected
[] = "ns::foo<char*>";
5349 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
5350 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5351 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
5352 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5353 CHECK_MATCH ("foo < char * > ( int ) const",
5354 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5355 CHECK_MATCH ("foo < char * > ( int ) &&",
5356 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5359 /* Test lookup names that don't match anything. */
5361 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
5364 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
5368 /* Some wild matching tests, exercising "(anonymous namespace)",
5369 which should not be confused with a parameter list. */
5371 static const char *syms
[] = {
5375 "A :: B :: C ( int )",
5380 for (const char *s
: syms
)
5382 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
5383 EXPECT ("(anonymous namespace)::A::B::C"));
5388 static const char expected
[] = "ns2::tmpl<int>::foo2";
5389 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5391 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5395 SELF_CHECK (!any_mismatch
);
5404 test_mapped_index_find_name_component_bounds ();
5405 test_dw2_expand_symtabs_matching_symbol ();
5408 }} // namespace selftests::dw2_expand_symtabs_matching
5410 #endif /* GDB_SELF_TEST */
5412 /* If FILE_MATCHER is NULL or if PER_CU has
5413 dwarf2_per_cu_quick_data::MARK set (see
5414 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5415 EXPANSION_NOTIFY on it. */
5418 dw2_expand_symtabs_matching_one
5419 (struct dwarf2_per_cu_data
*per_cu
,
5420 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5421 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5423 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5425 bool symtab_was_null
5426 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5428 dw2_instantiate_symtab (per_cu
);
5430 if (expansion_notify
!= NULL
5432 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5433 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5437 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5438 matched, to expand corresponding CUs that were marked. IDX is the
5439 index of the symbol name that matched. */
5442 dw2_expand_marked_cus
5443 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5444 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5445 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5448 offset_type
*vec
, vec_len
, vec_idx
;
5449 bool global_seen
= false;
5450 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5452 vec
= (offset_type
*) (index
.constant_pool
5453 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5454 vec_len
= MAYBE_SWAP (vec
[0]);
5455 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5457 struct dwarf2_per_cu_data
*per_cu
;
5458 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5459 /* This value is only valid for index versions >= 7. */
5460 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5461 gdb_index_symbol_kind symbol_kind
=
5462 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5463 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5464 /* Only check the symbol attributes if they're present.
5465 Indices prior to version 7 don't record them,
5466 and indices >= 7 may elide them for certain symbols
5467 (gold does this). */
5470 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5472 /* Work around gold/15646. */
5475 if (!is_static
&& global_seen
)
5481 /* Only check the symbol's kind if it has one. */
5486 case VARIABLES_DOMAIN
:
5487 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5490 case FUNCTIONS_DOMAIN
:
5491 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5495 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5503 /* Don't crash on bad data. */
5504 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
5505 + dwarf2_per_objfile
->n_type_units
))
5507 complaint (&symfile_complaints
,
5508 _(".gdb_index entry has bad CU index"
5510 objfile_name (dwarf2_per_objfile
->objfile
));
5514 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
5515 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5520 /* If FILE_MATCHER is non-NULL, set all the
5521 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5522 that match FILE_MATCHER. */
5525 dw_expand_symtabs_matching_file_matcher
5526 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5527 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5529 if (file_matcher
== NULL
)
5532 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5534 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5536 NULL
, xcalloc
, xfree
));
5537 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5539 NULL
, xcalloc
, xfree
));
5541 /* The rule is CUs specify all the files, including those used by
5542 any TU, so there's no need to scan TUs here. */
5544 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5547 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5548 struct quick_file_names
*file_data
;
5553 per_cu
->v
.quick
->mark
= 0;
5555 /* We only need to look at symtabs not already expanded. */
5556 if (per_cu
->v
.quick
->compunit_symtab
)
5559 file_data
= dw2_get_file_names (per_cu
);
5560 if (file_data
== NULL
)
5563 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5565 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5567 per_cu
->v
.quick
->mark
= 1;
5571 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
5573 const char *this_real_name
;
5575 if (file_matcher (file_data
->file_names
[j
], false))
5577 per_cu
->v
.quick
->mark
= 1;
5581 /* Before we invoke realpath, which can get expensive when many
5582 files are involved, do a quick comparison of the basenames. */
5583 if (!basenames_may_differ
5584 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5588 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5589 if (file_matcher (this_real_name
, false))
5591 per_cu
->v
.quick
->mark
= 1;
5596 slot
= htab_find_slot (per_cu
->v
.quick
->mark
5597 ? visited_found
.get ()
5598 : visited_not_found
.get (),
5605 dw2_expand_symtabs_matching
5606 (struct objfile
*objfile
,
5607 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5608 const lookup_name_info
&lookup_name
,
5609 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5610 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5611 enum search_domain kind
)
5613 struct dwarf2_per_objfile
*dwarf2_per_objfile
5614 = get_dwarf2_per_objfile (objfile
);
5616 /* index_table is NULL if OBJF_READNOW. */
5617 if (!dwarf2_per_objfile
->index_table
)
5620 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5622 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5624 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5626 kind
, [&] (offset_type idx
)
5628 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5629 expansion_notify
, kind
);
5633 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5636 static struct compunit_symtab
*
5637 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5642 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5643 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5646 if (cust
->includes
== NULL
)
5649 for (i
= 0; cust
->includes
[i
]; ++i
)
5651 struct compunit_symtab
*s
= cust
->includes
[i
];
5653 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5661 static struct compunit_symtab
*
5662 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5663 struct bound_minimal_symbol msymbol
,
5665 struct obj_section
*section
,
5668 struct dwarf2_per_cu_data
*data
;
5669 struct compunit_symtab
*result
;
5671 if (!objfile
->psymtabs_addrmap
)
5674 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5679 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5680 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5681 paddress (get_objfile_arch (objfile
), pc
));
5684 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5686 gdb_assert (result
!= NULL
);
5691 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5692 void *data
, int need_fullname
)
5694 struct dwarf2_per_objfile
*dwarf2_per_objfile
5695 = get_dwarf2_per_objfile (objfile
);
5697 if (!dwarf2_per_objfile
->filenames_cache
)
5699 dwarf2_per_objfile
->filenames_cache
.emplace ();
5701 htab_up
visited (htab_create_alloc (10,
5702 htab_hash_pointer
, htab_eq_pointer
,
5703 NULL
, xcalloc
, xfree
));
5705 /* The rule is CUs specify all the files, including those used
5706 by any TU, so there's no need to scan TUs here. We can
5707 ignore file names coming from already-expanded CUs. */
5709 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5711 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
5713 if (per_cu
->v
.quick
->compunit_symtab
)
5715 void **slot
= htab_find_slot (visited
.get (),
5716 per_cu
->v
.quick
->file_names
,
5719 *slot
= per_cu
->v
.quick
->file_names
;
5723 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5725 dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5726 struct quick_file_names
*file_data
;
5729 /* We only need to look at symtabs not already expanded. */
5730 if (per_cu
->v
.quick
->compunit_symtab
)
5733 file_data
= dw2_get_file_names (per_cu
);
5734 if (file_data
== NULL
)
5737 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5740 /* Already visited. */
5745 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5747 const char *filename
= file_data
->file_names
[j
];
5748 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5753 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5755 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5758 this_real_name
= gdb_realpath (filename
);
5759 (*fun
) (filename
, this_real_name
.get (), data
);
5764 dw2_has_symbols (struct objfile
*objfile
)
5769 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5772 dw2_find_last_source_symtab
,
5773 dw2_forget_cached_source_info
,
5774 dw2_map_symtabs_matching_filename
,
5779 dw2_expand_symtabs_for_function
,
5780 dw2_expand_all_symtabs
,
5781 dw2_expand_symtabs_with_fullname
,
5782 dw2_map_matching_symbols
,
5783 dw2_expand_symtabs_matching
,
5784 dw2_find_pc_sect_compunit_symtab
,
5786 dw2_map_symbol_filenames
5789 /* DWARF-5 debug_names reader. */
5791 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5792 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5794 /* A helper function that reads the .debug_names section in SECTION
5795 and fills in MAP. FILENAME is the name of the file containing the
5796 section; it is used for error reporting.
5798 Returns true if all went well, false otherwise. */
5801 read_debug_names_from_section (struct objfile
*objfile
,
5802 const char *filename
,
5803 struct dwarf2_section_info
*section
,
5804 mapped_debug_names
&map
)
5806 if (dwarf2_section_empty_p (section
))
5809 /* Older elfutils strip versions could keep the section in the main
5810 executable while splitting it for the separate debug info file. */
5811 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5814 dwarf2_read_section (objfile
, section
);
5816 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5818 const gdb_byte
*addr
= section
->buffer
;
5820 bfd
*const abfd
= get_section_bfd_owner (section
);
5822 unsigned int bytes_read
;
5823 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5826 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5827 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5828 if (bytes_read
+ length
!= section
->size
)
5830 /* There may be multiple per-CU indices. */
5831 warning (_("Section .debug_names in %s length %s does not match "
5832 "section length %s, ignoring .debug_names."),
5833 filename
, plongest (bytes_read
+ length
),
5834 pulongest (section
->size
));
5838 /* The version number. */
5839 uint16_t version
= read_2_bytes (abfd
, addr
);
5843 warning (_("Section .debug_names in %s has unsupported version %d, "
5844 "ignoring .debug_names."),
5850 uint16_t padding
= read_2_bytes (abfd
, addr
);
5854 warning (_("Section .debug_names in %s has unsupported padding %d, "
5855 "ignoring .debug_names."),
5860 /* comp_unit_count - The number of CUs in the CU list. */
5861 map
.cu_count
= read_4_bytes (abfd
, addr
);
5864 /* local_type_unit_count - The number of TUs in the local TU
5866 map
.tu_count
= read_4_bytes (abfd
, addr
);
5869 /* foreign_type_unit_count - The number of TUs in the foreign TU
5871 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5873 if (foreign_tu_count
!= 0)
5875 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5876 "ignoring .debug_names."),
5877 filename
, static_cast<unsigned long> (foreign_tu_count
));
5881 /* bucket_count - The number of hash buckets in the hash lookup
5883 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5886 /* name_count - The number of unique names in the index. */
5887 map
.name_count
= read_4_bytes (abfd
, addr
);
5890 /* abbrev_table_size - The size in bytes of the abbreviations
5892 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5895 /* augmentation_string_size - The size in bytes of the augmentation
5896 string. This value is rounded up to a multiple of 4. */
5897 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5899 map
.augmentation_is_gdb
= ((augmentation_string_size
5900 == sizeof (dwarf5_augmentation
))
5901 && memcmp (addr
, dwarf5_augmentation
,
5902 sizeof (dwarf5_augmentation
)) == 0);
5903 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5904 addr
+= augmentation_string_size
;
5907 map
.cu_table_reordered
= addr
;
5908 addr
+= map
.cu_count
* map
.offset_size
;
5910 /* List of Local TUs */
5911 map
.tu_table_reordered
= addr
;
5912 addr
+= map
.tu_count
* map
.offset_size
;
5914 /* Hash Lookup Table */
5915 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5916 addr
+= map
.bucket_count
* 4;
5917 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5918 addr
+= map
.name_count
* 4;
5921 map
.name_table_string_offs_reordered
= addr
;
5922 addr
+= map
.name_count
* map
.offset_size
;
5923 map
.name_table_entry_offs_reordered
= addr
;
5924 addr
+= map
.name_count
* map
.offset_size
;
5926 const gdb_byte
*abbrev_table_start
= addr
;
5929 unsigned int bytes_read
;
5930 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5935 const auto insertpair
5936 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5937 if (!insertpair
.second
)
5939 warning (_("Section .debug_names in %s has duplicate index %s, "
5940 "ignoring .debug_names."),
5941 filename
, pulongest (index_num
));
5944 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5945 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5950 mapped_debug_names::index_val::attr attr
;
5951 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5953 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5955 if (attr
.form
== DW_FORM_implicit_const
)
5957 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5961 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5963 indexval
.attr_vec
.push_back (std::move (attr
));
5966 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5968 warning (_("Section .debug_names in %s has abbreviation_table "
5969 "of size %zu vs. written as %u, ignoring .debug_names."),
5970 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5973 map
.entry_pool
= addr
;
5978 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5982 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5983 const mapped_debug_names
&map
,
5984 dwarf2_section_info
§ion
,
5985 bool is_dwz
, int base_offset
)
5987 sect_offset sect_off_prev
;
5988 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5990 sect_offset sect_off_next
;
5991 if (i
< map
.cu_count
)
5994 = (sect_offset
) (extract_unsigned_integer
5995 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5997 map
.dwarf5_byte_order
));
6000 sect_off_next
= (sect_offset
) section
.size
;
6003 const ULONGEST length
= sect_off_next
- sect_off_prev
;
6004 dwarf2_per_objfile
->all_comp_units
[base_offset
+ (i
- 1)]
6005 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
6006 sect_off_prev
, length
);
6008 sect_off_prev
= sect_off_next
;
6012 /* Read the CU list from the mapped index, and use it to create all
6013 the CU objects for this dwarf2_per_objfile. */
6016 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6017 const mapped_debug_names
&map
,
6018 const mapped_debug_names
&dwz_map
)
6020 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6022 dwarf2_per_objfile
->n_comp_units
= map
.cu_count
+ dwz_map
.cu_count
;
6023 dwarf2_per_objfile
->all_comp_units
6024 = XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
6025 dwarf2_per_objfile
->n_comp_units
);
6027 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
6028 dwarf2_per_objfile
->info
,
6030 0 /* base_offset */);
6032 if (dwz_map
.cu_count
== 0)
6035 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
6036 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
6038 map
.cu_count
/* base_offset */);
6041 /* Read .debug_names. If everything went ok, initialize the "quick"
6042 elements of all the CUs and return true. Otherwise, return false. */
6045 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6047 mapped_debug_names
local_map (dwarf2_per_objfile
);
6048 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
6049 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6051 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
6052 &dwarf2_per_objfile
->debug_names
,
6056 /* Don't use the index if it's empty. */
6057 if (local_map
.name_count
== 0)
6060 /* If there is a .dwz file, read it so we can get its CU list as
6062 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
6065 if (!read_debug_names_from_section (objfile
,
6066 bfd_get_filename (dwz
->dwz_bfd
),
6067 &dwz
->debug_names
, dwz_map
))
6069 warning (_("could not read '.debug_names' section from %s; skipping"),
6070 bfd_get_filename (dwz
->dwz_bfd
));
6075 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
6077 if (local_map
.tu_count
!= 0)
6079 /* We can only handle a single .debug_types when we have an
6081 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
6084 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
6085 dwarf2_per_objfile
->types
, 0);
6087 create_signatured_type_table_from_debug_names
6088 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
6091 create_addrmap_from_aranges (dwarf2_per_objfile
,
6092 &dwarf2_per_objfile
->debug_aranges
);
6094 dwarf2_per_objfile
->debug_names_table
.reset
6095 (new mapped_debug_names (dwarf2_per_objfile
));
6096 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
6097 dwarf2_per_objfile
->using_index
= 1;
6098 dwarf2_per_objfile
->quick_file_names_table
=
6099 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6104 /* Symbol name hashing function as specified by DWARF-5. */
6107 dwarf5_djb_hash (const char *str_
)
6109 const unsigned char *str
= (const unsigned char *) str_
;
6111 /* Note: tolower here ignores UTF-8, which isn't fully compliant.
6112 See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */
6114 uint32_t hash
= 5381;
6115 while (int c
= *str
++)
6116 hash
= hash
* 33 + tolower (c
);
6120 /* Type used to manage iterating over all CUs looking for a symbol for
6123 class dw2_debug_names_iterator
6126 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
6127 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
6128 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6129 bool want_specific_block
,
6130 block_enum block_index
, domain_enum domain
,
6132 : m_map (map
), m_want_specific_block (want_specific_block
),
6133 m_block_index (block_index
), m_domain (domain
),
6134 m_addr (find_vec_in_debug_names (map
, name
))
6137 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6138 search_domain search
, uint32_t namei
)
6141 m_addr (find_vec_in_debug_names (map
, namei
))
6144 /* Return the next matching CU or NULL if there are no more. */
6145 dwarf2_per_cu_data
*next ();
6148 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6150 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6153 /* The internalized form of .debug_names. */
6154 const mapped_debug_names
&m_map
;
6156 /* If true, only look for symbols that match BLOCK_INDEX. */
6157 const bool m_want_specific_block
= false;
6159 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
6160 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
6162 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
6164 /* The kind of symbol we're looking for. */
6165 const domain_enum m_domain
= UNDEF_DOMAIN
;
6166 const search_domain m_search
= ALL_DOMAIN
;
6168 /* The list of CUs from the index entry of the symbol, or NULL if
6170 const gdb_byte
*m_addr
;
6174 mapped_debug_names::namei_to_name (uint32_t namei
) const
6176 const ULONGEST namei_string_offs
6177 = extract_unsigned_integer ((name_table_string_offs_reordered
6178 + namei
* offset_size
),
6181 return read_indirect_string_at_offset
6182 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
6185 /* Find a slot in .debug_names for the object named NAME. If NAME is
6186 found, return pointer to its pool data. If NAME cannot be found,
6190 dw2_debug_names_iterator::find_vec_in_debug_names
6191 (const mapped_debug_names
&map
, const char *name
)
6193 int (*cmp
) (const char *, const char *);
6195 if (current_language
->la_language
== language_cplus
6196 || current_language
->la_language
== language_fortran
6197 || current_language
->la_language
== language_d
)
6199 /* NAME is already canonical. Drop any qualifiers as
6200 .debug_names does not contain any. */
6202 if (strchr (name
, '(') != NULL
)
6204 gdb::unique_xmalloc_ptr
<char> without_params
6205 = cp_remove_params (name
);
6207 if (without_params
!= NULL
)
6209 name
= without_params
.get();
6214 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
6216 const uint32_t full_hash
= dwarf5_djb_hash (name
);
6218 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6219 (map
.bucket_table_reordered
6220 + (full_hash
% map
.bucket_count
)), 4,
6221 map
.dwarf5_byte_order
);
6225 if (namei
>= map
.name_count
)
6227 complaint (&symfile_complaints
,
6228 _("Wrong .debug_names with name index %u but name_count=%u "
6230 namei
, map
.name_count
,
6231 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6237 const uint32_t namei_full_hash
6238 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6239 (map
.hash_table_reordered
+ namei
), 4,
6240 map
.dwarf5_byte_order
);
6241 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
6244 if (full_hash
== namei_full_hash
)
6246 const char *const namei_string
= map
.namei_to_name (namei
);
6248 #if 0 /* An expensive sanity check. */
6249 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
6251 complaint (&symfile_complaints
,
6252 _("Wrong .debug_names hash for string at index %u "
6254 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
6259 if (cmp (namei_string
, name
) == 0)
6261 const ULONGEST namei_entry_offs
6262 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6263 + namei
* map
.offset_size
),
6264 map
.offset_size
, map
.dwarf5_byte_order
);
6265 return map
.entry_pool
+ namei_entry_offs
;
6270 if (namei
>= map
.name_count
)
6276 dw2_debug_names_iterator::find_vec_in_debug_names
6277 (const mapped_debug_names
&map
, uint32_t namei
)
6279 if (namei
>= map
.name_count
)
6281 complaint (&symfile_complaints
,
6282 _("Wrong .debug_names with name index %u but name_count=%u "
6284 namei
, map
.name_count
,
6285 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6289 const ULONGEST namei_entry_offs
6290 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6291 + namei
* map
.offset_size
),
6292 map
.offset_size
, map
.dwarf5_byte_order
);
6293 return map
.entry_pool
+ namei_entry_offs
;
6296 /* See dw2_debug_names_iterator. */
6298 dwarf2_per_cu_data
*
6299 dw2_debug_names_iterator::next ()
6304 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
6305 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6306 bfd
*const abfd
= objfile
->obfd
;
6310 unsigned int bytes_read
;
6311 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6312 m_addr
+= bytes_read
;
6316 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
6317 if (indexval_it
== m_map
.abbrev_map
.cend ())
6319 complaint (&symfile_complaints
,
6320 _("Wrong .debug_names undefined abbrev code %s "
6322 pulongest (abbrev
), objfile_name (objfile
));
6325 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
6326 bool have_is_static
= false;
6328 dwarf2_per_cu_data
*per_cu
= NULL
;
6329 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
6334 case DW_FORM_implicit_const
:
6335 ull
= attr
.implicit_const
;
6337 case DW_FORM_flag_present
:
6341 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6342 m_addr
+= bytes_read
;
6345 complaint (&symfile_complaints
,
6346 _("Unsupported .debug_names form %s [in module %s]"),
6347 dwarf_form_name (attr
.form
),
6348 objfile_name (objfile
));
6351 switch (attr
.dw_idx
)
6353 case DW_IDX_compile_unit
:
6354 /* Don't crash on bad data. */
6355 if (ull
>= dwarf2_per_objfile
->n_comp_units
)
6357 complaint (&symfile_complaints
,
6358 _(".debug_names entry has bad CU index %s"
6361 objfile_name (dwarf2_per_objfile
->objfile
));
6364 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, ull
);
6366 case DW_IDX_type_unit
:
6367 /* Don't crash on bad data. */
6368 if (ull
>= dwarf2_per_objfile
->n_type_units
)
6370 complaint (&symfile_complaints
,
6371 _(".debug_names entry has bad TU index %s"
6374 objfile_name (dwarf2_per_objfile
->objfile
));
6377 per_cu
= dw2_get_cutu (dwarf2_per_objfile
,
6378 dwarf2_per_objfile
->n_comp_units
+ ull
);
6380 case DW_IDX_GNU_internal
:
6381 if (!m_map
.augmentation_is_gdb
)
6383 have_is_static
= true;
6386 case DW_IDX_GNU_external
:
6387 if (!m_map
.augmentation_is_gdb
)
6389 have_is_static
= true;
6395 /* Skip if already read in. */
6396 if (per_cu
->v
.quick
->compunit_symtab
)
6399 /* Check static vs global. */
6402 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
6403 if (m_want_specific_block
&& want_static
!= is_static
)
6407 /* Match dw2_symtab_iter_next, symbol_kind
6408 and debug_names::psymbol_tag. */
6412 switch (indexval
.dwarf_tag
)
6414 case DW_TAG_variable
:
6415 case DW_TAG_subprogram
:
6416 /* Some types are also in VAR_DOMAIN. */
6417 case DW_TAG_typedef
:
6418 case DW_TAG_structure_type
:
6425 switch (indexval
.dwarf_tag
)
6427 case DW_TAG_typedef
:
6428 case DW_TAG_structure_type
:
6435 switch (indexval
.dwarf_tag
)
6438 case DW_TAG_variable
:
6448 /* Match dw2_expand_symtabs_matching, symbol_kind and
6449 debug_names::psymbol_tag. */
6452 case VARIABLES_DOMAIN
:
6453 switch (indexval
.dwarf_tag
)
6455 case DW_TAG_variable
:
6461 case FUNCTIONS_DOMAIN
:
6462 switch (indexval
.dwarf_tag
)
6464 case DW_TAG_subprogram
:
6471 switch (indexval
.dwarf_tag
)
6473 case DW_TAG_typedef
:
6474 case DW_TAG_structure_type
:
6487 static struct compunit_symtab
*
6488 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6489 const char *name
, domain_enum domain
)
6491 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6492 struct dwarf2_per_objfile
*dwarf2_per_objfile
6493 = get_dwarf2_per_objfile (objfile
);
6495 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6498 /* index is NULL if OBJF_READNOW. */
6501 const auto &map
= *mapp
;
6503 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6504 block_index
, domain
, name
);
6506 struct compunit_symtab
*stab_best
= NULL
;
6507 struct dwarf2_per_cu_data
*per_cu
;
6508 while ((per_cu
= iter
.next ()) != NULL
)
6510 struct symbol
*sym
, *with_opaque
= NULL
;
6511 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6512 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6513 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6515 sym
= block_find_symbol (block
, name
, domain
,
6516 block_find_non_opaque_type_preferred
,
6519 /* Some caution must be observed with overloaded functions and
6520 methods, since the index will not contain any overload
6521 information (but NAME might contain it). */
6524 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6526 if (with_opaque
!= NULL
6527 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6530 /* Keep looking through other CUs. */
6536 /* This dumps minimal information about .debug_names. It is called
6537 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6538 uses this to verify that .debug_names has been loaded. */
6541 dw2_debug_names_dump (struct objfile
*objfile
)
6543 struct dwarf2_per_objfile
*dwarf2_per_objfile
6544 = get_dwarf2_per_objfile (objfile
);
6546 gdb_assert (dwarf2_per_objfile
->using_index
);
6547 printf_filtered (".debug_names:");
6548 if (dwarf2_per_objfile
->debug_names_table
)
6549 printf_filtered (" exists\n");
6551 printf_filtered (" faked for \"readnow\"\n");
6552 printf_filtered ("\n");
6556 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6557 const char *func_name
)
6559 struct dwarf2_per_objfile
*dwarf2_per_objfile
6560 = get_dwarf2_per_objfile (objfile
);
6562 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6563 if (dwarf2_per_objfile
->debug_names_table
)
6565 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6567 /* Note: It doesn't matter what we pass for block_index here. */
6568 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6569 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6571 struct dwarf2_per_cu_data
*per_cu
;
6572 while ((per_cu
= iter
.next ()) != NULL
)
6573 dw2_instantiate_symtab (per_cu
);
6578 dw2_debug_names_expand_symtabs_matching
6579 (struct objfile
*objfile
,
6580 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6581 const lookup_name_info
&lookup_name
,
6582 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6583 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6584 enum search_domain kind
)
6586 struct dwarf2_per_objfile
*dwarf2_per_objfile
6587 = get_dwarf2_per_objfile (objfile
);
6589 /* debug_names_table is NULL if OBJF_READNOW. */
6590 if (!dwarf2_per_objfile
->debug_names_table
)
6593 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6595 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6597 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6599 kind
, [&] (offset_type namei
)
6601 /* The name was matched, now expand corresponding CUs that were
6603 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6605 struct dwarf2_per_cu_data
*per_cu
;
6606 while ((per_cu
= iter
.next ()) != NULL
)
6607 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6612 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6615 dw2_find_last_source_symtab
,
6616 dw2_forget_cached_source_info
,
6617 dw2_map_symtabs_matching_filename
,
6618 dw2_debug_names_lookup_symbol
,
6620 dw2_debug_names_dump
,
6622 dw2_debug_names_expand_symtabs_for_function
,
6623 dw2_expand_all_symtabs
,
6624 dw2_expand_symtabs_with_fullname
,
6625 dw2_map_matching_symbols
,
6626 dw2_debug_names_expand_symtabs_matching
,
6627 dw2_find_pc_sect_compunit_symtab
,
6629 dw2_map_symbol_filenames
6632 /* See symfile.h. */
6635 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6637 struct dwarf2_per_objfile
*dwarf2_per_objfile
6638 = get_dwarf2_per_objfile (objfile
);
6640 /* If we're about to read full symbols, don't bother with the
6641 indices. In this case we also don't care if some other debug
6642 format is making psymtabs, because they are all about to be
6644 if ((objfile
->flags
& OBJF_READNOW
))
6648 dwarf2_per_objfile
->using_index
= 1;
6649 create_all_comp_units (dwarf2_per_objfile
);
6650 create_all_type_units (dwarf2_per_objfile
);
6651 dwarf2_per_objfile
->quick_file_names_table
=
6652 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6654 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
6655 + dwarf2_per_objfile
->n_type_units
); ++i
)
6657 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
6659 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6660 struct dwarf2_per_cu_quick_data
);
6663 /* Return 1 so that gdb sees the "quick" functions. However,
6664 these functions will be no-ops because we will have expanded
6666 *index_kind
= dw_index_kind::GDB_INDEX
;
6670 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6672 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6676 if (dwarf2_read_index (objfile
))
6678 *index_kind
= dw_index_kind::GDB_INDEX
;
6687 /* Build a partial symbol table. */
6690 dwarf2_build_psymtabs (struct objfile
*objfile
)
6692 struct dwarf2_per_objfile
*dwarf2_per_objfile
6693 = get_dwarf2_per_objfile (objfile
);
6695 if (objfile
->global_psymbols
.capacity () == 0
6696 && objfile
->static_psymbols
.capacity () == 0)
6697 init_psymbol_list (objfile
, 1024);
6701 /* This isn't really ideal: all the data we allocate on the
6702 objfile's obstack is still uselessly kept around. However,
6703 freeing it seems unsafe. */
6704 psymtab_discarder
psymtabs (objfile
);
6705 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6708 CATCH (except
, RETURN_MASK_ERROR
)
6710 exception_print (gdb_stderr
, except
);
6715 /* Return the total length of the CU described by HEADER. */
6718 get_cu_length (const struct comp_unit_head
*header
)
6720 return header
->initial_length_size
+ header
->length
;
6723 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6726 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6728 sect_offset bottom
= cu_header
->sect_off
;
6729 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6731 return sect_off
>= bottom
&& sect_off
< top
;
6734 /* Find the base address of the compilation unit for range lists and
6735 location lists. It will normally be specified by DW_AT_low_pc.
6736 In DWARF-3 draft 4, the base address could be overridden by
6737 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6738 compilation units with discontinuous ranges. */
6741 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6743 struct attribute
*attr
;
6746 cu
->base_address
= 0;
6748 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6751 cu
->base_address
= attr_value_as_address (attr
);
6756 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6759 cu
->base_address
= attr_value_as_address (attr
);
6765 /* Read in the comp unit header information from the debug_info at info_ptr.
6766 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6767 NOTE: This leaves members offset, first_die_offset to be filled in
6770 static const gdb_byte
*
6771 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6772 const gdb_byte
*info_ptr
,
6773 struct dwarf2_section_info
*section
,
6774 rcuh_kind section_kind
)
6777 unsigned int bytes_read
;
6778 const char *filename
= get_section_file_name (section
);
6779 bfd
*abfd
= get_section_bfd_owner (section
);
6781 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6782 cu_header
->initial_length_size
= bytes_read
;
6783 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6784 info_ptr
+= bytes_read
;
6785 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6787 if (cu_header
->version
< 5)
6788 switch (section_kind
)
6790 case rcuh_kind::COMPILE
:
6791 cu_header
->unit_type
= DW_UT_compile
;
6793 case rcuh_kind::TYPE
:
6794 cu_header
->unit_type
= DW_UT_type
;
6797 internal_error (__FILE__
, __LINE__
,
6798 _("read_comp_unit_head: invalid section_kind"));
6802 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6803 (read_1_byte (abfd
, info_ptr
));
6805 switch (cu_header
->unit_type
)
6808 if (section_kind
!= rcuh_kind::COMPILE
)
6809 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6810 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6814 section_kind
= rcuh_kind::TYPE
;
6817 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6818 "(is %d, should be %d or %d) [in module %s]"),
6819 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6822 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6825 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6828 info_ptr
+= bytes_read
;
6829 if (cu_header
->version
< 5)
6831 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6834 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6835 if (signed_addr
< 0)
6836 internal_error (__FILE__
, __LINE__
,
6837 _("read_comp_unit_head: dwarf from non elf file"));
6838 cu_header
->signed_addr_p
= signed_addr
;
6840 if (section_kind
== rcuh_kind::TYPE
)
6842 LONGEST type_offset
;
6844 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6847 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6848 info_ptr
+= bytes_read
;
6849 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6850 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6851 error (_("Dwarf Error: Too big type_offset in compilation unit "
6852 "header (is %s) [in module %s]"), plongest (type_offset
),
6859 /* Helper function that returns the proper abbrev section for
6862 static struct dwarf2_section_info
*
6863 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6865 struct dwarf2_section_info
*abbrev
;
6866 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6868 if (this_cu
->is_dwz
)
6869 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6871 abbrev
= &dwarf2_per_objfile
->abbrev
;
6876 /* Subroutine of read_and_check_comp_unit_head and
6877 read_and_check_type_unit_head to simplify them.
6878 Perform various error checking on the header. */
6881 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6882 struct comp_unit_head
*header
,
6883 struct dwarf2_section_info
*section
,
6884 struct dwarf2_section_info
*abbrev_section
)
6886 const char *filename
= get_section_file_name (section
);
6888 if (header
->version
< 2 || header
->version
> 5)
6889 error (_("Dwarf Error: wrong version in compilation unit header "
6890 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6893 if (to_underlying (header
->abbrev_sect_off
)
6894 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6895 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6896 "(offset %s + 6) [in module %s]"),
6897 sect_offset_str (header
->abbrev_sect_off
),
6898 sect_offset_str (header
->sect_off
),
6901 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6902 avoid potential 32-bit overflow. */
6903 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6905 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6906 "(offset %s + 0) [in module %s]"),
6907 header
->length
, sect_offset_str (header
->sect_off
),
6911 /* Read in a CU/TU header and perform some basic error checking.
6912 The contents of the header are stored in HEADER.
6913 The result is a pointer to the start of the first DIE. */
6915 static const gdb_byte
*
6916 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6917 struct comp_unit_head
*header
,
6918 struct dwarf2_section_info
*section
,
6919 struct dwarf2_section_info
*abbrev_section
,
6920 const gdb_byte
*info_ptr
,
6921 rcuh_kind section_kind
)
6923 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6925 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6927 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6929 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6931 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6937 /* Fetch the abbreviation table offset from a comp or type unit header. */
6940 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6941 struct dwarf2_section_info
*section
,
6942 sect_offset sect_off
)
6944 bfd
*abfd
= get_section_bfd_owner (section
);
6945 const gdb_byte
*info_ptr
;
6946 unsigned int initial_length_size
, offset_size
;
6949 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6950 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6951 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6952 offset_size
= initial_length_size
== 4 ? 4 : 8;
6953 info_ptr
+= initial_length_size
;
6955 version
= read_2_bytes (abfd
, info_ptr
);
6959 /* Skip unit type and address size. */
6963 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6966 /* Allocate a new partial symtab for file named NAME and mark this new
6967 partial symtab as being an include of PST. */
6970 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6971 struct objfile
*objfile
)
6973 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6975 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6977 /* It shares objfile->objfile_obstack. */
6978 subpst
->dirname
= pst
->dirname
;
6981 subpst
->textlow
= 0;
6982 subpst
->texthigh
= 0;
6984 subpst
->dependencies
6985 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6986 subpst
->dependencies
[0] = pst
;
6987 subpst
->number_of_dependencies
= 1;
6989 subpst
->globals_offset
= 0;
6990 subpst
->n_global_syms
= 0;
6991 subpst
->statics_offset
= 0;
6992 subpst
->n_static_syms
= 0;
6993 subpst
->compunit_symtab
= NULL
;
6994 subpst
->read_symtab
= pst
->read_symtab
;
6997 /* No private part is necessary for include psymtabs. This property
6998 can be used to differentiate between such include psymtabs and
6999 the regular ones. */
7000 subpst
->read_symtab_private
= NULL
;
7003 /* Read the Line Number Program data and extract the list of files
7004 included by the source file represented by PST. Build an include
7005 partial symtab for each of these included files. */
7008 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
7009 struct die_info
*die
,
7010 struct partial_symtab
*pst
)
7013 struct attribute
*attr
;
7015 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7017 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
7019 return; /* No linetable, so no includes. */
7021 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
7022 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
7026 hash_signatured_type (const void *item
)
7028 const struct signatured_type
*sig_type
7029 = (const struct signatured_type
*) item
;
7031 /* This drops the top 32 bits of the signature, but is ok for a hash. */
7032 return sig_type
->signature
;
7036 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
7038 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
7039 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
7041 return lhs
->signature
== rhs
->signature
;
7044 /* Allocate a hash table for signatured types. */
7047 allocate_signatured_type_table (struct objfile
*objfile
)
7049 return htab_create_alloc_ex (41,
7050 hash_signatured_type
,
7053 &objfile
->objfile_obstack
,
7054 hashtab_obstack_allocate
,
7055 dummy_obstack_deallocate
);
7058 /* A helper function to add a signatured type CU to a table. */
7061 add_signatured_type_cu_to_table (void **slot
, void *datum
)
7063 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
7064 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
7072 /* A helper for create_debug_types_hash_table. Read types from SECTION
7073 and fill them into TYPES_HTAB. It will process only type units,
7074 therefore DW_UT_type. */
7077 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7078 struct dwo_file
*dwo_file
,
7079 dwarf2_section_info
*section
, htab_t
&types_htab
,
7080 rcuh_kind section_kind
)
7082 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7083 struct dwarf2_section_info
*abbrev_section
;
7085 const gdb_byte
*info_ptr
, *end_ptr
;
7087 abbrev_section
= (dwo_file
!= NULL
7088 ? &dwo_file
->sections
.abbrev
7089 : &dwarf2_per_objfile
->abbrev
);
7091 if (dwarf_read_debug
)
7092 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
7093 get_section_name (section
),
7094 get_section_file_name (abbrev_section
));
7096 dwarf2_read_section (objfile
, section
);
7097 info_ptr
= section
->buffer
;
7099 if (info_ptr
== NULL
)
7102 /* We can't set abfd until now because the section may be empty or
7103 not present, in which case the bfd is unknown. */
7104 abfd
= get_section_bfd_owner (section
);
7106 /* We don't use init_cutu_and_read_dies_simple, or some such, here
7107 because we don't need to read any dies: the signature is in the
7110 end_ptr
= info_ptr
+ section
->size
;
7111 while (info_ptr
< end_ptr
)
7113 struct signatured_type
*sig_type
;
7114 struct dwo_unit
*dwo_tu
;
7116 const gdb_byte
*ptr
= info_ptr
;
7117 struct comp_unit_head header
;
7118 unsigned int length
;
7120 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
7122 /* Initialize it due to a false compiler warning. */
7123 header
.signature
= -1;
7124 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
7126 /* We need to read the type's signature in order to build the hash
7127 table, but we don't need anything else just yet. */
7129 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
7130 abbrev_section
, ptr
, section_kind
);
7132 length
= get_cu_length (&header
);
7134 /* Skip dummy type units. */
7135 if (ptr
>= info_ptr
+ length
7136 || peek_abbrev_code (abfd
, ptr
) == 0
7137 || header
.unit_type
!= DW_UT_type
)
7143 if (types_htab
== NULL
)
7146 types_htab
= allocate_dwo_unit_table (objfile
);
7148 types_htab
= allocate_signatured_type_table (objfile
);
7154 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7156 dwo_tu
->dwo_file
= dwo_file
;
7157 dwo_tu
->signature
= header
.signature
;
7158 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7159 dwo_tu
->section
= section
;
7160 dwo_tu
->sect_off
= sect_off
;
7161 dwo_tu
->length
= length
;
7165 /* N.B.: type_offset is not usable if this type uses a DWO file.
7166 The real type_offset is in the DWO file. */
7168 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7169 struct signatured_type
);
7170 sig_type
->signature
= header
.signature
;
7171 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7172 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7173 sig_type
->per_cu
.is_debug_types
= 1;
7174 sig_type
->per_cu
.section
= section
;
7175 sig_type
->per_cu
.sect_off
= sect_off
;
7176 sig_type
->per_cu
.length
= length
;
7179 slot
= htab_find_slot (types_htab
,
7180 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
7182 gdb_assert (slot
!= NULL
);
7185 sect_offset dup_sect_off
;
7189 const struct dwo_unit
*dup_tu
7190 = (const struct dwo_unit
*) *slot
;
7192 dup_sect_off
= dup_tu
->sect_off
;
7196 const struct signatured_type
*dup_tu
7197 = (const struct signatured_type
*) *slot
;
7199 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
7202 complaint (&symfile_complaints
,
7203 _("debug type entry at offset %s is duplicate to"
7204 " the entry at offset %s, signature %s"),
7205 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
7206 hex_string (header
.signature
));
7208 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
7210 if (dwarf_read_debug
> 1)
7211 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
7212 sect_offset_str (sect_off
),
7213 hex_string (header
.signature
));
7219 /* Create the hash table of all entries in the .debug_types
7220 (or .debug_types.dwo) section(s).
7221 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
7222 otherwise it is NULL.
7224 The result is a pointer to the hash table or NULL if there are no types.
7226 Note: This function processes DWO files only, not DWP files. */
7229 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7230 struct dwo_file
*dwo_file
,
7231 VEC (dwarf2_section_info_def
) *types
,
7235 struct dwarf2_section_info
*section
;
7237 if (VEC_empty (dwarf2_section_info_def
, types
))
7241 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
7243 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
7244 types_htab
, rcuh_kind::TYPE
);
7247 /* Create the hash table of all entries in the .debug_types section,
7248 and initialize all_type_units.
7249 The result is zero if there is an error (e.g. missing .debug_types section),
7250 otherwise non-zero. */
7253 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7255 htab_t types_htab
= NULL
;
7256 struct signatured_type
**iter
;
7258 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
7259 &dwarf2_per_objfile
->info
, types_htab
,
7260 rcuh_kind::COMPILE
);
7261 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
7262 dwarf2_per_objfile
->types
, types_htab
);
7263 if (types_htab
== NULL
)
7265 dwarf2_per_objfile
->signatured_types
= NULL
;
7269 dwarf2_per_objfile
->signatured_types
= types_htab
;
7271 dwarf2_per_objfile
->n_type_units
7272 = dwarf2_per_objfile
->n_allocated_type_units
7273 = htab_elements (types_htab
);
7274 dwarf2_per_objfile
->all_type_units
=
7275 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
7276 iter
= &dwarf2_per_objfile
->all_type_units
[0];
7277 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
7278 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
7279 == dwarf2_per_objfile
->n_type_units
);
7284 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
7285 If SLOT is non-NULL, it is the entry to use in the hash table.
7286 Otherwise we find one. */
7288 static struct signatured_type
*
7289 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
7292 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7293 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
7294 struct signatured_type
*sig_type
;
7296 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
7298 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
7300 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
7301 dwarf2_per_objfile
->n_allocated_type_units
= 1;
7302 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
7303 dwarf2_per_objfile
->all_type_units
7304 = XRESIZEVEC (struct signatured_type
*,
7305 dwarf2_per_objfile
->all_type_units
,
7306 dwarf2_per_objfile
->n_allocated_type_units
);
7307 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
7309 dwarf2_per_objfile
->n_type_units
= n_type_units
;
7311 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7312 struct signatured_type
);
7313 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
7314 sig_type
->signature
= sig
;
7315 sig_type
->per_cu
.is_debug_types
= 1;
7316 if (dwarf2_per_objfile
->using_index
)
7318 sig_type
->per_cu
.v
.quick
=
7319 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7320 struct dwarf2_per_cu_quick_data
);
7325 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7328 gdb_assert (*slot
== NULL
);
7330 /* The rest of sig_type must be filled in by the caller. */
7334 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7335 Fill in SIG_ENTRY with DWO_ENTRY. */
7338 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7339 struct signatured_type
*sig_entry
,
7340 struct dwo_unit
*dwo_entry
)
7342 /* Make sure we're not clobbering something we don't expect to. */
7343 gdb_assert (! sig_entry
->per_cu
.queued
);
7344 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7345 if (dwarf2_per_objfile
->using_index
)
7347 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7348 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7351 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7352 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7353 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7354 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7355 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7357 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7358 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7359 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7360 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7361 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7362 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7363 sig_entry
->dwo_unit
= dwo_entry
;
7366 /* Subroutine of lookup_signatured_type.
7367 If we haven't read the TU yet, create the signatured_type data structure
7368 for a TU to be read in directly from a DWO file, bypassing the stub.
7369 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7370 using .gdb_index, then when reading a CU we want to stay in the DWO file
7371 containing that CU. Otherwise we could end up reading several other DWO
7372 files (due to comdat folding) to process the transitive closure of all the
7373 mentioned TUs, and that can be slow. The current DWO file will have every
7374 type signature that it needs.
7375 We only do this for .gdb_index because in the psymtab case we already have
7376 to read all the DWOs to build the type unit groups. */
7378 static struct signatured_type
*
7379 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7381 struct dwarf2_per_objfile
*dwarf2_per_objfile
7382 = cu
->per_cu
->dwarf2_per_objfile
;
7383 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7384 struct dwo_file
*dwo_file
;
7385 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7386 struct signatured_type find_sig_entry
, *sig_entry
;
7389 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7391 /* If TU skeletons have been removed then we may not have read in any
7393 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7395 dwarf2_per_objfile
->signatured_types
7396 = allocate_signatured_type_table (objfile
);
7399 /* We only ever need to read in one copy of a signatured type.
7400 Use the global signatured_types array to do our own comdat-folding
7401 of types. If this is the first time we're reading this TU, and
7402 the TU has an entry in .gdb_index, replace the recorded data from
7403 .gdb_index with this TU. */
7405 find_sig_entry
.signature
= sig
;
7406 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7407 &find_sig_entry
, INSERT
);
7408 sig_entry
= (struct signatured_type
*) *slot
;
7410 /* We can get here with the TU already read, *or* in the process of being
7411 read. Don't reassign the global entry to point to this DWO if that's
7412 the case. Also note that if the TU is already being read, it may not
7413 have come from a DWO, the program may be a mix of Fission-compiled
7414 code and non-Fission-compiled code. */
7416 /* Have we already tried to read this TU?
7417 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7418 needn't exist in the global table yet). */
7419 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7422 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7423 dwo_unit of the TU itself. */
7424 dwo_file
= cu
->dwo_unit
->dwo_file
;
7426 /* Ok, this is the first time we're reading this TU. */
7427 if (dwo_file
->tus
== NULL
)
7429 find_dwo_entry
.signature
= sig
;
7430 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7431 if (dwo_entry
== NULL
)
7434 /* If the global table doesn't have an entry for this TU, add one. */
7435 if (sig_entry
== NULL
)
7436 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7438 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7439 sig_entry
->per_cu
.tu_read
= 1;
7443 /* Subroutine of lookup_signatured_type.
7444 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7445 then try the DWP file. If the TU stub (skeleton) has been removed then
7446 it won't be in .gdb_index. */
7448 static struct signatured_type
*
7449 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7451 struct dwarf2_per_objfile
*dwarf2_per_objfile
7452 = cu
->per_cu
->dwarf2_per_objfile
;
7453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7454 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7455 struct dwo_unit
*dwo_entry
;
7456 struct signatured_type find_sig_entry
, *sig_entry
;
7459 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7460 gdb_assert (dwp_file
!= NULL
);
7462 /* If TU skeletons have been removed then we may not have read in any
7464 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7466 dwarf2_per_objfile
->signatured_types
7467 = allocate_signatured_type_table (objfile
);
7470 find_sig_entry
.signature
= sig
;
7471 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7472 &find_sig_entry
, INSERT
);
7473 sig_entry
= (struct signatured_type
*) *slot
;
7475 /* Have we already tried to read this TU?
7476 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7477 needn't exist in the global table yet). */
7478 if (sig_entry
!= NULL
)
7481 if (dwp_file
->tus
== NULL
)
7483 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7484 sig
, 1 /* is_debug_types */);
7485 if (dwo_entry
== NULL
)
7488 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7489 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7494 /* Lookup a signature based type for DW_FORM_ref_sig8.
7495 Returns NULL if signature SIG is not present in the table.
7496 It is up to the caller to complain about this. */
7498 static struct signatured_type
*
7499 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7501 struct dwarf2_per_objfile
*dwarf2_per_objfile
7502 = cu
->per_cu
->dwarf2_per_objfile
;
7505 && dwarf2_per_objfile
->using_index
)
7507 /* We're in a DWO/DWP file, and we're using .gdb_index.
7508 These cases require special processing. */
7509 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7510 return lookup_dwo_signatured_type (cu
, sig
);
7512 return lookup_dwp_signatured_type (cu
, sig
);
7516 struct signatured_type find_entry
, *entry
;
7518 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7520 find_entry
.signature
= sig
;
7521 entry
= ((struct signatured_type
*)
7522 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7527 /* Low level DIE reading support. */
7529 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7532 init_cu_die_reader (struct die_reader_specs
*reader
,
7533 struct dwarf2_cu
*cu
,
7534 struct dwarf2_section_info
*section
,
7535 struct dwo_file
*dwo_file
,
7536 struct abbrev_table
*abbrev_table
)
7538 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7539 reader
->abfd
= get_section_bfd_owner (section
);
7541 reader
->dwo_file
= dwo_file
;
7542 reader
->die_section
= section
;
7543 reader
->buffer
= section
->buffer
;
7544 reader
->buffer_end
= section
->buffer
+ section
->size
;
7545 reader
->comp_dir
= NULL
;
7546 reader
->abbrev_table
= abbrev_table
;
7549 /* Subroutine of init_cutu_and_read_dies to simplify it.
7550 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7551 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7554 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7555 from it to the DIE in the DWO. If NULL we are skipping the stub.
7556 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7557 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7558 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7559 STUB_COMP_DIR may be non-NULL.
7560 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7561 are filled in with the info of the DIE from the DWO file.
7562 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7563 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7564 kept around for at least as long as *RESULT_READER.
7566 The result is non-zero if a valid (non-dummy) DIE was found. */
7569 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7570 struct dwo_unit
*dwo_unit
,
7571 struct die_info
*stub_comp_unit_die
,
7572 const char *stub_comp_dir
,
7573 struct die_reader_specs
*result_reader
,
7574 const gdb_byte
**result_info_ptr
,
7575 struct die_info
**result_comp_unit_die
,
7576 int *result_has_children
,
7577 abbrev_table_up
*result_dwo_abbrev_table
)
7579 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7580 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7581 struct dwarf2_cu
*cu
= this_cu
->cu
;
7583 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7584 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7585 int i
,num_extra_attrs
;
7586 struct dwarf2_section_info
*dwo_abbrev_section
;
7587 struct attribute
*attr
;
7588 struct die_info
*comp_unit_die
;
7590 /* At most one of these may be provided. */
7591 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7593 /* These attributes aren't processed until later:
7594 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7595 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7596 referenced later. However, these attributes are found in the stub
7597 which we won't have later. In order to not impose this complication
7598 on the rest of the code, we read them here and copy them to the
7607 if (stub_comp_unit_die
!= NULL
)
7609 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7611 if (! this_cu
->is_debug_types
)
7612 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7613 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7614 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7615 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7616 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7618 /* There should be a DW_AT_addr_base attribute here (if needed).
7619 We need the value before we can process DW_FORM_GNU_addr_index. */
7621 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7623 cu
->addr_base
= DW_UNSND (attr
);
7625 /* There should be a DW_AT_ranges_base attribute here (if needed).
7626 We need the value before we can process DW_AT_ranges. */
7627 cu
->ranges_base
= 0;
7628 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7630 cu
->ranges_base
= DW_UNSND (attr
);
7632 else if (stub_comp_dir
!= NULL
)
7634 /* Reconstruct the comp_dir attribute to simplify the code below. */
7635 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7636 comp_dir
->name
= DW_AT_comp_dir
;
7637 comp_dir
->form
= DW_FORM_string
;
7638 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7639 DW_STRING (comp_dir
) = stub_comp_dir
;
7642 /* Set up for reading the DWO CU/TU. */
7643 cu
->dwo_unit
= dwo_unit
;
7644 dwarf2_section_info
*section
= dwo_unit
->section
;
7645 dwarf2_read_section (objfile
, section
);
7646 abfd
= get_section_bfd_owner (section
);
7647 begin_info_ptr
= info_ptr
= (section
->buffer
7648 + to_underlying (dwo_unit
->sect_off
));
7649 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7651 if (this_cu
->is_debug_types
)
7653 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7655 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7656 &cu
->header
, section
,
7658 info_ptr
, rcuh_kind::TYPE
);
7659 /* This is not an assert because it can be caused by bad debug info. */
7660 if (sig_type
->signature
!= cu
->header
.signature
)
7662 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7663 " TU at offset %s [in module %s]"),
7664 hex_string (sig_type
->signature
),
7665 hex_string (cu
->header
.signature
),
7666 sect_offset_str (dwo_unit
->sect_off
),
7667 bfd_get_filename (abfd
));
7669 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7670 /* For DWOs coming from DWP files, we don't know the CU length
7671 nor the type's offset in the TU until now. */
7672 dwo_unit
->length
= get_cu_length (&cu
->header
);
7673 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7675 /* Establish the type offset that can be used to lookup the type.
7676 For DWO files, we don't know it until now. */
7677 sig_type
->type_offset_in_section
7678 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7682 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7683 &cu
->header
, section
,
7685 info_ptr
, rcuh_kind::COMPILE
);
7686 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7687 /* For DWOs coming from DWP files, we don't know the CU length
7689 dwo_unit
->length
= get_cu_length (&cu
->header
);
7692 *result_dwo_abbrev_table
7693 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7694 cu
->header
.abbrev_sect_off
);
7695 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7696 result_dwo_abbrev_table
->get ());
7698 /* Read in the die, but leave space to copy over the attributes
7699 from the stub. This has the benefit of simplifying the rest of
7700 the code - all the work to maintain the illusion of a single
7701 DW_TAG_{compile,type}_unit DIE is done here. */
7702 num_extra_attrs
= ((stmt_list
!= NULL
)
7706 + (comp_dir
!= NULL
));
7707 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7708 result_has_children
, num_extra_attrs
);
7710 /* Copy over the attributes from the stub to the DIE we just read in. */
7711 comp_unit_die
= *result_comp_unit_die
;
7712 i
= comp_unit_die
->num_attrs
;
7713 if (stmt_list
!= NULL
)
7714 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7716 comp_unit_die
->attrs
[i
++] = *low_pc
;
7717 if (high_pc
!= NULL
)
7718 comp_unit_die
->attrs
[i
++] = *high_pc
;
7720 comp_unit_die
->attrs
[i
++] = *ranges
;
7721 if (comp_dir
!= NULL
)
7722 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7723 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7725 if (dwarf_die_debug
)
7727 fprintf_unfiltered (gdb_stdlog
,
7728 "Read die from %s@0x%x of %s:\n",
7729 get_section_name (section
),
7730 (unsigned) (begin_info_ptr
- section
->buffer
),
7731 bfd_get_filename (abfd
));
7732 dump_die (comp_unit_die
, dwarf_die_debug
);
7735 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7736 TUs by skipping the stub and going directly to the entry in the DWO file.
7737 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7738 to get it via circuitous means. Blech. */
7739 if (comp_dir
!= NULL
)
7740 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7742 /* Skip dummy compilation units. */
7743 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7744 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7747 *result_info_ptr
= info_ptr
;
7751 /* Subroutine of init_cutu_and_read_dies to simplify it.
7752 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7753 Returns NULL if the specified DWO unit cannot be found. */
7755 static struct dwo_unit
*
7756 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7757 struct die_info
*comp_unit_die
)
7759 struct dwarf2_cu
*cu
= this_cu
->cu
;
7761 struct dwo_unit
*dwo_unit
;
7762 const char *comp_dir
, *dwo_name
;
7764 gdb_assert (cu
!= NULL
);
7766 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7767 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7768 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7770 if (this_cu
->is_debug_types
)
7772 struct signatured_type
*sig_type
;
7774 /* Since this_cu is the first member of struct signatured_type,
7775 we can go from a pointer to one to a pointer to the other. */
7776 sig_type
= (struct signatured_type
*) this_cu
;
7777 signature
= sig_type
->signature
;
7778 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7782 struct attribute
*attr
;
7784 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7786 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7788 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7789 signature
= DW_UNSND (attr
);
7790 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7797 /* Subroutine of init_cutu_and_read_dies to simplify it.
7798 See it for a description of the parameters.
7799 Read a TU directly from a DWO file, bypassing the stub. */
7802 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7803 int use_existing_cu
, int keep
,
7804 die_reader_func_ftype
*die_reader_func
,
7807 std::unique_ptr
<dwarf2_cu
> new_cu
;
7808 struct signatured_type
*sig_type
;
7809 struct die_reader_specs reader
;
7810 const gdb_byte
*info_ptr
;
7811 struct die_info
*comp_unit_die
;
7813 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7815 /* Verify we can do the following downcast, and that we have the
7817 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7818 sig_type
= (struct signatured_type
*) this_cu
;
7819 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7821 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7823 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7824 /* There's no need to do the rereading_dwo_cu handling that
7825 init_cutu_and_read_dies does since we don't read the stub. */
7829 /* If !use_existing_cu, this_cu->cu must be NULL. */
7830 gdb_assert (this_cu
->cu
== NULL
);
7831 new_cu
.reset (new dwarf2_cu (this_cu
));
7834 /* A future optimization, if needed, would be to use an existing
7835 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7836 could share abbrev tables. */
7838 /* The abbreviation table used by READER, this must live at least as long as
7840 abbrev_table_up dwo_abbrev_table
;
7842 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7843 NULL
/* stub_comp_unit_die */,
7844 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7846 &comp_unit_die
, &has_children
,
7847 &dwo_abbrev_table
) == 0)
7853 /* All the "real" work is done here. */
7854 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7856 /* This duplicates the code in init_cutu_and_read_dies,
7857 but the alternative is making the latter more complex.
7858 This function is only for the special case of using DWO files directly:
7859 no point in overly complicating the general case just to handle this. */
7860 if (new_cu
!= NULL
&& keep
)
7862 /* Link this CU into read_in_chain. */
7863 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7864 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7865 /* The chain owns it now. */
7870 /* Initialize a CU (or TU) and read its DIEs.
7871 If the CU defers to a DWO file, read the DWO file as well.
7873 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7874 Otherwise the table specified in the comp unit header is read in and used.
7875 This is an optimization for when we already have the abbrev table.
7877 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7878 Otherwise, a new CU is allocated with xmalloc.
7880 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7881 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7883 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7884 linker) then DIE_READER_FUNC will not get called. */
7887 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7888 struct abbrev_table
*abbrev_table
,
7889 int use_existing_cu
, int keep
,
7890 die_reader_func_ftype
*die_reader_func
,
7893 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7894 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7895 struct dwarf2_section_info
*section
= this_cu
->section
;
7896 bfd
*abfd
= get_section_bfd_owner (section
);
7897 struct dwarf2_cu
*cu
;
7898 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7899 struct die_reader_specs reader
;
7900 struct die_info
*comp_unit_die
;
7902 struct attribute
*attr
;
7903 struct signatured_type
*sig_type
= NULL
;
7904 struct dwarf2_section_info
*abbrev_section
;
7905 /* Non-zero if CU currently points to a DWO file and we need to
7906 reread it. When this happens we need to reread the skeleton die
7907 before we can reread the DWO file (this only applies to CUs, not TUs). */
7908 int rereading_dwo_cu
= 0;
7910 if (dwarf_die_debug
)
7911 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7912 this_cu
->is_debug_types
? "type" : "comp",
7913 sect_offset_str (this_cu
->sect_off
));
7915 if (use_existing_cu
)
7918 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7919 file (instead of going through the stub), short-circuit all of this. */
7920 if (this_cu
->reading_dwo_directly
)
7922 /* Narrow down the scope of possibilities to have to understand. */
7923 gdb_assert (this_cu
->is_debug_types
);
7924 gdb_assert (abbrev_table
== NULL
);
7925 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7926 die_reader_func
, data
);
7930 /* This is cheap if the section is already read in. */
7931 dwarf2_read_section (objfile
, section
);
7933 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7935 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7937 std::unique_ptr
<dwarf2_cu
> new_cu
;
7938 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7941 /* If this CU is from a DWO file we need to start over, we need to
7942 refetch the attributes from the skeleton CU.
7943 This could be optimized by retrieving those attributes from when we
7944 were here the first time: the previous comp_unit_die was stored in
7945 comp_unit_obstack. But there's no data yet that we need this
7947 if (cu
->dwo_unit
!= NULL
)
7948 rereading_dwo_cu
= 1;
7952 /* If !use_existing_cu, this_cu->cu must be NULL. */
7953 gdb_assert (this_cu
->cu
== NULL
);
7954 new_cu
.reset (new dwarf2_cu (this_cu
));
7958 /* Get the header. */
7959 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7961 /* We already have the header, there's no need to read it in again. */
7962 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7966 if (this_cu
->is_debug_types
)
7968 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7969 &cu
->header
, section
,
7970 abbrev_section
, info_ptr
,
7973 /* Since per_cu is the first member of struct signatured_type,
7974 we can go from a pointer to one to a pointer to the other. */
7975 sig_type
= (struct signatured_type
*) this_cu
;
7976 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7977 gdb_assert (sig_type
->type_offset_in_tu
7978 == cu
->header
.type_cu_offset_in_tu
);
7979 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7981 /* LENGTH has not been set yet for type units if we're
7982 using .gdb_index. */
7983 this_cu
->length
= get_cu_length (&cu
->header
);
7985 /* Establish the type offset that can be used to lookup the type. */
7986 sig_type
->type_offset_in_section
=
7987 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7989 this_cu
->dwarf_version
= cu
->header
.version
;
7993 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7994 &cu
->header
, section
,
7997 rcuh_kind::COMPILE
);
7999 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
8000 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
8001 this_cu
->dwarf_version
= cu
->header
.version
;
8005 /* Skip dummy compilation units. */
8006 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
8007 || peek_abbrev_code (abfd
, info_ptr
) == 0)
8010 /* If we don't have them yet, read the abbrevs for this compilation unit.
8011 And if we need to read them now, make sure they're freed when we're
8012 done (own the table through ABBREV_TABLE_HOLDER). */
8013 abbrev_table_up abbrev_table_holder
;
8014 if (abbrev_table
!= NULL
)
8015 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
8019 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
8020 cu
->header
.abbrev_sect_off
);
8021 abbrev_table
= abbrev_table_holder
.get ();
8024 /* Read the top level CU/TU die. */
8025 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
8026 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8028 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
8029 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
8030 table from the DWO file and pass the ownership over to us. It will be
8031 referenced from READER, so we must make sure to free it after we're done
8034 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
8035 DWO CU, that this test will fail (the attribute will not be present). */
8036 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
8037 abbrev_table_up dwo_abbrev_table
;
8040 struct dwo_unit
*dwo_unit
;
8041 struct die_info
*dwo_comp_unit_die
;
8045 complaint (&symfile_complaints
,
8046 _("compilation unit with DW_AT_GNU_dwo_name"
8047 " has children (offset %s) [in module %s]"),
8048 sect_offset_str (this_cu
->sect_off
),
8049 bfd_get_filename (abfd
));
8051 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
8052 if (dwo_unit
!= NULL
)
8054 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
8055 comp_unit_die
, NULL
,
8057 &dwo_comp_unit_die
, &has_children
,
8058 &dwo_abbrev_table
) == 0)
8063 comp_unit_die
= dwo_comp_unit_die
;
8067 /* Yikes, we couldn't find the rest of the DIE, we only have
8068 the stub. A complaint has already been logged. There's
8069 not much more we can do except pass on the stub DIE to
8070 die_reader_func. We don't want to throw an error on bad
8075 /* All of the above is setup for this call. Yikes. */
8076 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8078 /* Done, clean up. */
8079 if (new_cu
!= NULL
&& keep
)
8081 /* Link this CU into read_in_chain. */
8082 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
8083 dwarf2_per_objfile
->read_in_chain
= this_cu
;
8084 /* The chain owns it now. */
8089 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
8090 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
8091 to have already done the lookup to find the DWO file).
8093 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
8094 THIS_CU->is_debug_types, but nothing else.
8096 We fill in THIS_CU->length.
8098 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
8099 linker) then DIE_READER_FUNC will not get called.
8101 THIS_CU->cu is always freed when done.
8102 This is done in order to not leave THIS_CU->cu in a state where we have
8103 to care whether it refers to the "main" CU or the DWO CU. */
8106 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
8107 struct dwo_file
*dwo_file
,
8108 die_reader_func_ftype
*die_reader_func
,
8111 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
8112 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8113 struct dwarf2_section_info
*section
= this_cu
->section
;
8114 bfd
*abfd
= get_section_bfd_owner (section
);
8115 struct dwarf2_section_info
*abbrev_section
;
8116 const gdb_byte
*begin_info_ptr
, *info_ptr
;
8117 struct die_reader_specs reader
;
8118 struct die_info
*comp_unit_die
;
8121 if (dwarf_die_debug
)
8122 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
8123 this_cu
->is_debug_types
? "type" : "comp",
8124 sect_offset_str (this_cu
->sect_off
));
8126 gdb_assert (this_cu
->cu
== NULL
);
8128 abbrev_section
= (dwo_file
!= NULL
8129 ? &dwo_file
->sections
.abbrev
8130 : get_abbrev_section_for_cu (this_cu
));
8132 /* This is cheap if the section is already read in. */
8133 dwarf2_read_section (objfile
, section
);
8135 struct dwarf2_cu
cu (this_cu
);
8137 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
8138 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
8139 &cu
.header
, section
,
8140 abbrev_section
, info_ptr
,
8141 (this_cu
->is_debug_types
8143 : rcuh_kind::COMPILE
));
8145 this_cu
->length
= get_cu_length (&cu
.header
);
8147 /* Skip dummy compilation units. */
8148 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
8149 || peek_abbrev_code (abfd
, info_ptr
) == 0)
8152 abbrev_table_up abbrev_table
8153 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
8154 cu
.header
.abbrev_sect_off
);
8156 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
8157 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8159 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8162 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
8163 does not lookup the specified DWO file.
8164 This cannot be used to read DWO files.
8166 THIS_CU->cu is always freed when done.
8167 This is done in order to not leave THIS_CU->cu in a state where we have
8168 to care whether it refers to the "main" CU or the DWO CU.
8169 We can revisit this if the data shows there's a performance issue. */
8172 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
8173 die_reader_func_ftype
*die_reader_func
,
8176 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
8179 /* Type Unit Groups.
8181 Type Unit Groups are a way to collapse the set of all TUs (type units) into
8182 a more manageable set. The grouping is done by DW_AT_stmt_list entry
8183 so that all types coming from the same compilation (.o file) are grouped
8184 together. A future step could be to put the types in the same symtab as
8185 the CU the types ultimately came from. */
8188 hash_type_unit_group (const void *item
)
8190 const struct type_unit_group
*tu_group
8191 = (const struct type_unit_group
*) item
;
8193 return hash_stmt_list_entry (&tu_group
->hash
);
8197 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
8199 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
8200 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
8202 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
8205 /* Allocate a hash table for type unit groups. */
8208 allocate_type_unit_groups_table (struct objfile
*objfile
)
8210 return htab_create_alloc_ex (3,
8211 hash_type_unit_group
,
8214 &objfile
->objfile_obstack
,
8215 hashtab_obstack_allocate
,
8216 dummy_obstack_deallocate
);
8219 /* Type units that don't have DW_AT_stmt_list are grouped into their own
8220 partial symtabs. We combine several TUs per psymtab to not let the size
8221 of any one psymtab grow too big. */
8222 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
8223 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
8225 /* Helper routine for get_type_unit_group.
8226 Create the type_unit_group object used to hold one or more TUs. */
8228 static struct type_unit_group
*
8229 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
8231 struct dwarf2_per_objfile
*dwarf2_per_objfile
8232 = cu
->per_cu
->dwarf2_per_objfile
;
8233 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8234 struct dwarf2_per_cu_data
*per_cu
;
8235 struct type_unit_group
*tu_group
;
8237 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8238 struct type_unit_group
);
8239 per_cu
= &tu_group
->per_cu
;
8240 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8242 if (dwarf2_per_objfile
->using_index
)
8244 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8245 struct dwarf2_per_cu_quick_data
);
8249 unsigned int line_offset
= to_underlying (line_offset_struct
);
8250 struct partial_symtab
*pst
;
8253 /* Give the symtab a useful name for debug purposes. */
8254 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
8255 name
= xstrprintf ("<type_units_%d>",
8256 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
8258 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
8260 pst
= create_partial_symtab (per_cu
, name
);
8266 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
8267 tu_group
->hash
.line_sect_off
= line_offset_struct
;
8272 /* Look up the type_unit_group for type unit CU, and create it if necessary.
8273 STMT_LIST is a DW_AT_stmt_list attribute. */
8275 static struct type_unit_group
*
8276 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
8278 struct dwarf2_per_objfile
*dwarf2_per_objfile
8279 = cu
->per_cu
->dwarf2_per_objfile
;
8280 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8281 struct type_unit_group
*tu_group
;
8283 unsigned int line_offset
;
8284 struct type_unit_group type_unit_group_for_lookup
;
8286 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
8288 dwarf2_per_objfile
->type_unit_groups
=
8289 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
8292 /* Do we need to create a new group, or can we use an existing one? */
8296 line_offset
= DW_UNSND (stmt_list
);
8297 ++tu_stats
->nr_symtab_sharers
;
8301 /* Ugh, no stmt_list. Rare, but we have to handle it.
8302 We can do various things here like create one group per TU or
8303 spread them over multiple groups to split up the expansion work.
8304 To avoid worst case scenarios (too many groups or too large groups)
8305 we, umm, group them in bunches. */
8306 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
8307 | (tu_stats
->nr_stmt_less_type_units
8308 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
8309 ++tu_stats
->nr_stmt_less_type_units
;
8312 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
8313 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
8314 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
8315 &type_unit_group_for_lookup
, INSERT
);
8318 tu_group
= (struct type_unit_group
*) *slot
;
8319 gdb_assert (tu_group
!= NULL
);
8323 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8324 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8326 ++tu_stats
->nr_symtabs
;
8332 /* Partial symbol tables. */
8334 /* Create a psymtab named NAME and assign it to PER_CU.
8336 The caller must fill in the following details:
8337 dirname, textlow, texthigh. */
8339 static struct partial_symtab
*
8340 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8342 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8343 struct partial_symtab
*pst
;
8345 pst
= start_psymtab_common (objfile
, name
, 0,
8346 objfile
->global_psymbols
,
8347 objfile
->static_psymbols
);
8349 pst
->psymtabs_addrmap_supported
= 1;
8351 /* This is the glue that links PST into GDB's symbol API. */
8352 pst
->read_symtab_private
= per_cu
;
8353 pst
->read_symtab
= dwarf2_read_symtab
;
8354 per_cu
->v
.psymtab
= pst
;
8359 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8362 struct process_psymtab_comp_unit_data
8364 /* True if we are reading a DW_TAG_partial_unit. */
8366 int want_partial_unit
;
8368 /* The "pretend" language that is used if the CU doesn't declare a
8371 enum language pretend_language
;
8374 /* die_reader_func for process_psymtab_comp_unit. */
8377 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8378 const gdb_byte
*info_ptr
,
8379 struct die_info
*comp_unit_die
,
8383 struct dwarf2_cu
*cu
= reader
->cu
;
8384 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8385 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8386 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8388 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8389 struct partial_symtab
*pst
;
8390 enum pc_bounds_kind cu_bounds_kind
;
8391 const char *filename
;
8392 struct process_psymtab_comp_unit_data
*info
8393 = (struct process_psymtab_comp_unit_data
*) data
;
8395 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8398 gdb_assert (! per_cu
->is_debug_types
);
8400 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8402 cu
->list_in_scope
= &file_symbols
;
8404 /* Allocate a new partial symbol table structure. */
8405 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8406 if (filename
== NULL
)
8409 pst
= create_partial_symtab (per_cu
, filename
);
8411 /* This must be done before calling dwarf2_build_include_psymtabs. */
8412 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8414 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8416 dwarf2_find_base_address (comp_unit_die
, cu
);
8418 /* Possibly set the default values of LOWPC and HIGHPC from
8420 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8421 &best_highpc
, cu
, pst
);
8422 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8423 /* Store the contiguous range if it is not empty; it can be empty for
8424 CUs with no code. */
8425 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8426 gdbarch_adjust_dwarf2_addr (gdbarch
,
8427 best_lowpc
+ baseaddr
),
8428 gdbarch_adjust_dwarf2_addr (gdbarch
,
8429 best_highpc
+ baseaddr
) - 1,
8432 /* Check if comp unit has_children.
8433 If so, read the rest of the partial symbols from this comp unit.
8434 If not, there's no more debug_info for this comp unit. */
8437 struct partial_die_info
*first_die
;
8438 CORE_ADDR lowpc
, highpc
;
8440 lowpc
= ((CORE_ADDR
) -1);
8441 highpc
= ((CORE_ADDR
) 0);
8443 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8445 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8446 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8448 /* If we didn't find a lowpc, set it to highpc to avoid
8449 complaints from `maint check'. */
8450 if (lowpc
== ((CORE_ADDR
) -1))
8453 /* If the compilation unit didn't have an explicit address range,
8454 then use the information extracted from its child dies. */
8455 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8458 best_highpc
= highpc
;
8461 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8462 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8464 end_psymtab_common (objfile
, pst
);
8466 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8469 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8470 struct dwarf2_per_cu_data
*iter
;
8472 /* Fill in 'dependencies' here; we fill in 'users' in a
8474 pst
->number_of_dependencies
= len
;
8476 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8478 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8481 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8483 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8486 /* Get the list of files included in the current compilation unit,
8487 and build a psymtab for each of them. */
8488 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8490 if (dwarf_read_debug
)
8492 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8494 fprintf_unfiltered (gdb_stdlog
,
8495 "Psymtab for %s unit @%s: %s - %s"
8496 ", %d global, %d static syms\n",
8497 per_cu
->is_debug_types
? "type" : "comp",
8498 sect_offset_str (per_cu
->sect_off
),
8499 paddress (gdbarch
, pst
->textlow
),
8500 paddress (gdbarch
, pst
->texthigh
),
8501 pst
->n_global_syms
, pst
->n_static_syms
);
8505 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8506 Process compilation unit THIS_CU for a psymtab. */
8509 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8510 int want_partial_unit
,
8511 enum language pretend_language
)
8513 /* If this compilation unit was already read in, free the
8514 cached copy in order to read it in again. This is
8515 necessary because we skipped some symbols when we first
8516 read in the compilation unit (see load_partial_dies).
8517 This problem could be avoided, but the benefit is unclear. */
8518 if (this_cu
->cu
!= NULL
)
8519 free_one_cached_comp_unit (this_cu
);
8521 if (this_cu
->is_debug_types
)
8522 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8526 process_psymtab_comp_unit_data info
;
8527 info
.want_partial_unit
= want_partial_unit
;
8528 info
.pretend_language
= pretend_language
;
8529 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8530 process_psymtab_comp_unit_reader
, &info
);
8533 /* Age out any secondary CUs. */
8534 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8537 /* Reader function for build_type_psymtabs. */
8540 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8541 const gdb_byte
*info_ptr
,
8542 struct die_info
*type_unit_die
,
8546 struct dwarf2_per_objfile
*dwarf2_per_objfile
8547 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8549 struct dwarf2_cu
*cu
= reader
->cu
;
8550 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8551 struct signatured_type
*sig_type
;
8552 struct type_unit_group
*tu_group
;
8553 struct attribute
*attr
;
8554 struct partial_die_info
*first_die
;
8555 CORE_ADDR lowpc
, highpc
;
8556 struct partial_symtab
*pst
;
8558 gdb_assert (data
== NULL
);
8559 gdb_assert (per_cu
->is_debug_types
);
8560 sig_type
= (struct signatured_type
*) per_cu
;
8565 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8566 tu_group
= get_type_unit_group (cu
, attr
);
8568 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8570 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8571 cu
->list_in_scope
= &file_symbols
;
8572 pst
= create_partial_symtab (per_cu
, "");
8575 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8577 lowpc
= (CORE_ADDR
) -1;
8578 highpc
= (CORE_ADDR
) 0;
8579 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8581 end_psymtab_common (objfile
, pst
);
8584 /* Struct used to sort TUs by their abbreviation table offset. */
8586 struct tu_abbrev_offset
8588 struct signatured_type
*sig_type
;
8589 sect_offset abbrev_offset
;
8592 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8595 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8596 const struct tu_abbrev_offset
&b
)
8598 return a
.abbrev_offset
< b
.abbrev_offset
;
8601 /* Efficiently read all the type units.
8602 This does the bulk of the work for build_type_psymtabs.
8604 The efficiency is because we sort TUs by the abbrev table they use and
8605 only read each abbrev table once. In one program there are 200K TUs
8606 sharing 8K abbrev tables.
8608 The main purpose of this function is to support building the
8609 dwarf2_per_objfile->type_unit_groups table.
8610 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8611 can collapse the search space by grouping them by stmt_list.
8612 The savings can be significant, in the same program from above the 200K TUs
8613 share 8K stmt_list tables.
8615 FUNC is expected to call get_type_unit_group, which will create the
8616 struct type_unit_group if necessary and add it to
8617 dwarf2_per_objfile->type_unit_groups. */
8620 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8622 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8623 abbrev_table_up abbrev_table
;
8624 sect_offset abbrev_offset
;
8627 /* It's up to the caller to not call us multiple times. */
8628 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8630 if (dwarf2_per_objfile
->n_type_units
== 0)
8633 /* TUs typically share abbrev tables, and there can be way more TUs than
8634 abbrev tables. Sort by abbrev table to reduce the number of times we
8635 read each abbrev table in.
8636 Alternatives are to punt or to maintain a cache of abbrev tables.
8637 This is simpler and efficient enough for now.
8639 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8640 symtab to use). Typically TUs with the same abbrev offset have the same
8641 stmt_list value too so in practice this should work well.
8643 The basic algorithm here is:
8645 sort TUs by abbrev table
8646 for each TU with same abbrev table:
8647 read abbrev table if first user
8648 read TU top level DIE
8649 [IWBN if DWO skeletons had DW_AT_stmt_list]
8652 if (dwarf_read_debug
)
8653 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8655 /* Sort in a separate table to maintain the order of all_type_units
8656 for .gdb_index: TU indices directly index all_type_units. */
8657 std::vector
<struct tu_abbrev_offset
> sorted_by_abbrev
8658 (dwarf2_per_objfile
->n_type_units
);
8659 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8661 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8663 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8664 sorted_by_abbrev
[i
].abbrev_offset
=
8665 read_abbrev_offset (dwarf2_per_objfile
,
8666 sig_type
->per_cu
.section
,
8667 sig_type
->per_cu
.sect_off
);
8669 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8670 sort_tu_by_abbrev_offset
);
8672 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8674 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8676 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8678 /* Switch to the next abbrev table if necessary. */
8679 if (abbrev_table
== NULL
8680 || tu
->abbrev_offset
!= abbrev_offset
)
8682 abbrev_offset
= tu
->abbrev_offset
;
8684 abbrev_table_read_table (dwarf2_per_objfile
,
8685 &dwarf2_per_objfile
->abbrev
,
8687 ++tu_stats
->nr_uniq_abbrev_tables
;
8690 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
.get (),
8691 0, 0, build_type_psymtabs_reader
, NULL
);
8695 /* Print collected type unit statistics. */
8698 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8700 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8702 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8703 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8704 dwarf2_per_objfile
->n_type_units
);
8705 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8706 tu_stats
->nr_uniq_abbrev_tables
);
8707 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8708 tu_stats
->nr_symtabs
);
8709 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8710 tu_stats
->nr_symtab_sharers
);
8711 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8712 tu_stats
->nr_stmt_less_type_units
);
8713 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8714 tu_stats
->nr_all_type_units_reallocs
);
8717 /* Traversal function for build_type_psymtabs. */
8720 build_type_psymtab_dependencies (void **slot
, void *info
)
8722 struct dwarf2_per_objfile
*dwarf2_per_objfile
8723 = (struct dwarf2_per_objfile
*) info
;
8724 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8725 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8726 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8727 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8728 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8729 struct signatured_type
*iter
;
8732 gdb_assert (len
> 0);
8733 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8735 pst
->number_of_dependencies
= len
;
8737 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8739 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8742 gdb_assert (iter
->per_cu
.is_debug_types
);
8743 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8744 iter
->type_unit_group
= tu_group
;
8747 VEC_free (sig_type_ptr
, tu_group
->tus
);
8752 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8753 Build partial symbol tables for the .debug_types comp-units. */
8756 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8758 if (! create_all_type_units (dwarf2_per_objfile
))
8761 build_type_psymtabs_1 (dwarf2_per_objfile
);
8764 /* Traversal function for process_skeletonless_type_unit.
8765 Read a TU in a DWO file and build partial symbols for it. */
8768 process_skeletonless_type_unit (void **slot
, void *info
)
8770 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8771 struct dwarf2_per_objfile
*dwarf2_per_objfile
8772 = (struct dwarf2_per_objfile
*) info
;
8773 struct signatured_type find_entry
, *entry
;
8775 /* If this TU doesn't exist in the global table, add it and read it in. */
8777 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8779 dwarf2_per_objfile
->signatured_types
8780 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8783 find_entry
.signature
= dwo_unit
->signature
;
8784 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8786 /* If we've already seen this type there's nothing to do. What's happening
8787 is we're doing our own version of comdat-folding here. */
8791 /* This does the job that create_all_type_units would have done for
8793 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8794 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8797 /* This does the job that build_type_psymtabs_1 would have done. */
8798 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8799 build_type_psymtabs_reader
, NULL
);
8804 /* Traversal function for process_skeletonless_type_units. */
8807 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8809 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8811 if (dwo_file
->tus
!= NULL
)
8813 htab_traverse_noresize (dwo_file
->tus
,
8814 process_skeletonless_type_unit
, info
);
8820 /* Scan all TUs of DWO files, verifying we've processed them.
8821 This is needed in case a TU was emitted without its skeleton.
8822 Note: This can't be done until we know what all the DWO files are. */
8825 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8827 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8828 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8829 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8831 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8832 process_dwo_file_for_skeletonless_type_units
,
8833 dwarf2_per_objfile
);
8837 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8840 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8844 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8846 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8847 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8853 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8855 /* Set the 'user' field only if it is not already set. */
8856 if (pst
->dependencies
[j
]->user
== NULL
)
8857 pst
->dependencies
[j
]->user
= pst
;
8862 /* Build the partial symbol table by doing a quick pass through the
8863 .debug_info and .debug_abbrev sections. */
8866 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8868 struct cleanup
*back_to
;
8870 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8872 if (dwarf_read_debug
)
8874 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8875 objfile_name (objfile
));
8878 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8880 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8882 /* Any cached compilation units will be linked by the per-objfile
8883 read_in_chain. Make sure to free them when we're done. */
8884 back_to
= make_cleanup (free_cached_comp_units
, dwarf2_per_objfile
);
8886 build_type_psymtabs (dwarf2_per_objfile
);
8888 create_all_comp_units (dwarf2_per_objfile
);
8890 /* Create a temporary address map on a temporary obstack. We later
8891 copy this to the final obstack. */
8892 auto_obstack temp_obstack
;
8894 scoped_restore save_psymtabs_addrmap
8895 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8896 addrmap_create_mutable (&temp_obstack
));
8898 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8900 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8902 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8905 /* This has to wait until we read the CUs, we need the list of DWOs. */
8906 process_skeletonless_type_units (dwarf2_per_objfile
);
8908 /* Now that all TUs have been processed we can fill in the dependencies. */
8909 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8911 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8912 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8915 if (dwarf_read_debug
)
8916 print_tu_stats (dwarf2_per_objfile
);
8918 set_partial_user (dwarf2_per_objfile
);
8920 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8921 &objfile
->objfile_obstack
);
8922 /* At this point we want to keep the address map. */
8923 save_psymtabs_addrmap
.release ();
8925 do_cleanups (back_to
);
8927 if (dwarf_read_debug
)
8928 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8929 objfile_name (objfile
));
8932 /* die_reader_func for load_partial_comp_unit. */
8935 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8936 const gdb_byte
*info_ptr
,
8937 struct die_info
*comp_unit_die
,
8941 struct dwarf2_cu
*cu
= reader
->cu
;
8943 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8945 /* Check if comp unit has_children.
8946 If so, read the rest of the partial symbols from this comp unit.
8947 If not, there's no more debug_info for this comp unit. */
8949 load_partial_dies (reader
, info_ptr
, 0);
8952 /* Load the partial DIEs for a secondary CU into memory.
8953 This is also used when rereading a primary CU with load_all_dies. */
8956 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8958 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8959 load_partial_comp_unit_reader
, NULL
);
8963 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8964 struct dwarf2_section_info
*section
,
8965 struct dwarf2_section_info
*abbrev_section
,
8966 unsigned int is_dwz
,
8969 struct dwarf2_per_cu_data
***all_comp_units
)
8971 const gdb_byte
*info_ptr
;
8972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8974 if (dwarf_read_debug
)
8975 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8976 get_section_name (section
),
8977 get_section_file_name (section
));
8979 dwarf2_read_section (objfile
, section
);
8981 info_ptr
= section
->buffer
;
8983 while (info_ptr
< section
->buffer
+ section
->size
)
8985 struct dwarf2_per_cu_data
*this_cu
;
8987 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8989 comp_unit_head cu_header
;
8990 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8991 abbrev_section
, info_ptr
,
8992 rcuh_kind::COMPILE
);
8994 /* Save the compilation unit for later lookup. */
8995 if (cu_header
.unit_type
!= DW_UT_type
)
8997 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8998 struct dwarf2_per_cu_data
);
8999 memset (this_cu
, 0, sizeof (*this_cu
));
9003 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
9004 struct signatured_type
);
9005 memset (sig_type
, 0, sizeof (*sig_type
));
9006 sig_type
->signature
= cu_header
.signature
;
9007 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
9008 this_cu
= &sig_type
->per_cu
;
9010 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
9011 this_cu
->sect_off
= sect_off
;
9012 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
9013 this_cu
->is_dwz
= is_dwz
;
9014 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
9015 this_cu
->section
= section
;
9017 if (*n_comp_units
== *n_allocated
)
9020 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
9021 *all_comp_units
, *n_allocated
);
9023 (*all_comp_units
)[*n_comp_units
] = this_cu
;
9026 info_ptr
= info_ptr
+ this_cu
->length
;
9030 /* Create a list of all compilation units in OBJFILE.
9031 This is only done for -readnow and building partial symtabs. */
9034 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9038 struct dwarf2_per_cu_data
**all_comp_units
;
9039 struct dwz_file
*dwz
;
9040 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9044 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
9046 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
9047 &dwarf2_per_objfile
->abbrev
, 0,
9048 &n_allocated
, &n_comp_units
, &all_comp_units
);
9050 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
9052 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
9053 1, &n_allocated
, &n_comp_units
,
9056 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
9057 struct dwarf2_per_cu_data
*,
9059 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
9060 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
9061 xfree (all_comp_units
);
9062 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
9065 /* Process all loaded DIEs for compilation unit CU, starting at
9066 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
9067 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
9068 DW_AT_ranges). See the comments of add_partial_subprogram on how
9069 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
9072 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
9073 CORE_ADDR
*highpc
, int set_addrmap
,
9074 struct dwarf2_cu
*cu
)
9076 struct partial_die_info
*pdi
;
9078 /* Now, march along the PDI's, descending into ones which have
9079 interesting children but skipping the children of the other ones,
9080 until we reach the end of the compilation unit. */
9088 /* Anonymous namespaces or modules have no name but have interesting
9089 children, so we need to look at them. Ditto for anonymous
9092 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
9093 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
9094 || pdi
->tag
== DW_TAG_imported_unit
9095 || pdi
->tag
== DW_TAG_inlined_subroutine
)
9099 case DW_TAG_subprogram
:
9100 case DW_TAG_inlined_subroutine
:
9101 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9103 case DW_TAG_constant
:
9104 case DW_TAG_variable
:
9105 case DW_TAG_typedef
:
9106 case DW_TAG_union_type
:
9107 if (!pdi
->is_declaration
)
9109 add_partial_symbol (pdi
, cu
);
9112 case DW_TAG_class_type
:
9113 case DW_TAG_interface_type
:
9114 case DW_TAG_structure_type
:
9115 if (!pdi
->is_declaration
)
9117 add_partial_symbol (pdi
, cu
);
9119 if ((cu
->language
== language_rust
9120 || cu
->language
== language_cplus
) && pdi
->has_children
)
9121 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
9124 case DW_TAG_enumeration_type
:
9125 if (!pdi
->is_declaration
)
9126 add_partial_enumeration (pdi
, cu
);
9128 case DW_TAG_base_type
:
9129 case DW_TAG_subrange_type
:
9130 /* File scope base type definitions are added to the partial
9132 add_partial_symbol (pdi
, cu
);
9134 case DW_TAG_namespace
:
9135 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9138 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9140 case DW_TAG_imported_unit
:
9142 struct dwarf2_per_cu_data
*per_cu
;
9144 /* For now we don't handle imported units in type units. */
9145 if (cu
->per_cu
->is_debug_types
)
9147 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9148 " supported in type units [in module %s]"),
9149 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9152 per_cu
= dwarf2_find_containing_comp_unit
9153 (pdi
->d
.sect_off
, pdi
->is_dwz
,
9154 cu
->per_cu
->dwarf2_per_objfile
);
9156 /* Go read the partial unit, if needed. */
9157 if (per_cu
->v
.psymtab
== NULL
)
9158 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
9160 VEC_safe_push (dwarf2_per_cu_ptr
,
9161 cu
->per_cu
->imported_symtabs
, per_cu
);
9164 case DW_TAG_imported_declaration
:
9165 add_partial_symbol (pdi
, cu
);
9172 /* If the die has a sibling, skip to the sibling. */
9174 pdi
= pdi
->die_sibling
;
9178 /* Functions used to compute the fully scoped name of a partial DIE.
9180 Normally, this is simple. For C++, the parent DIE's fully scoped
9181 name is concatenated with "::" and the partial DIE's name.
9182 Enumerators are an exception; they use the scope of their parent
9183 enumeration type, i.e. the name of the enumeration type is not
9184 prepended to the enumerator.
9186 There are two complexities. One is DW_AT_specification; in this
9187 case "parent" means the parent of the target of the specification,
9188 instead of the direct parent of the DIE. The other is compilers
9189 which do not emit DW_TAG_namespace; in this case we try to guess
9190 the fully qualified name of structure types from their members'
9191 linkage names. This must be done using the DIE's children rather
9192 than the children of any DW_AT_specification target. We only need
9193 to do this for structures at the top level, i.e. if the target of
9194 any DW_AT_specification (if any; otherwise the DIE itself) does not
9197 /* Compute the scope prefix associated with PDI's parent, in
9198 compilation unit CU. The result will be allocated on CU's
9199 comp_unit_obstack, or a copy of the already allocated PDI->NAME
9200 field. NULL is returned if no prefix is necessary. */
9202 partial_die_parent_scope (struct partial_die_info
*pdi
,
9203 struct dwarf2_cu
*cu
)
9205 const char *grandparent_scope
;
9206 struct partial_die_info
*parent
, *real_pdi
;
9208 /* We need to look at our parent DIE; if we have a DW_AT_specification,
9209 then this means the parent of the specification DIE. */
9212 while (real_pdi
->has_specification
)
9213 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
9214 real_pdi
->spec_is_dwz
, cu
);
9216 parent
= real_pdi
->die_parent
;
9220 if (parent
->scope_set
)
9221 return parent
->scope
;
9225 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
9227 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9228 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9229 Work around this problem here. */
9230 if (cu
->language
== language_cplus
9231 && parent
->tag
== DW_TAG_namespace
9232 && strcmp (parent
->name
, "::") == 0
9233 && grandparent_scope
== NULL
)
9235 parent
->scope
= NULL
;
9236 parent
->scope_set
= 1;
9240 if (pdi
->tag
== DW_TAG_enumerator
)
9241 /* Enumerators should not get the name of the enumeration as a prefix. */
9242 parent
->scope
= grandparent_scope
;
9243 else if (parent
->tag
== DW_TAG_namespace
9244 || parent
->tag
== DW_TAG_module
9245 || parent
->tag
== DW_TAG_structure_type
9246 || parent
->tag
== DW_TAG_class_type
9247 || parent
->tag
== DW_TAG_interface_type
9248 || parent
->tag
== DW_TAG_union_type
9249 || parent
->tag
== DW_TAG_enumeration_type
)
9251 if (grandparent_scope
== NULL
)
9252 parent
->scope
= parent
->name
;
9254 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
9256 parent
->name
, 0, cu
);
9260 /* FIXME drow/2004-04-01: What should we be doing with
9261 function-local names? For partial symbols, we should probably be
9263 complaint (&symfile_complaints
,
9264 _("unhandled containing DIE tag %d for DIE at %s"),
9265 parent
->tag
, sect_offset_str (pdi
->sect_off
));
9266 parent
->scope
= grandparent_scope
;
9269 parent
->scope_set
= 1;
9270 return parent
->scope
;
9273 /* Return the fully scoped name associated with PDI, from compilation unit
9274 CU. The result will be allocated with malloc. */
9277 partial_die_full_name (struct partial_die_info
*pdi
,
9278 struct dwarf2_cu
*cu
)
9280 const char *parent_scope
;
9282 /* If this is a template instantiation, we can not work out the
9283 template arguments from partial DIEs. So, unfortunately, we have
9284 to go through the full DIEs. At least any work we do building
9285 types here will be reused if full symbols are loaded later. */
9286 if (pdi
->has_template_arguments
)
9290 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
9292 struct die_info
*die
;
9293 struct attribute attr
;
9294 struct dwarf2_cu
*ref_cu
= cu
;
9296 /* DW_FORM_ref_addr is using section offset. */
9297 attr
.name
= (enum dwarf_attribute
) 0;
9298 attr
.form
= DW_FORM_ref_addr
;
9299 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
9300 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
9302 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
9306 parent_scope
= partial_die_parent_scope (pdi
, cu
);
9307 if (parent_scope
== NULL
)
9310 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
9314 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
9316 struct dwarf2_per_objfile
*dwarf2_per_objfile
9317 = cu
->per_cu
->dwarf2_per_objfile
;
9318 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9319 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9321 const char *actual_name
= NULL
;
9323 char *built_actual_name
;
9325 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9327 built_actual_name
= partial_die_full_name (pdi
, cu
);
9328 if (built_actual_name
!= NULL
)
9329 actual_name
= built_actual_name
;
9331 if (actual_name
== NULL
)
9332 actual_name
= pdi
->name
;
9336 case DW_TAG_inlined_subroutine
:
9337 case DW_TAG_subprogram
:
9338 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
9339 if (pdi
->is_external
|| cu
->language
== language_ada
)
9341 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
9342 of the global scope. But in Ada, we want to be able to access
9343 nested procedures globally. So all Ada subprograms are stored
9344 in the global scope. */
9345 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9346 built_actual_name
!= NULL
,
9347 VAR_DOMAIN
, LOC_BLOCK
,
9348 &objfile
->global_psymbols
,
9349 addr
, cu
->language
, objfile
);
9353 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9354 built_actual_name
!= NULL
,
9355 VAR_DOMAIN
, LOC_BLOCK
,
9356 &objfile
->static_psymbols
,
9357 addr
, cu
->language
, objfile
);
9360 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9361 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9363 case DW_TAG_constant
:
9365 std::vector
<partial_symbol
*> *list
;
9367 if (pdi
->is_external
)
9368 list
= &objfile
->global_psymbols
;
9370 list
= &objfile
->static_psymbols
;
9371 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9372 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9373 list
, 0, cu
->language
, objfile
);
9376 case DW_TAG_variable
:
9378 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9382 && !dwarf2_per_objfile
->has_section_at_zero
)
9384 /* A global or static variable may also have been stripped
9385 out by the linker if unused, in which case its address
9386 will be nullified; do not add such variables into partial
9387 symbol table then. */
9389 else if (pdi
->is_external
)
9392 Don't enter into the minimal symbol tables as there is
9393 a minimal symbol table entry from the ELF symbols already.
9394 Enter into partial symbol table if it has a location
9395 descriptor or a type.
9396 If the location descriptor is missing, new_symbol will create
9397 a LOC_UNRESOLVED symbol, the address of the variable will then
9398 be determined from the minimal symbol table whenever the variable
9400 The address for the partial symbol table entry is not
9401 used by GDB, but it comes in handy for debugging partial symbol
9404 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9405 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9406 built_actual_name
!= NULL
,
9407 VAR_DOMAIN
, LOC_STATIC
,
9408 &objfile
->global_psymbols
,
9410 cu
->language
, objfile
);
9414 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9416 /* Static Variable. Skip symbols whose value we cannot know (those
9417 without location descriptors or constant values). */
9418 if (!has_loc
&& !pdi
->has_const_value
)
9420 xfree (built_actual_name
);
9424 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9425 built_actual_name
!= NULL
,
9426 VAR_DOMAIN
, LOC_STATIC
,
9427 &objfile
->static_psymbols
,
9428 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
9429 cu
->language
, objfile
);
9432 case DW_TAG_typedef
:
9433 case DW_TAG_base_type
:
9434 case DW_TAG_subrange_type
:
9435 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9436 built_actual_name
!= NULL
,
9437 VAR_DOMAIN
, LOC_TYPEDEF
,
9438 &objfile
->static_psymbols
,
9439 0, cu
->language
, objfile
);
9441 case DW_TAG_imported_declaration
:
9442 case DW_TAG_namespace
:
9443 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9444 built_actual_name
!= NULL
,
9445 VAR_DOMAIN
, LOC_TYPEDEF
,
9446 &objfile
->global_psymbols
,
9447 0, cu
->language
, objfile
);
9450 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9451 built_actual_name
!= NULL
,
9452 MODULE_DOMAIN
, LOC_TYPEDEF
,
9453 &objfile
->global_psymbols
,
9454 0, cu
->language
, objfile
);
9456 case DW_TAG_class_type
:
9457 case DW_TAG_interface_type
:
9458 case DW_TAG_structure_type
:
9459 case DW_TAG_union_type
:
9460 case DW_TAG_enumeration_type
:
9461 /* Skip external references. The DWARF standard says in the section
9462 about "Structure, Union, and Class Type Entries": "An incomplete
9463 structure, union or class type is represented by a structure,
9464 union or class entry that does not have a byte size attribute
9465 and that has a DW_AT_declaration attribute." */
9466 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9468 xfree (built_actual_name
);
9472 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9473 static vs. global. */
9474 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9475 built_actual_name
!= NULL
,
9476 STRUCT_DOMAIN
, LOC_TYPEDEF
,
9477 cu
->language
== language_cplus
9478 ? &objfile
->global_psymbols
9479 : &objfile
->static_psymbols
,
9480 0, cu
->language
, objfile
);
9483 case DW_TAG_enumerator
:
9484 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9485 built_actual_name
!= NULL
,
9486 VAR_DOMAIN
, LOC_CONST
,
9487 cu
->language
== language_cplus
9488 ? &objfile
->global_psymbols
9489 : &objfile
->static_psymbols
,
9490 0, cu
->language
, objfile
);
9496 xfree (built_actual_name
);
9499 /* Read a partial die corresponding to a namespace; also, add a symbol
9500 corresponding to that namespace to the symbol table. NAMESPACE is
9501 the name of the enclosing namespace. */
9504 add_partial_namespace (struct partial_die_info
*pdi
,
9505 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9506 int set_addrmap
, struct dwarf2_cu
*cu
)
9508 /* Add a symbol for the namespace. */
9510 add_partial_symbol (pdi
, cu
);
9512 /* Now scan partial symbols in that namespace. */
9514 if (pdi
->has_children
)
9515 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9518 /* Read a partial die corresponding to a Fortran module. */
9521 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9522 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9524 /* Add a symbol for the namespace. */
9526 add_partial_symbol (pdi
, cu
);
9528 /* Now scan partial symbols in that module. */
9530 if (pdi
->has_children
)
9531 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9534 /* Read a partial die corresponding to a subprogram or an inlined
9535 subprogram and create a partial symbol for that subprogram.
9536 When the CU language allows it, this routine also defines a partial
9537 symbol for each nested subprogram that this subprogram contains.
9538 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9539 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9541 PDI may also be a lexical block, in which case we simply search
9542 recursively for subprograms defined inside that lexical block.
9543 Again, this is only performed when the CU language allows this
9544 type of definitions. */
9547 add_partial_subprogram (struct partial_die_info
*pdi
,
9548 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9549 int set_addrmap
, struct dwarf2_cu
*cu
)
9551 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9553 if (pdi
->has_pc_info
)
9555 if (pdi
->lowpc
< *lowpc
)
9556 *lowpc
= pdi
->lowpc
;
9557 if (pdi
->highpc
> *highpc
)
9558 *highpc
= pdi
->highpc
;
9561 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9562 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9567 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9568 SECT_OFF_TEXT (objfile
));
9569 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9570 pdi
->lowpc
+ baseaddr
);
9571 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9572 pdi
->highpc
+ baseaddr
);
9573 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9574 cu
->per_cu
->v
.psymtab
);
9578 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9580 if (!pdi
->is_declaration
)
9581 /* Ignore subprogram DIEs that do not have a name, they are
9582 illegal. Do not emit a complaint at this point, we will
9583 do so when we convert this psymtab into a symtab. */
9585 add_partial_symbol (pdi
, cu
);
9589 if (! pdi
->has_children
)
9592 if (cu
->language
== language_ada
)
9594 pdi
= pdi
->die_child
;
9598 if (pdi
->tag
== DW_TAG_subprogram
9599 || pdi
->tag
== DW_TAG_inlined_subroutine
9600 || pdi
->tag
== DW_TAG_lexical_block
)
9601 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9602 pdi
= pdi
->die_sibling
;
9607 /* Read a partial die corresponding to an enumeration type. */
9610 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9611 struct dwarf2_cu
*cu
)
9613 struct partial_die_info
*pdi
;
9615 if (enum_pdi
->name
!= NULL
)
9616 add_partial_symbol (enum_pdi
, cu
);
9618 pdi
= enum_pdi
->die_child
;
9621 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9622 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9624 add_partial_symbol (pdi
, cu
);
9625 pdi
= pdi
->die_sibling
;
9629 /* Return the initial uleb128 in the die at INFO_PTR. */
9632 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9634 unsigned int bytes_read
;
9636 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9639 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9640 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9642 Return the corresponding abbrev, or NULL if the number is zero (indicating
9643 an empty DIE). In either case *BYTES_READ will be set to the length of
9644 the initial number. */
9646 static struct abbrev_info
*
9647 peek_die_abbrev (const die_reader_specs
&reader
,
9648 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9650 dwarf2_cu
*cu
= reader
.cu
;
9651 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9652 unsigned int abbrev_number
9653 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9655 if (abbrev_number
== 0)
9658 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9661 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9662 " at offset %s [in module %s]"),
9663 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9664 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9670 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9671 Returns a pointer to the end of a series of DIEs, terminated by an empty
9672 DIE. Any children of the skipped DIEs will also be skipped. */
9674 static const gdb_byte
*
9675 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9679 unsigned int bytes_read
;
9680 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9683 return info_ptr
+ bytes_read
;
9685 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9689 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9690 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9691 abbrev corresponding to that skipped uleb128 should be passed in
9692 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9695 static const gdb_byte
*
9696 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9697 struct abbrev_info
*abbrev
)
9699 unsigned int bytes_read
;
9700 struct attribute attr
;
9701 bfd
*abfd
= reader
->abfd
;
9702 struct dwarf2_cu
*cu
= reader
->cu
;
9703 const gdb_byte
*buffer
= reader
->buffer
;
9704 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9705 unsigned int form
, i
;
9707 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9709 /* The only abbrev we care about is DW_AT_sibling. */
9710 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9712 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9713 if (attr
.form
== DW_FORM_ref_addr
)
9714 complaint (&symfile_complaints
,
9715 _("ignoring absolute DW_AT_sibling"));
9718 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9719 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9721 if (sibling_ptr
< info_ptr
)
9722 complaint (&symfile_complaints
,
9723 _("DW_AT_sibling points backwards"));
9724 else if (sibling_ptr
> reader
->buffer_end
)
9725 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9731 /* If it isn't DW_AT_sibling, skip this attribute. */
9732 form
= abbrev
->attrs
[i
].form
;
9736 case DW_FORM_ref_addr
:
9737 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9738 and later it is offset sized. */
9739 if (cu
->header
.version
== 2)
9740 info_ptr
+= cu
->header
.addr_size
;
9742 info_ptr
+= cu
->header
.offset_size
;
9744 case DW_FORM_GNU_ref_alt
:
9745 info_ptr
+= cu
->header
.offset_size
;
9748 info_ptr
+= cu
->header
.addr_size
;
9755 case DW_FORM_flag_present
:
9756 case DW_FORM_implicit_const
:
9768 case DW_FORM_ref_sig8
:
9771 case DW_FORM_data16
:
9774 case DW_FORM_string
:
9775 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9776 info_ptr
+= bytes_read
;
9778 case DW_FORM_sec_offset
:
9780 case DW_FORM_GNU_strp_alt
:
9781 info_ptr
+= cu
->header
.offset_size
;
9783 case DW_FORM_exprloc
:
9785 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9786 info_ptr
+= bytes_read
;
9788 case DW_FORM_block1
:
9789 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9791 case DW_FORM_block2
:
9792 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9794 case DW_FORM_block4
:
9795 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9799 case DW_FORM_ref_udata
:
9800 case DW_FORM_GNU_addr_index
:
9801 case DW_FORM_GNU_str_index
:
9802 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9804 case DW_FORM_indirect
:
9805 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9806 info_ptr
+= bytes_read
;
9807 /* We need to continue parsing from here, so just go back to
9809 goto skip_attribute
;
9812 error (_("Dwarf Error: Cannot handle %s "
9813 "in DWARF reader [in module %s]"),
9814 dwarf_form_name (form
),
9815 bfd_get_filename (abfd
));
9819 if (abbrev
->has_children
)
9820 return skip_children (reader
, info_ptr
);
9825 /* Locate ORIG_PDI's sibling.
9826 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9828 static const gdb_byte
*
9829 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9830 struct partial_die_info
*orig_pdi
,
9831 const gdb_byte
*info_ptr
)
9833 /* Do we know the sibling already? */
9835 if (orig_pdi
->sibling
)
9836 return orig_pdi
->sibling
;
9838 /* Are there any children to deal with? */
9840 if (!orig_pdi
->has_children
)
9843 /* Skip the children the long way. */
9845 return skip_children (reader
, info_ptr
);
9848 /* Expand this partial symbol table into a full symbol table. SELF is
9852 dwarf2_read_symtab (struct partial_symtab
*self
,
9853 struct objfile
*objfile
)
9855 struct dwarf2_per_objfile
*dwarf2_per_objfile
9856 = get_dwarf2_per_objfile (objfile
);
9860 warning (_("bug: psymtab for %s is already read in."),
9867 printf_filtered (_("Reading in symbols for %s..."),
9869 gdb_flush (gdb_stdout
);
9872 /* If this psymtab is constructed from a debug-only objfile, the
9873 has_section_at_zero flag will not necessarily be correct. We
9874 can get the correct value for this flag by looking at the data
9875 associated with the (presumably stripped) associated objfile. */
9876 if (objfile
->separate_debug_objfile_backlink
)
9878 struct dwarf2_per_objfile
*dpo_backlink
9879 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9881 dwarf2_per_objfile
->has_section_at_zero
9882 = dpo_backlink
->has_section_at_zero
;
9885 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9887 psymtab_to_symtab_1 (self
);
9889 /* Finish up the debug error message. */
9891 printf_filtered (_("done.\n"));
9894 process_cu_includes (dwarf2_per_objfile
);
9897 /* Reading in full CUs. */
9899 /* Add PER_CU to the queue. */
9902 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9903 enum language pretend_language
)
9905 struct dwarf2_queue_item
*item
;
9908 item
= XNEW (struct dwarf2_queue_item
);
9909 item
->per_cu
= per_cu
;
9910 item
->pretend_language
= pretend_language
;
9913 if (dwarf2_queue
== NULL
)
9914 dwarf2_queue
= item
;
9916 dwarf2_queue_tail
->next
= item
;
9918 dwarf2_queue_tail
= item
;
9921 /* If PER_CU is not yet queued, add it to the queue.
9922 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9924 The result is non-zero if PER_CU was queued, otherwise the result is zero
9925 meaning either PER_CU is already queued or it is already loaded.
9927 N.B. There is an invariant here that if a CU is queued then it is loaded.
9928 The caller is required to load PER_CU if we return non-zero. */
9931 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9932 struct dwarf2_per_cu_data
*per_cu
,
9933 enum language pretend_language
)
9935 /* We may arrive here during partial symbol reading, if we need full
9936 DIEs to process an unusual case (e.g. template arguments). Do
9937 not queue PER_CU, just tell our caller to load its DIEs. */
9938 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9940 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9945 /* Mark the dependence relation so that we don't flush PER_CU
9947 if (dependent_cu
!= NULL
)
9948 dwarf2_add_dependence (dependent_cu
, per_cu
);
9950 /* If it's already on the queue, we have nothing to do. */
9954 /* If the compilation unit is already loaded, just mark it as
9956 if (per_cu
->cu
!= NULL
)
9958 per_cu
->cu
->last_used
= 0;
9962 /* Add it to the queue. */
9963 queue_comp_unit (per_cu
, pretend_language
);
9968 /* Process the queue. */
9971 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9973 struct dwarf2_queue_item
*item
, *next_item
;
9975 if (dwarf_read_debug
)
9977 fprintf_unfiltered (gdb_stdlog
,
9978 "Expanding one or more symtabs of objfile %s ...\n",
9979 objfile_name (dwarf2_per_objfile
->objfile
));
9982 /* The queue starts out with one item, but following a DIE reference
9983 may load a new CU, adding it to the end of the queue. */
9984 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9986 if ((dwarf2_per_objfile
->using_index
9987 ? !item
->per_cu
->v
.quick
->compunit_symtab
9988 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9989 /* Skip dummy CUs. */
9990 && item
->per_cu
->cu
!= NULL
)
9992 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9993 unsigned int debug_print_threshold
;
9996 if (per_cu
->is_debug_types
)
9998 struct signatured_type
*sig_type
=
9999 (struct signatured_type
*) per_cu
;
10001 sprintf (buf
, "TU %s at offset %s",
10002 hex_string (sig_type
->signature
),
10003 sect_offset_str (per_cu
->sect_off
));
10004 /* There can be 100s of TUs.
10005 Only print them in verbose mode. */
10006 debug_print_threshold
= 2;
10010 sprintf (buf
, "CU at offset %s",
10011 sect_offset_str (per_cu
->sect_off
));
10012 debug_print_threshold
= 1;
10015 if (dwarf_read_debug
>= debug_print_threshold
)
10016 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
10018 if (per_cu
->is_debug_types
)
10019 process_full_type_unit (per_cu
, item
->pretend_language
);
10021 process_full_comp_unit (per_cu
, item
->pretend_language
);
10023 if (dwarf_read_debug
>= debug_print_threshold
)
10024 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
10027 item
->per_cu
->queued
= 0;
10028 next_item
= item
->next
;
10032 dwarf2_queue_tail
= NULL
;
10034 if (dwarf_read_debug
)
10036 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
10037 objfile_name (dwarf2_per_objfile
->objfile
));
10041 /* Read in full symbols for PST, and anything it depends on. */
10044 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
10046 struct dwarf2_per_cu_data
*per_cu
;
10052 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
10053 if (!pst
->dependencies
[i
]->readin
10054 && pst
->dependencies
[i
]->user
== NULL
)
10056 /* Inform about additional files that need to be read in. */
10059 /* FIXME: i18n: Need to make this a single string. */
10060 fputs_filtered (" ", gdb_stdout
);
10062 fputs_filtered ("and ", gdb_stdout
);
10064 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
10065 wrap_here (""); /* Flush output. */
10066 gdb_flush (gdb_stdout
);
10068 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
10071 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
10073 if (per_cu
== NULL
)
10075 /* It's an include file, no symbols to read for it.
10076 Everything is in the parent symtab. */
10081 dw2_do_instantiate_symtab (per_cu
);
10084 /* Trivial hash function for die_info: the hash value of a DIE
10085 is its offset in .debug_info for this objfile. */
10088 die_hash (const void *item
)
10090 const struct die_info
*die
= (const struct die_info
*) item
;
10092 return to_underlying (die
->sect_off
);
10095 /* Trivial comparison function for die_info structures: two DIEs
10096 are equal if they have the same offset. */
10099 die_eq (const void *item_lhs
, const void *item_rhs
)
10101 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
10102 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
10104 return die_lhs
->sect_off
== die_rhs
->sect_off
;
10107 /* die_reader_func for load_full_comp_unit.
10108 This is identical to read_signatured_type_reader,
10109 but is kept separate for now. */
10112 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
10113 const gdb_byte
*info_ptr
,
10114 struct die_info
*comp_unit_die
,
10118 struct dwarf2_cu
*cu
= reader
->cu
;
10119 enum language
*language_ptr
= (enum language
*) data
;
10121 gdb_assert (cu
->die_hash
== NULL
);
10123 htab_create_alloc_ex (cu
->header
.length
/ 12,
10127 &cu
->comp_unit_obstack
,
10128 hashtab_obstack_allocate
,
10129 dummy_obstack_deallocate
);
10132 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
10133 &info_ptr
, comp_unit_die
);
10134 cu
->dies
= comp_unit_die
;
10135 /* comp_unit_die is not stored in die_hash, no need. */
10137 /* We try not to read any attributes in this function, because not
10138 all CUs needed for references have been loaded yet, and symbol
10139 table processing isn't initialized. But we have to set the CU language,
10140 or we won't be able to build types correctly.
10141 Similarly, if we do not read the producer, we can not apply
10142 producer-specific interpretation. */
10143 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
10146 /* Load the DIEs associated with PER_CU into memory. */
10149 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
10150 enum language pretend_language
)
10152 gdb_assert (! this_cu
->is_debug_types
);
10154 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
10155 load_full_comp_unit_reader
, &pretend_language
);
10158 /* Add a DIE to the delayed physname list. */
10161 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
10162 const char *name
, struct die_info
*die
,
10163 struct dwarf2_cu
*cu
)
10165 struct delayed_method_info mi
;
10167 mi
.fnfield_index
= fnfield_index
;
10171 cu
->method_list
.push_back (mi
);
10174 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
10175 "const" / "volatile". If so, decrements LEN by the length of the
10176 modifier and return true. Otherwise return false. */
10180 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
10182 size_t mod_len
= sizeof (mod
) - 1;
10183 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
10191 /* Compute the physnames of any methods on the CU's method list.
10193 The computation of method physnames is delayed in order to avoid the
10194 (bad) condition that one of the method's formal parameters is of an as yet
10195 incomplete type. */
10198 compute_delayed_physnames (struct dwarf2_cu
*cu
)
10200 /* Only C++ delays computing physnames. */
10201 if (cu
->method_list
.empty ())
10203 gdb_assert (cu
->language
== language_cplus
);
10205 for (struct delayed_method_info
&mi
: cu
->method_list
)
10207 const char *physname
;
10208 struct fn_fieldlist
*fn_flp
10209 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
10210 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
10211 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
10212 = physname
? physname
: "";
10214 /* Since there's no tag to indicate whether a method is a
10215 const/volatile overload, extract that information out of the
10217 if (physname
!= NULL
)
10219 size_t len
= strlen (physname
);
10223 if (physname
[len
] == ')') /* shortcut */
10225 else if (check_modifier (physname
, len
, " const"))
10226 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
10227 else if (check_modifier (physname
, len
, " volatile"))
10228 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
10235 /* The list is no longer needed. */
10236 cu
->method_list
.clear ();
10239 /* Go objects should be embedded in a DW_TAG_module DIE,
10240 and it's not clear if/how imported objects will appear.
10241 To keep Go support simple until that's worked out,
10242 go back through what we've read and create something usable.
10243 We could do this while processing each DIE, and feels kinda cleaner,
10244 but that way is more invasive.
10245 This is to, for example, allow the user to type "p var" or "b main"
10246 without having to specify the package name, and allow lookups
10247 of module.object to work in contexts that use the expression
10251 fixup_go_packaging (struct dwarf2_cu
*cu
)
10253 char *package_name
= NULL
;
10254 struct pending
*list
;
10257 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
10259 for (i
= 0; i
< list
->nsyms
; ++i
)
10261 struct symbol
*sym
= list
->symbol
[i
];
10263 if (SYMBOL_LANGUAGE (sym
) == language_go
10264 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
10266 char *this_package_name
= go_symbol_package_name (sym
);
10268 if (this_package_name
== NULL
)
10270 if (package_name
== NULL
)
10271 package_name
= this_package_name
;
10274 struct objfile
*objfile
10275 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10276 if (strcmp (package_name
, this_package_name
) != 0)
10277 complaint (&symfile_complaints
,
10278 _("Symtab %s has objects from two different Go packages: %s and %s"),
10279 (symbol_symtab (sym
) != NULL
10280 ? symtab_to_filename_for_display
10281 (symbol_symtab (sym
))
10282 : objfile_name (objfile
)),
10283 this_package_name
, package_name
);
10284 xfree (this_package_name
);
10290 if (package_name
!= NULL
)
10292 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10293 const char *saved_package_name
10294 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10296 strlen (package_name
));
10297 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
10298 saved_package_name
);
10299 struct symbol
*sym
;
10301 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10303 sym
= allocate_symbol (objfile
);
10304 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
10305 SYMBOL_SET_NAMES (sym
, saved_package_name
,
10306 strlen (saved_package_name
), 0, objfile
);
10307 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
10308 e.g., "main" finds the "main" module and not C's main(). */
10309 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10310 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
10311 SYMBOL_TYPE (sym
) = type
;
10313 add_symbol_to_list (sym
, &global_symbols
);
10315 xfree (package_name
);
10319 /* Allocate a fully-qualified name consisting of the two parts on the
10322 static const char *
10323 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
10325 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
10328 /* A helper that allocates a struct discriminant_info to attach to a
10331 static struct discriminant_info
*
10332 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
10335 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10336 gdb_assert (discriminant_index
== -1
10337 || (discriminant_index
>= 0
10338 && discriminant_index
< TYPE_NFIELDS (type
)));
10339 gdb_assert (default_index
== -1
10340 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
10342 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
10344 struct discriminant_info
*disc
10345 = ((struct discriminant_info
*)
10347 offsetof (struct discriminant_info
, discriminants
)
10348 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
10349 disc
->default_index
= default_index
;
10350 disc
->discriminant_index
= discriminant_index
;
10352 struct dynamic_prop prop
;
10353 prop
.kind
= PROP_UNDEFINED
;
10354 prop
.data
.baton
= disc
;
10356 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
10361 /* Some versions of rustc emitted enums in an unusual way.
10363 Ordinary enums were emitted as unions. The first element of each
10364 structure in the union was named "RUST$ENUM$DISR". This element
10365 held the discriminant.
10367 These versions of Rust also implemented the "non-zero"
10368 optimization. When the enum had two values, and one is empty and
10369 the other holds a pointer that cannot be zero, the pointer is used
10370 as the discriminant, with a zero value meaning the empty variant.
10371 Here, the union's first member is of the form
10372 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10373 where the fieldnos are the indices of the fields that should be
10374 traversed in order to find the field (which may be several fields deep)
10375 and the variantname is the name of the variant of the case when the
10378 This function recognizes whether TYPE is of one of these forms,
10379 and, if so, smashes it to be a variant type. */
10382 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10384 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10386 /* We don't need to deal with empty enums. */
10387 if (TYPE_NFIELDS (type
) == 0)
10390 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10391 if (TYPE_NFIELDS (type
) == 1
10392 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10394 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10396 /* Decode the field name to find the offset of the
10398 ULONGEST bit_offset
= 0;
10399 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10400 while (name
[0] >= '0' && name
[0] <= '9')
10403 unsigned long index
= strtoul (name
, &tail
, 10);
10406 || index
>= TYPE_NFIELDS (field_type
)
10407 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10408 != FIELD_LOC_KIND_BITPOS
))
10410 complaint (&symfile_complaints
,
10411 _("Could not parse Rust enum encoding string \"%s\""
10413 TYPE_FIELD_NAME (type
, 0),
10414 objfile_name (objfile
));
10419 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10420 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10423 /* Make a union to hold the variants. */
10424 struct type
*union_type
= alloc_type (objfile
);
10425 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10426 TYPE_NFIELDS (union_type
) = 3;
10427 TYPE_FIELDS (union_type
)
10428 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10429 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10431 /* Put the discriminant must at index 0. */
10432 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10433 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10434 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10435 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10437 /* The order of fields doesn't really matter, so put the real
10438 field at index 1 and the data-less field at index 2. */
10439 struct discriminant_info
*disc
10440 = alloc_discriminant_info (union_type
, 0, 1);
10441 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10442 TYPE_FIELD_NAME (union_type
, 1)
10443 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10444 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10445 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10446 TYPE_FIELD_NAME (union_type
, 1));
10448 const char *dataless_name
10449 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10451 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10453 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10454 /* NAME points into the original discriminant name, which
10455 already has the correct lifetime. */
10456 TYPE_FIELD_NAME (union_type
, 2) = name
;
10457 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10458 disc
->discriminants
[2] = 0;
10460 /* Smash this type to be a structure type. We have to do this
10461 because the type has already been recorded. */
10462 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10463 TYPE_NFIELDS (type
) = 1;
10465 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10467 /* Install the variant part. */
10468 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10469 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10470 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10472 else if (TYPE_NFIELDS (type
) == 1)
10474 /* We assume that a union with a single field is a univariant
10476 /* Smash this type to be a structure type. We have to do this
10477 because the type has already been recorded. */
10478 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10480 /* Make a union to hold the variants. */
10481 struct type
*union_type
= alloc_type (objfile
);
10482 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10483 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10484 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10485 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10487 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10488 const char *variant_name
10489 = rust_last_path_segment (TYPE_NAME (field_type
));
10490 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10491 TYPE_NAME (field_type
)
10492 = rust_fully_qualify (&objfile
->objfile_obstack
,
10493 TYPE_NAME (type
), variant_name
);
10495 /* Install the union in the outer struct type. */
10496 TYPE_NFIELDS (type
) = 1;
10498 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10499 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10500 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10501 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10503 alloc_discriminant_info (union_type
, -1, 0);
10507 struct type
*disr_type
= nullptr;
10508 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10510 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10512 if (TYPE_NFIELDS (disr_type
) == 0)
10514 /* Could be data-less variant, so keep going. */
10516 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10517 "RUST$ENUM$DISR") != 0)
10519 /* Not a Rust enum. */
10529 /* If we got here without a discriminant, then it's probably
10531 if (disr_type
== nullptr)
10534 /* Smash this type to be a structure type. We have to do this
10535 because the type has already been recorded. */
10536 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10538 /* Make a union to hold the variants. */
10539 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10540 struct type
*union_type
= alloc_type (objfile
);
10541 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10542 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10543 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10544 TYPE_FIELDS (union_type
)
10545 = (struct field
*) TYPE_ZALLOC (union_type
,
10546 (TYPE_NFIELDS (union_type
)
10547 * sizeof (struct field
)));
10549 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10550 TYPE_NFIELDS (type
) * sizeof (struct field
));
10552 /* Install the discriminant at index 0 in the union. */
10553 TYPE_FIELD (union_type
, 0) = *disr_field
;
10554 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10555 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10557 /* Install the union in the outer struct type. */
10558 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10559 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10560 TYPE_NFIELDS (type
) = 1;
10562 /* Set the size and offset of the union type. */
10563 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10565 /* We need a way to find the correct discriminant given a
10566 variant name. For convenience we build a map here. */
10567 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10568 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10569 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10571 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10574 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10575 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10579 int n_fields
= TYPE_NFIELDS (union_type
);
10580 struct discriminant_info
*disc
10581 = alloc_discriminant_info (union_type
, 0, -1);
10582 /* Skip the discriminant here. */
10583 for (int i
= 1; i
< n_fields
; ++i
)
10585 /* Find the final word in the name of this variant's type.
10586 That name can be used to look up the correct
10588 const char *variant_name
10589 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10592 auto iter
= discriminant_map
.find (variant_name
);
10593 if (iter
!= discriminant_map
.end ())
10594 disc
->discriminants
[i
] = iter
->second
;
10596 /* Remove the discriminant field. */
10597 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10598 --TYPE_NFIELDS (sub_type
);
10599 ++TYPE_FIELDS (sub_type
);
10600 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10601 TYPE_NAME (sub_type
)
10602 = rust_fully_qualify (&objfile
->objfile_obstack
,
10603 TYPE_NAME (type
), variant_name
);
10608 /* Rewrite some Rust unions to be structures with variants parts. */
10611 rust_union_quirks (struct dwarf2_cu
*cu
)
10613 gdb_assert (cu
->language
== language_rust
);
10614 for (struct type
*type
: cu
->rust_unions
)
10615 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10618 /* Return the symtab for PER_CU. This works properly regardless of
10619 whether we're using the index or psymtabs. */
10621 static struct compunit_symtab
*
10622 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10624 return (per_cu
->dwarf2_per_objfile
->using_index
10625 ? per_cu
->v
.quick
->compunit_symtab
10626 : per_cu
->v
.psymtab
->compunit_symtab
);
10629 /* A helper function for computing the list of all symbol tables
10630 included by PER_CU. */
10633 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10634 htab_t all_children
, htab_t all_type_symtabs
,
10635 struct dwarf2_per_cu_data
*per_cu
,
10636 struct compunit_symtab
*immediate_parent
)
10640 struct compunit_symtab
*cust
;
10641 struct dwarf2_per_cu_data
*iter
;
10643 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10646 /* This inclusion and its children have been processed. */
10651 /* Only add a CU if it has a symbol table. */
10652 cust
= get_compunit_symtab (per_cu
);
10655 /* If this is a type unit only add its symbol table if we haven't
10656 seen it yet (type unit per_cu's can share symtabs). */
10657 if (per_cu
->is_debug_types
)
10659 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10663 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10664 if (cust
->user
== NULL
)
10665 cust
->user
= immediate_parent
;
10670 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10671 if (cust
->user
== NULL
)
10672 cust
->user
= immediate_parent
;
10677 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10680 recursively_compute_inclusions (result
, all_children
,
10681 all_type_symtabs
, iter
, cust
);
10685 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10689 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10691 gdb_assert (! per_cu
->is_debug_types
);
10693 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10696 struct dwarf2_per_cu_data
*per_cu_iter
;
10697 struct compunit_symtab
*compunit_symtab_iter
;
10698 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10699 htab_t all_children
, all_type_symtabs
;
10700 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10702 /* If we don't have a symtab, we can just skip this case. */
10706 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10707 NULL
, xcalloc
, xfree
);
10708 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10709 NULL
, xcalloc
, xfree
);
10712 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10716 recursively_compute_inclusions (&result_symtabs
, all_children
,
10717 all_type_symtabs
, per_cu_iter
,
10721 /* Now we have a transitive closure of all the included symtabs. */
10722 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10724 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10725 struct compunit_symtab
*, len
+ 1);
10727 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10728 compunit_symtab_iter
);
10730 cust
->includes
[ix
] = compunit_symtab_iter
;
10731 cust
->includes
[len
] = NULL
;
10733 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10734 htab_delete (all_children
);
10735 htab_delete (all_type_symtabs
);
10739 /* Compute the 'includes' field for the symtabs of all the CUs we just
10743 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10746 struct dwarf2_per_cu_data
*iter
;
10749 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10753 if (! iter
->is_debug_types
)
10754 compute_compunit_symtab_includes (iter
);
10757 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10760 /* Generate full symbol information for PER_CU, whose DIEs have
10761 already been loaded into memory. */
10764 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10765 enum language pretend_language
)
10767 struct dwarf2_cu
*cu
= per_cu
->cu
;
10768 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10769 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10770 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10771 CORE_ADDR lowpc
, highpc
;
10772 struct compunit_symtab
*cust
;
10773 CORE_ADDR baseaddr
;
10774 struct block
*static_block
;
10777 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10780 scoped_free_pendings free_pending
;
10782 /* Clear the list here in case something was left over. */
10783 cu
->method_list
.clear ();
10785 cu
->list_in_scope
= &file_symbols
;
10787 cu
->language
= pretend_language
;
10788 cu
->language_defn
= language_def (cu
->language
);
10790 /* Do line number decoding in read_file_scope () */
10791 process_die (cu
->dies
, cu
);
10793 /* For now fudge the Go package. */
10794 if (cu
->language
== language_go
)
10795 fixup_go_packaging (cu
);
10797 /* Now that we have processed all the DIEs in the CU, all the types
10798 should be complete, and it should now be safe to compute all of the
10800 compute_delayed_physnames (cu
);
10802 if (cu
->language
== language_rust
)
10803 rust_union_quirks (cu
);
10805 /* Some compilers don't define a DW_AT_high_pc attribute for the
10806 compilation unit. If the DW_AT_high_pc is missing, synthesize
10807 it, by scanning the DIE's below the compilation unit. */
10808 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10810 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10811 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10813 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10814 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10815 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10816 addrmap to help ensure it has an accurate map of pc values belonging to
10818 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10820 cust
= end_symtab_from_static_block (static_block
,
10821 SECT_OFF_TEXT (objfile
), 0);
10825 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10827 /* Set symtab language to language from DW_AT_language. If the
10828 compilation is from a C file generated by language preprocessors, do
10829 not set the language if it was already deduced by start_subfile. */
10830 if (!(cu
->language
== language_c
10831 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10832 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10834 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10835 produce DW_AT_location with location lists but it can be possibly
10836 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10837 there were bugs in prologue debug info, fixed later in GCC-4.5
10838 by "unwind info for epilogues" patch (which is not directly related).
10840 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10841 needed, it would be wrong due to missing DW_AT_producer there.
10843 Still one can confuse GDB by using non-standard GCC compilation
10844 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10846 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10847 cust
->locations_valid
= 1;
10849 if (gcc_4_minor
>= 5)
10850 cust
->epilogue_unwind_valid
= 1;
10852 cust
->call_site_htab
= cu
->call_site_htab
;
10855 if (dwarf2_per_objfile
->using_index
)
10856 per_cu
->v
.quick
->compunit_symtab
= cust
;
10859 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10860 pst
->compunit_symtab
= cust
;
10864 /* Push it for inclusion processing later. */
10865 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10868 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10869 already been loaded into memory. */
10872 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10873 enum language pretend_language
)
10875 struct dwarf2_cu
*cu
= per_cu
->cu
;
10876 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10877 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10878 struct compunit_symtab
*cust
;
10879 struct signatured_type
*sig_type
;
10881 gdb_assert (per_cu
->is_debug_types
);
10882 sig_type
= (struct signatured_type
*) per_cu
;
10885 scoped_free_pendings free_pending
;
10887 /* Clear the list here in case something was left over. */
10888 cu
->method_list
.clear ();
10890 cu
->list_in_scope
= &file_symbols
;
10892 cu
->language
= pretend_language
;
10893 cu
->language_defn
= language_def (cu
->language
);
10895 /* The symbol tables are set up in read_type_unit_scope. */
10896 process_die (cu
->dies
, cu
);
10898 /* For now fudge the Go package. */
10899 if (cu
->language
== language_go
)
10900 fixup_go_packaging (cu
);
10902 /* Now that we have processed all the DIEs in the CU, all the types
10903 should be complete, and it should now be safe to compute all of the
10905 compute_delayed_physnames (cu
);
10907 if (cu
->language
== language_rust
)
10908 rust_union_quirks (cu
);
10910 /* TUs share symbol tables.
10911 If this is the first TU to use this symtab, complete the construction
10912 of it with end_expandable_symtab. Otherwise, complete the addition of
10913 this TU's symbols to the existing symtab. */
10914 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10916 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10917 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10921 /* Set symtab language to language from DW_AT_language. If the
10922 compilation is from a C file generated by language preprocessors,
10923 do not set the language if it was already deduced by
10925 if (!(cu
->language
== language_c
10926 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10927 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10932 augment_type_symtab ();
10933 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10936 if (dwarf2_per_objfile
->using_index
)
10937 per_cu
->v
.quick
->compunit_symtab
= cust
;
10940 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10941 pst
->compunit_symtab
= cust
;
10946 /* Process an imported unit DIE. */
10949 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10951 struct attribute
*attr
;
10953 /* For now we don't handle imported units in type units. */
10954 if (cu
->per_cu
->is_debug_types
)
10956 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10957 " supported in type units [in module %s]"),
10958 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10961 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10964 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10965 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10966 dwarf2_per_cu_data
*per_cu
10967 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10968 cu
->per_cu
->dwarf2_per_objfile
);
10970 /* If necessary, add it to the queue and load its DIEs. */
10971 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10972 load_full_comp_unit (per_cu
, cu
->language
);
10974 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10979 /* RAII object that represents a process_die scope: i.e.,
10980 starts/finishes processing a DIE. */
10981 class process_die_scope
10984 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10985 : m_die (die
), m_cu (cu
)
10987 /* We should only be processing DIEs not already in process. */
10988 gdb_assert (!m_die
->in_process
);
10989 m_die
->in_process
= true;
10992 ~process_die_scope ()
10994 m_die
->in_process
= false;
10996 /* If we're done processing the DIE for the CU that owns the line
10997 header, we don't need the line header anymore. */
10998 if (m_cu
->line_header_die_owner
== m_die
)
11000 delete m_cu
->line_header
;
11001 m_cu
->line_header
= NULL
;
11002 m_cu
->line_header_die_owner
= NULL
;
11011 /* Process a die and its children. */
11014 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11016 process_die_scope
scope (die
, cu
);
11020 case DW_TAG_padding
:
11022 case DW_TAG_compile_unit
:
11023 case DW_TAG_partial_unit
:
11024 read_file_scope (die
, cu
);
11026 case DW_TAG_type_unit
:
11027 read_type_unit_scope (die
, cu
);
11029 case DW_TAG_subprogram
:
11030 case DW_TAG_inlined_subroutine
:
11031 read_func_scope (die
, cu
);
11033 case DW_TAG_lexical_block
:
11034 case DW_TAG_try_block
:
11035 case DW_TAG_catch_block
:
11036 read_lexical_block_scope (die
, cu
);
11038 case DW_TAG_call_site
:
11039 case DW_TAG_GNU_call_site
:
11040 read_call_site_scope (die
, cu
);
11042 case DW_TAG_class_type
:
11043 case DW_TAG_interface_type
:
11044 case DW_TAG_structure_type
:
11045 case DW_TAG_union_type
:
11046 process_structure_scope (die
, cu
);
11048 case DW_TAG_enumeration_type
:
11049 process_enumeration_scope (die
, cu
);
11052 /* These dies have a type, but processing them does not create
11053 a symbol or recurse to process the children. Therefore we can
11054 read them on-demand through read_type_die. */
11055 case DW_TAG_subroutine_type
:
11056 case DW_TAG_set_type
:
11057 case DW_TAG_array_type
:
11058 case DW_TAG_pointer_type
:
11059 case DW_TAG_ptr_to_member_type
:
11060 case DW_TAG_reference_type
:
11061 case DW_TAG_rvalue_reference_type
:
11062 case DW_TAG_string_type
:
11065 case DW_TAG_base_type
:
11066 case DW_TAG_subrange_type
:
11067 case DW_TAG_typedef
:
11068 /* Add a typedef symbol for the type definition, if it has a
11070 new_symbol (die
, read_type_die (die
, cu
), cu
);
11072 case DW_TAG_common_block
:
11073 read_common_block (die
, cu
);
11075 case DW_TAG_common_inclusion
:
11077 case DW_TAG_namespace
:
11078 cu
->processing_has_namespace_info
= 1;
11079 read_namespace (die
, cu
);
11081 case DW_TAG_module
:
11082 cu
->processing_has_namespace_info
= 1;
11083 read_module (die
, cu
);
11085 case DW_TAG_imported_declaration
:
11086 cu
->processing_has_namespace_info
= 1;
11087 if (read_namespace_alias (die
, cu
))
11089 /* The declaration is not a global namespace alias: fall through. */
11090 case DW_TAG_imported_module
:
11091 cu
->processing_has_namespace_info
= 1;
11092 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
11093 || cu
->language
!= language_fortran
))
11094 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
11095 dwarf_tag_name (die
->tag
));
11096 read_import_statement (die
, cu
);
11099 case DW_TAG_imported_unit
:
11100 process_imported_unit_die (die
, cu
);
11103 case DW_TAG_variable
:
11104 read_variable (die
, cu
);
11108 new_symbol (die
, NULL
, cu
);
11113 /* DWARF name computation. */
11115 /* A helper function for dwarf2_compute_name which determines whether DIE
11116 needs to have the name of the scope prepended to the name listed in the
11120 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11122 struct attribute
*attr
;
11126 case DW_TAG_namespace
:
11127 case DW_TAG_typedef
:
11128 case DW_TAG_class_type
:
11129 case DW_TAG_interface_type
:
11130 case DW_TAG_structure_type
:
11131 case DW_TAG_union_type
:
11132 case DW_TAG_enumeration_type
:
11133 case DW_TAG_enumerator
:
11134 case DW_TAG_subprogram
:
11135 case DW_TAG_inlined_subroutine
:
11136 case DW_TAG_member
:
11137 case DW_TAG_imported_declaration
:
11140 case DW_TAG_variable
:
11141 case DW_TAG_constant
:
11142 /* We only need to prefix "globally" visible variables. These include
11143 any variable marked with DW_AT_external or any variable that
11144 lives in a namespace. [Variables in anonymous namespaces
11145 require prefixing, but they are not DW_AT_external.] */
11147 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
11149 struct dwarf2_cu
*spec_cu
= cu
;
11151 return die_needs_namespace (die_specification (die
, &spec_cu
),
11155 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11156 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
11157 && die
->parent
->tag
!= DW_TAG_module
)
11159 /* A variable in a lexical block of some kind does not need a
11160 namespace, even though in C++ such variables may be external
11161 and have a mangled name. */
11162 if (die
->parent
->tag
== DW_TAG_lexical_block
11163 || die
->parent
->tag
== DW_TAG_try_block
11164 || die
->parent
->tag
== DW_TAG_catch_block
11165 || die
->parent
->tag
== DW_TAG_subprogram
)
11174 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
11175 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
11176 defined for the given DIE. */
11178 static struct attribute
*
11179 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
11181 struct attribute
*attr
;
11183 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
11185 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
11190 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
11191 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
11192 defined for the given DIE. */
11194 static const char *
11195 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11197 const char *linkage_name
;
11199 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
11200 if (linkage_name
== NULL
)
11201 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
11203 return linkage_name
;
11206 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
11207 compute the physname for the object, which include a method's:
11208 - formal parameters (C++),
11209 - receiver type (Go),
11211 The term "physname" is a bit confusing.
11212 For C++, for example, it is the demangled name.
11213 For Go, for example, it's the mangled name.
11215 For Ada, return the DIE's linkage name rather than the fully qualified
11216 name. PHYSNAME is ignored..
11218 The result is allocated on the objfile_obstack and canonicalized. */
11220 static const char *
11221 dwarf2_compute_name (const char *name
,
11222 struct die_info
*die
, struct dwarf2_cu
*cu
,
11225 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11228 name
= dwarf2_name (die
, cu
);
11230 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
11231 but otherwise compute it by typename_concat inside GDB.
11232 FIXME: Actually this is not really true, or at least not always true.
11233 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
11234 Fortran names because there is no mangling standard. So new_symbol
11235 will set the demangled name to the result of dwarf2_full_name, and it is
11236 the demangled name that GDB uses if it exists. */
11237 if (cu
->language
== language_ada
11238 || (cu
->language
== language_fortran
&& physname
))
11240 /* For Ada unit, we prefer the linkage name over the name, as
11241 the former contains the exported name, which the user expects
11242 to be able to reference. Ideally, we want the user to be able
11243 to reference this entity using either natural or linkage name,
11244 but we haven't started looking at this enhancement yet. */
11245 const char *linkage_name
= dw2_linkage_name (die
, cu
);
11247 if (linkage_name
!= NULL
)
11248 return linkage_name
;
11251 /* These are the only languages we know how to qualify names in. */
11253 && (cu
->language
== language_cplus
11254 || cu
->language
== language_fortran
|| cu
->language
== language_d
11255 || cu
->language
== language_rust
))
11257 if (die_needs_namespace (die
, cu
))
11259 const char *prefix
;
11260 const char *canonical_name
= NULL
;
11264 prefix
= determine_prefix (die
, cu
);
11265 if (*prefix
!= '\0')
11267 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
11270 buf
.puts (prefixed_name
);
11271 xfree (prefixed_name
);
11276 /* Template parameters may be specified in the DIE's DW_AT_name, or
11277 as children with DW_TAG_template_type_param or
11278 DW_TAG_value_type_param. If the latter, add them to the name
11279 here. If the name already has template parameters, then
11280 skip this step; some versions of GCC emit both, and
11281 it is more efficient to use the pre-computed name.
11283 Something to keep in mind about this process: it is very
11284 unlikely, or in some cases downright impossible, to produce
11285 something that will match the mangled name of a function.
11286 If the definition of the function has the same debug info,
11287 we should be able to match up with it anyway. But fallbacks
11288 using the minimal symbol, for instance to find a method
11289 implemented in a stripped copy of libstdc++, will not work.
11290 If we do not have debug info for the definition, we will have to
11291 match them up some other way.
11293 When we do name matching there is a related problem with function
11294 templates; two instantiated function templates are allowed to
11295 differ only by their return types, which we do not add here. */
11297 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
11299 struct attribute
*attr
;
11300 struct die_info
*child
;
11303 die
->building_fullname
= 1;
11305 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
11309 const gdb_byte
*bytes
;
11310 struct dwarf2_locexpr_baton
*baton
;
11313 if (child
->tag
!= DW_TAG_template_type_param
11314 && child
->tag
!= DW_TAG_template_value_param
)
11325 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
11328 complaint (&symfile_complaints
,
11329 _("template parameter missing DW_AT_type"));
11330 buf
.puts ("UNKNOWN_TYPE");
11333 type
= die_type (child
, cu
);
11335 if (child
->tag
== DW_TAG_template_type_param
)
11337 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
11341 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
11344 complaint (&symfile_complaints
,
11345 _("template parameter missing "
11346 "DW_AT_const_value"));
11347 buf
.puts ("UNKNOWN_VALUE");
11351 dwarf2_const_value_attr (attr
, type
, name
,
11352 &cu
->comp_unit_obstack
, cu
,
11353 &value
, &bytes
, &baton
);
11355 if (TYPE_NOSIGN (type
))
11356 /* GDB prints characters as NUMBER 'CHAR'. If that's
11357 changed, this can use value_print instead. */
11358 c_printchar (value
, type
, &buf
);
11361 struct value_print_options opts
;
11364 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
11368 else if (bytes
!= NULL
)
11370 v
= allocate_value (type
);
11371 memcpy (value_contents_writeable (v
), bytes
,
11372 TYPE_LENGTH (type
));
11375 v
= value_from_longest (type
, value
);
11377 /* Specify decimal so that we do not depend on
11379 get_formatted_print_options (&opts
, 'd');
11381 value_print (v
, &buf
, &opts
);
11387 die
->building_fullname
= 0;
11391 /* Close the argument list, with a space if necessary
11392 (nested templates). */
11393 if (!buf
.empty () && buf
.string ().back () == '>')
11400 /* For C++ methods, append formal parameter type
11401 information, if PHYSNAME. */
11403 if (physname
&& die
->tag
== DW_TAG_subprogram
11404 && cu
->language
== language_cplus
)
11406 struct type
*type
= read_type_die (die
, cu
);
11408 c_type_print_args (type
, &buf
, 1, cu
->language
,
11409 &type_print_raw_options
);
11411 if (cu
->language
== language_cplus
)
11413 /* Assume that an artificial first parameter is
11414 "this", but do not crash if it is not. RealView
11415 marks unnamed (and thus unused) parameters as
11416 artificial; there is no way to differentiate
11418 if (TYPE_NFIELDS (type
) > 0
11419 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11420 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11421 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11423 buf
.puts (" const");
11427 const std::string
&intermediate_name
= buf
.string ();
11429 if (cu
->language
== language_cplus
)
11431 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11432 &objfile
->per_bfd
->storage_obstack
);
11434 /* If we only computed INTERMEDIATE_NAME, or if
11435 INTERMEDIATE_NAME is already canonical, then we need to
11436 copy it to the appropriate obstack. */
11437 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11438 name
= ((const char *)
11439 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11440 intermediate_name
.c_str (),
11441 intermediate_name
.length ()));
11443 name
= canonical_name
;
11450 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11451 If scope qualifiers are appropriate they will be added. The result
11452 will be allocated on the storage_obstack, or NULL if the DIE does
11453 not have a name. NAME may either be from a previous call to
11454 dwarf2_name or NULL.
11456 The output string will be canonicalized (if C++). */
11458 static const char *
11459 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11461 return dwarf2_compute_name (name
, die
, cu
, 0);
11464 /* Construct a physname for the given DIE in CU. NAME may either be
11465 from a previous call to dwarf2_name or NULL. The result will be
11466 allocated on the objfile_objstack or NULL if the DIE does not have a
11469 The output string will be canonicalized (if C++). */
11471 static const char *
11472 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11474 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11475 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11478 /* In this case dwarf2_compute_name is just a shortcut not building anything
11480 if (!die_needs_namespace (die
, cu
))
11481 return dwarf2_compute_name (name
, die
, cu
, 1);
11483 mangled
= dw2_linkage_name (die
, cu
);
11485 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11486 See https://github.com/rust-lang/rust/issues/32925. */
11487 if (cu
->language
== language_rust
&& mangled
!= NULL
11488 && strchr (mangled
, '{') != NULL
)
11491 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11493 gdb::unique_xmalloc_ptr
<char> demangled
;
11494 if (mangled
!= NULL
)
11497 if (cu
->language
== language_go
)
11499 /* This is a lie, but we already lie to the caller new_symbol.
11500 new_symbol assumes we return the mangled name.
11501 This just undoes that lie until things are cleaned up. */
11505 /* Use DMGL_RET_DROP for C++ template functions to suppress
11506 their return type. It is easier for GDB users to search
11507 for such functions as `name(params)' than `long name(params)'.
11508 In such case the minimal symbol names do not match the full
11509 symbol names but for template functions there is never a need
11510 to look up their definition from their declaration so
11511 the only disadvantage remains the minimal symbol variant
11512 `long name(params)' does not have the proper inferior type. */
11513 demangled
.reset (gdb_demangle (mangled
,
11514 (DMGL_PARAMS
| DMGL_ANSI
11515 | DMGL_RET_DROP
)));
11518 canon
= demangled
.get ();
11526 if (canon
== NULL
|| check_physname
)
11528 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11530 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11532 /* It may not mean a bug in GDB. The compiler could also
11533 compute DW_AT_linkage_name incorrectly. But in such case
11534 GDB would need to be bug-to-bug compatible. */
11536 complaint (&symfile_complaints
,
11537 _("Computed physname <%s> does not match demangled <%s> "
11538 "(from linkage <%s>) - DIE at %s [in module %s]"),
11539 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11540 objfile_name (objfile
));
11542 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11543 is available here - over computed PHYSNAME. It is safer
11544 against both buggy GDB and buggy compilers. */
11558 retval
= ((const char *)
11559 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11560 retval
, strlen (retval
)));
11565 /* Inspect DIE in CU for a namespace alias. If one exists, record
11566 a new symbol for it.
11568 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11571 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11573 struct attribute
*attr
;
11575 /* If the die does not have a name, this is not a namespace
11577 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11581 struct die_info
*d
= die
;
11582 struct dwarf2_cu
*imported_cu
= cu
;
11584 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11585 keep inspecting DIEs until we hit the underlying import. */
11586 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11587 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11589 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11593 d
= follow_die_ref (d
, attr
, &imported_cu
);
11594 if (d
->tag
!= DW_TAG_imported_declaration
)
11598 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11600 complaint (&symfile_complaints
,
11601 _("DIE at %s has too many recursively imported "
11602 "declarations"), sect_offset_str (d
->sect_off
));
11609 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11611 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11612 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11614 /* This declaration is a global namespace alias. Add
11615 a symbol for it whose type is the aliased namespace. */
11616 new_symbol (die
, type
, cu
);
11625 /* Return the using directives repository (global or local?) to use in the
11626 current context for LANGUAGE.
11628 For Ada, imported declarations can materialize renamings, which *may* be
11629 global. However it is impossible (for now?) in DWARF to distinguish
11630 "external" imported declarations and "static" ones. As all imported
11631 declarations seem to be static in all other languages, make them all CU-wide
11632 global only in Ada. */
11634 static struct using_direct
**
11635 using_directives (enum language language
)
11637 if (language
== language_ada
&& context_stack_depth
== 0)
11638 return &global_using_directives
;
11640 return &local_using_directives
;
11643 /* Read the import statement specified by the given die and record it. */
11646 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11648 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11649 struct attribute
*import_attr
;
11650 struct die_info
*imported_die
, *child_die
;
11651 struct dwarf2_cu
*imported_cu
;
11652 const char *imported_name
;
11653 const char *imported_name_prefix
;
11654 const char *canonical_name
;
11655 const char *import_alias
;
11656 const char *imported_declaration
= NULL
;
11657 const char *import_prefix
;
11658 std::vector
<const char *> excludes
;
11660 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11661 if (import_attr
== NULL
)
11663 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11664 dwarf_tag_name (die
->tag
));
11669 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11670 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11671 if (imported_name
== NULL
)
11673 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11675 The import in the following code:
11689 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11690 <52> DW_AT_decl_file : 1
11691 <53> DW_AT_decl_line : 6
11692 <54> DW_AT_import : <0x75>
11693 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11694 <59> DW_AT_name : B
11695 <5b> DW_AT_decl_file : 1
11696 <5c> DW_AT_decl_line : 2
11697 <5d> DW_AT_type : <0x6e>
11699 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11700 <76> DW_AT_byte_size : 4
11701 <77> DW_AT_encoding : 5 (signed)
11703 imports the wrong die ( 0x75 instead of 0x58 ).
11704 This case will be ignored until the gcc bug is fixed. */
11708 /* Figure out the local name after import. */
11709 import_alias
= dwarf2_name (die
, cu
);
11711 /* Figure out where the statement is being imported to. */
11712 import_prefix
= determine_prefix (die
, cu
);
11714 /* Figure out what the scope of the imported die is and prepend it
11715 to the name of the imported die. */
11716 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11718 if (imported_die
->tag
!= DW_TAG_namespace
11719 && imported_die
->tag
!= DW_TAG_module
)
11721 imported_declaration
= imported_name
;
11722 canonical_name
= imported_name_prefix
;
11724 else if (strlen (imported_name_prefix
) > 0)
11725 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11726 imported_name_prefix
,
11727 (cu
->language
== language_d
? "." : "::"),
11728 imported_name
, (char *) NULL
);
11730 canonical_name
= imported_name
;
11732 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11733 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11734 child_die
= sibling_die (child_die
))
11736 /* DWARF-4: A Fortran use statement with a “rename list” may be
11737 represented by an imported module entry with an import attribute
11738 referring to the module and owned entries corresponding to those
11739 entities that are renamed as part of being imported. */
11741 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11743 complaint (&symfile_complaints
,
11744 _("child DW_TAG_imported_declaration expected "
11745 "- DIE at %s [in module %s]"),
11746 sect_offset_str (child_die
->sect_off
),
11747 objfile_name (objfile
));
11751 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11752 if (import_attr
== NULL
)
11754 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11755 dwarf_tag_name (child_die
->tag
));
11760 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11762 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11763 if (imported_name
== NULL
)
11765 complaint (&symfile_complaints
,
11766 _("child DW_TAG_imported_declaration has unknown "
11767 "imported name - DIE at %s [in module %s]"),
11768 sect_offset_str (child_die
->sect_off
),
11769 objfile_name (objfile
));
11773 excludes
.push_back (imported_name
);
11775 process_die (child_die
, cu
);
11778 add_using_directive (using_directives (cu
->language
),
11782 imported_declaration
,
11785 &objfile
->objfile_obstack
);
11788 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11789 types, but gives them a size of zero. Starting with version 14,
11790 ICC is compatible with GCC. */
11793 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11795 if (!cu
->checked_producer
)
11796 check_producer (cu
);
11798 return cu
->producer_is_icc_lt_14
;
11801 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11802 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11803 this, it was first present in GCC release 4.3.0. */
11806 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11808 if (!cu
->checked_producer
)
11809 check_producer (cu
);
11811 return cu
->producer_is_gcc_lt_4_3
;
11814 static file_and_directory
11815 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11817 file_and_directory res
;
11819 /* Find the filename. Do not use dwarf2_name here, since the filename
11820 is not a source language identifier. */
11821 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11822 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11824 if (res
.comp_dir
== NULL
11825 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11826 && IS_ABSOLUTE_PATH (res
.name
))
11828 res
.comp_dir_storage
= ldirname (res
.name
);
11829 if (!res
.comp_dir_storage
.empty ())
11830 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11832 if (res
.comp_dir
!= NULL
)
11834 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11835 directory, get rid of it. */
11836 const char *cp
= strchr (res
.comp_dir
, ':');
11838 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11839 res
.comp_dir
= cp
+ 1;
11842 if (res
.name
== NULL
)
11843 res
.name
= "<unknown>";
11848 /* Handle DW_AT_stmt_list for a compilation unit.
11849 DIE is the DW_TAG_compile_unit die for CU.
11850 COMP_DIR is the compilation directory. LOWPC is passed to
11851 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11854 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11855 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11857 struct dwarf2_per_objfile
*dwarf2_per_objfile
11858 = cu
->per_cu
->dwarf2_per_objfile
;
11859 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11860 struct attribute
*attr
;
11861 struct line_header line_header_local
;
11862 hashval_t line_header_local_hash
;
11864 int decode_mapping
;
11866 gdb_assert (! cu
->per_cu
->is_debug_types
);
11868 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11872 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11874 /* The line header hash table is only created if needed (it exists to
11875 prevent redundant reading of the line table for partial_units).
11876 If we're given a partial_unit, we'll need it. If we're given a
11877 compile_unit, then use the line header hash table if it's already
11878 created, but don't create one just yet. */
11880 if (dwarf2_per_objfile
->line_header_hash
== NULL
11881 && die
->tag
== DW_TAG_partial_unit
)
11883 dwarf2_per_objfile
->line_header_hash
11884 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11885 line_header_eq_voidp
,
11886 free_line_header_voidp
,
11887 &objfile
->objfile_obstack
,
11888 hashtab_obstack_allocate
,
11889 dummy_obstack_deallocate
);
11892 line_header_local
.sect_off
= line_offset
;
11893 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11894 line_header_local_hash
= line_header_hash (&line_header_local
);
11895 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11897 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11898 &line_header_local
,
11899 line_header_local_hash
, NO_INSERT
);
11901 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11902 is not present in *SLOT (since if there is something in *SLOT then
11903 it will be for a partial_unit). */
11904 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11906 gdb_assert (*slot
!= NULL
);
11907 cu
->line_header
= (struct line_header
*) *slot
;
11912 /* dwarf_decode_line_header does not yet provide sufficient information.
11913 We always have to call also dwarf_decode_lines for it. */
11914 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11918 cu
->line_header
= lh
.release ();
11919 cu
->line_header_die_owner
= die
;
11921 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11925 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11926 &line_header_local
,
11927 line_header_local_hash
, INSERT
);
11928 gdb_assert (slot
!= NULL
);
11930 if (slot
!= NULL
&& *slot
== NULL
)
11932 /* This newly decoded line number information unit will be owned
11933 by line_header_hash hash table. */
11934 *slot
= cu
->line_header
;
11935 cu
->line_header_die_owner
= NULL
;
11939 /* We cannot free any current entry in (*slot) as that struct line_header
11940 may be already used by multiple CUs. Create only temporary decoded
11941 line_header for this CU - it may happen at most once for each line
11942 number information unit. And if we're not using line_header_hash
11943 then this is what we want as well. */
11944 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11946 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11947 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11952 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11955 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11957 struct dwarf2_per_objfile
*dwarf2_per_objfile
11958 = cu
->per_cu
->dwarf2_per_objfile
;
11959 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11960 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11961 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11962 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11963 struct attribute
*attr
;
11964 struct die_info
*child_die
;
11965 CORE_ADDR baseaddr
;
11967 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11969 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11971 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11972 from finish_block. */
11973 if (lowpc
== ((CORE_ADDR
) -1))
11975 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11977 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11979 prepare_one_comp_unit (cu
, die
, cu
->language
);
11981 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11982 standardised yet. As a workaround for the language detection we fall
11983 back to the DW_AT_producer string. */
11984 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11985 cu
->language
= language_opencl
;
11987 /* Similar hack for Go. */
11988 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11989 set_cu_language (DW_LANG_Go
, cu
);
11991 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11993 /* Decode line number information if present. We do this before
11994 processing child DIEs, so that the line header table is available
11995 for DW_AT_decl_file. */
11996 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11998 /* Process all dies in compilation unit. */
11999 if (die
->child
!= NULL
)
12001 child_die
= die
->child
;
12002 while (child_die
&& child_die
->tag
)
12004 process_die (child_die
, cu
);
12005 child_die
= sibling_die (child_die
);
12009 /* Decode macro information, if present. Dwarf 2 macro information
12010 refers to information in the line number info statement program
12011 header, so we can only read it if we've read the header
12013 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
12015 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
12016 if (attr
&& cu
->line_header
)
12018 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
12019 complaint (&symfile_complaints
,
12020 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
12022 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
12026 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
12027 if (attr
&& cu
->line_header
)
12029 unsigned int macro_offset
= DW_UNSND (attr
);
12031 dwarf_decode_macros (cu
, macro_offset
, 0);
12036 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
12037 Create the set of symtabs used by this TU, or if this TU is sharing
12038 symtabs with another TU and the symtabs have already been created
12039 then restore those symtabs in the line header.
12040 We don't need the pc/line-number mapping for type units. */
12043 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
12045 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
12046 struct type_unit_group
*tu_group
;
12048 struct attribute
*attr
;
12050 struct signatured_type
*sig_type
;
12052 gdb_assert (per_cu
->is_debug_types
);
12053 sig_type
= (struct signatured_type
*) per_cu
;
12055 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
12057 /* If we're using .gdb_index (includes -readnow) then
12058 per_cu->type_unit_group may not have been set up yet. */
12059 if (sig_type
->type_unit_group
== NULL
)
12060 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
12061 tu_group
= sig_type
->type_unit_group
;
12063 /* If we've already processed this stmt_list there's no real need to
12064 do it again, we could fake it and just recreate the part we need
12065 (file name,index -> symtab mapping). If data shows this optimization
12066 is useful we can do it then. */
12067 first_time
= tu_group
->compunit_symtab
== NULL
;
12069 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
12074 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
12075 lh
= dwarf_decode_line_header (line_offset
, cu
);
12080 dwarf2_start_symtab (cu
, "", NULL
, 0);
12083 gdb_assert (tu_group
->symtabs
== NULL
);
12084 restart_symtab (tu_group
->compunit_symtab
, "", 0);
12089 cu
->line_header
= lh
.release ();
12090 cu
->line_header_die_owner
= die
;
12094 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
12096 /* Note: We don't assign tu_group->compunit_symtab yet because we're
12097 still initializing it, and our caller (a few levels up)
12098 process_full_type_unit still needs to know if this is the first
12101 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
12102 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
12103 cu
->line_header
->file_names
.size ());
12105 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
12107 file_entry
&fe
= cu
->line_header
->file_names
[i
];
12109 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
12111 if (current_subfile
->symtab
== NULL
)
12113 /* NOTE: start_subfile will recognize when it's been
12114 passed a file it has already seen. So we can't
12115 assume there's a simple mapping from
12116 cu->line_header->file_names to subfiles, plus
12117 cu->line_header->file_names may contain dups. */
12118 current_subfile
->symtab
12119 = allocate_symtab (cust
, current_subfile
->name
);
12122 fe
.symtab
= current_subfile
->symtab
;
12123 tu_group
->symtabs
[i
] = fe
.symtab
;
12128 restart_symtab (tu_group
->compunit_symtab
, "", 0);
12130 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
12132 file_entry
&fe
= cu
->line_header
->file_names
[i
];
12134 fe
.symtab
= tu_group
->symtabs
[i
];
12138 /* The main symtab is allocated last. Type units don't have DW_AT_name
12139 so they don't have a "real" (so to speak) symtab anyway.
12140 There is later code that will assign the main symtab to all symbols
12141 that don't have one. We need to handle the case of a symbol with a
12142 missing symtab (DW_AT_decl_file) anyway. */
12145 /* Process DW_TAG_type_unit.
12146 For TUs we want to skip the first top level sibling if it's not the
12147 actual type being defined by this TU. In this case the first top
12148 level sibling is there to provide context only. */
12151 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12153 struct die_info
*child_die
;
12155 prepare_one_comp_unit (cu
, die
, language_minimal
);
12157 /* Initialize (or reinitialize) the machinery for building symtabs.
12158 We do this before processing child DIEs, so that the line header table
12159 is available for DW_AT_decl_file. */
12160 setup_type_unit_groups (die
, cu
);
12162 if (die
->child
!= NULL
)
12164 child_die
= die
->child
;
12165 while (child_die
&& child_die
->tag
)
12167 process_die (child_die
, cu
);
12168 child_die
= sibling_die (child_die
);
12175 http://gcc.gnu.org/wiki/DebugFission
12176 http://gcc.gnu.org/wiki/DebugFissionDWP
12178 To simplify handling of both DWO files ("object" files with the DWARF info)
12179 and DWP files (a file with the DWOs packaged up into one file), we treat
12180 DWP files as having a collection of virtual DWO files. */
12183 hash_dwo_file (const void *item
)
12185 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
12188 hash
= htab_hash_string (dwo_file
->dwo_name
);
12189 if (dwo_file
->comp_dir
!= NULL
)
12190 hash
+= htab_hash_string (dwo_file
->comp_dir
);
12195 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
12197 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
12198 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
12200 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
12202 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
12203 return lhs
->comp_dir
== rhs
->comp_dir
;
12204 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
12207 /* Allocate a hash table for DWO files. */
12210 allocate_dwo_file_hash_table (struct objfile
*objfile
)
12212 return htab_create_alloc_ex (41,
12216 &objfile
->objfile_obstack
,
12217 hashtab_obstack_allocate
,
12218 dummy_obstack_deallocate
);
12221 /* Lookup DWO file DWO_NAME. */
12224 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12225 const char *dwo_name
,
12226 const char *comp_dir
)
12228 struct dwo_file find_entry
;
12231 if (dwarf2_per_objfile
->dwo_files
== NULL
)
12232 dwarf2_per_objfile
->dwo_files
12233 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
12235 memset (&find_entry
, 0, sizeof (find_entry
));
12236 find_entry
.dwo_name
= dwo_name
;
12237 find_entry
.comp_dir
= comp_dir
;
12238 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
12244 hash_dwo_unit (const void *item
)
12246 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12248 /* This drops the top 32 bits of the id, but is ok for a hash. */
12249 return dwo_unit
->signature
;
12253 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
12255 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
12256 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
12258 /* The signature is assumed to be unique within the DWO file.
12259 So while object file CU dwo_id's always have the value zero,
12260 that's OK, assuming each object file DWO file has only one CU,
12261 and that's the rule for now. */
12262 return lhs
->signature
== rhs
->signature
;
12265 /* Allocate a hash table for DWO CUs,TUs.
12266 There is one of these tables for each of CUs,TUs for each DWO file. */
12269 allocate_dwo_unit_table (struct objfile
*objfile
)
12271 /* Start out with a pretty small number.
12272 Generally DWO files contain only one CU and maybe some TUs. */
12273 return htab_create_alloc_ex (3,
12277 &objfile
->objfile_obstack
,
12278 hashtab_obstack_allocate
,
12279 dummy_obstack_deallocate
);
12282 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
12284 struct create_dwo_cu_data
12286 struct dwo_file
*dwo_file
;
12287 struct dwo_unit dwo_unit
;
12290 /* die_reader_func for create_dwo_cu. */
12293 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
12294 const gdb_byte
*info_ptr
,
12295 struct die_info
*comp_unit_die
,
12299 struct dwarf2_cu
*cu
= reader
->cu
;
12300 sect_offset sect_off
= cu
->per_cu
->sect_off
;
12301 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
12302 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
12303 struct dwo_file
*dwo_file
= data
->dwo_file
;
12304 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
12305 struct attribute
*attr
;
12307 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
12310 complaint (&symfile_complaints
,
12311 _("Dwarf Error: debug entry at offset %s is missing"
12312 " its dwo_id [in module %s]"),
12313 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
12317 dwo_unit
->dwo_file
= dwo_file
;
12318 dwo_unit
->signature
= DW_UNSND (attr
);
12319 dwo_unit
->section
= section
;
12320 dwo_unit
->sect_off
= sect_off
;
12321 dwo_unit
->length
= cu
->per_cu
->length
;
12323 if (dwarf_read_debug
)
12324 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
12325 sect_offset_str (sect_off
),
12326 hex_string (dwo_unit
->signature
));
12329 /* Create the dwo_units for the CUs in a DWO_FILE.
12330 Note: This function processes DWO files only, not DWP files. */
12333 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12334 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
12337 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12338 const gdb_byte
*info_ptr
, *end_ptr
;
12340 dwarf2_read_section (objfile
, §ion
);
12341 info_ptr
= section
.buffer
;
12343 if (info_ptr
== NULL
)
12346 if (dwarf_read_debug
)
12348 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
12349 get_section_name (§ion
),
12350 get_section_file_name (§ion
));
12353 end_ptr
= info_ptr
+ section
.size
;
12354 while (info_ptr
< end_ptr
)
12356 struct dwarf2_per_cu_data per_cu
;
12357 struct create_dwo_cu_data create_dwo_cu_data
;
12358 struct dwo_unit
*dwo_unit
;
12360 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12362 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12363 sizeof (create_dwo_cu_data
.dwo_unit
));
12364 memset (&per_cu
, 0, sizeof (per_cu
));
12365 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12366 per_cu
.is_debug_types
= 0;
12367 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12368 per_cu
.section
= §ion
;
12369 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12371 init_cutu_and_read_dies_no_follow (
12372 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12373 info_ptr
+= per_cu
.length
;
12375 // If the unit could not be parsed, skip it.
12376 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12379 if (cus_htab
== NULL
)
12380 cus_htab
= allocate_dwo_unit_table (objfile
);
12382 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12383 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12384 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12385 gdb_assert (slot
!= NULL
);
12388 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12389 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12391 complaint (&symfile_complaints
,
12392 _("debug cu entry at offset %s is duplicate to"
12393 " the entry at offset %s, signature %s"),
12394 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12395 hex_string (dwo_unit
->signature
));
12397 *slot
= (void *)dwo_unit
;
12401 /* DWP file .debug_{cu,tu}_index section format:
12402 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12406 Both index sections have the same format, and serve to map a 64-bit
12407 signature to a set of section numbers. Each section begins with a header,
12408 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12409 indexes, and a pool of 32-bit section numbers. The index sections will be
12410 aligned at 8-byte boundaries in the file.
12412 The index section header consists of:
12414 V, 32 bit version number
12416 N, 32 bit number of compilation units or type units in the index
12417 M, 32 bit number of slots in the hash table
12419 Numbers are recorded using the byte order of the application binary.
12421 The hash table begins at offset 16 in the section, and consists of an array
12422 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12423 order of the application binary). Unused slots in the hash table are 0.
12424 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12426 The parallel table begins immediately after the hash table
12427 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12428 array of 32-bit indexes (using the byte order of the application binary),
12429 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12430 table contains a 32-bit index into the pool of section numbers. For unused
12431 hash table slots, the corresponding entry in the parallel table will be 0.
12433 The pool of section numbers begins immediately following the hash table
12434 (at offset 16 + 12 * M from the beginning of the section). The pool of
12435 section numbers consists of an array of 32-bit words (using the byte order
12436 of the application binary). Each item in the array is indexed starting
12437 from 0. The hash table entry provides the index of the first section
12438 number in the set. Additional section numbers in the set follow, and the
12439 set is terminated by a 0 entry (section number 0 is not used in ELF).
12441 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12442 section must be the first entry in the set, and the .debug_abbrev.dwo must
12443 be the second entry. Other members of the set may follow in any order.
12449 DWP Version 2 combines all the .debug_info, etc. sections into one,
12450 and the entries in the index tables are now offsets into these sections.
12451 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12454 Index Section Contents:
12456 Hash Table of Signatures dwp_hash_table.hash_table
12457 Parallel Table of Indices dwp_hash_table.unit_table
12458 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12459 Table of Section Sizes dwp_hash_table.v2.sizes
12461 The index section header consists of:
12463 V, 32 bit version number
12464 L, 32 bit number of columns in the table of section offsets
12465 N, 32 bit number of compilation units or type units in the index
12466 M, 32 bit number of slots in the hash table
12468 Numbers are recorded using the byte order of the application binary.
12470 The hash table has the same format as version 1.
12471 The parallel table of indices has the same format as version 1,
12472 except that the entries are origin-1 indices into the table of sections
12473 offsets and the table of section sizes.
12475 The table of offsets begins immediately following the parallel table
12476 (at offset 16 + 12 * M from the beginning of the section). The table is
12477 a two-dimensional array of 32-bit words (using the byte order of the
12478 application binary), with L columns and N+1 rows, in row-major order.
12479 Each row in the array is indexed starting from 0. The first row provides
12480 a key to the remaining rows: each column in this row provides an identifier
12481 for a debug section, and the offsets in the same column of subsequent rows
12482 refer to that section. The section identifiers are:
12484 DW_SECT_INFO 1 .debug_info.dwo
12485 DW_SECT_TYPES 2 .debug_types.dwo
12486 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12487 DW_SECT_LINE 4 .debug_line.dwo
12488 DW_SECT_LOC 5 .debug_loc.dwo
12489 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12490 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12491 DW_SECT_MACRO 8 .debug_macro.dwo
12493 The offsets provided by the CU and TU index sections are the base offsets
12494 for the contributions made by each CU or TU to the corresponding section
12495 in the package file. Each CU and TU header contains an abbrev_offset
12496 field, used to find the abbreviations table for that CU or TU within the
12497 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12498 be interpreted as relative to the base offset given in the index section.
12499 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12500 should be interpreted as relative to the base offset for .debug_line.dwo,
12501 and offsets into other debug sections obtained from DWARF attributes should
12502 also be interpreted as relative to the corresponding base offset.
12504 The table of sizes begins immediately following the table of offsets.
12505 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12506 with L columns and N rows, in row-major order. Each row in the array is
12507 indexed starting from 1 (row 0 is shared by the two tables).
12511 Hash table lookup is handled the same in version 1 and 2:
12513 We assume that N and M will not exceed 2^32 - 1.
12514 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12516 Given a 64-bit compilation unit signature or a type signature S, an entry
12517 in the hash table is located as follows:
12519 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12520 the low-order k bits all set to 1.
12522 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12524 3) If the hash table entry at index H matches the signature, use that
12525 entry. If the hash table entry at index H is unused (all zeroes),
12526 terminate the search: the signature is not present in the table.
12528 4) Let H = (H + H') modulo M. Repeat at Step 3.
12530 Because M > N and H' and M are relatively prime, the search is guaranteed
12531 to stop at an unused slot or find the match. */
12533 /* Create a hash table to map DWO IDs to their CU/TU entry in
12534 .debug_{info,types}.dwo in DWP_FILE.
12535 Returns NULL if there isn't one.
12536 Note: This function processes DWP files only, not DWO files. */
12538 static struct dwp_hash_table
*
12539 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12540 struct dwp_file
*dwp_file
, int is_debug_types
)
12542 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12543 bfd
*dbfd
= dwp_file
->dbfd
;
12544 const gdb_byte
*index_ptr
, *index_end
;
12545 struct dwarf2_section_info
*index
;
12546 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12547 struct dwp_hash_table
*htab
;
12549 if (is_debug_types
)
12550 index
= &dwp_file
->sections
.tu_index
;
12552 index
= &dwp_file
->sections
.cu_index
;
12554 if (dwarf2_section_empty_p (index
))
12556 dwarf2_read_section (objfile
, index
);
12558 index_ptr
= index
->buffer
;
12559 index_end
= index_ptr
+ index
->size
;
12561 version
= read_4_bytes (dbfd
, index_ptr
);
12564 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12568 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12570 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12573 if (version
!= 1 && version
!= 2)
12575 error (_("Dwarf Error: unsupported DWP file version (%s)"
12576 " [in module %s]"),
12577 pulongest (version
), dwp_file
->name
);
12579 if (nr_slots
!= (nr_slots
& -nr_slots
))
12581 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12582 " is not power of 2 [in module %s]"),
12583 pulongest (nr_slots
), dwp_file
->name
);
12586 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12587 htab
->version
= version
;
12588 htab
->nr_columns
= nr_columns
;
12589 htab
->nr_units
= nr_units
;
12590 htab
->nr_slots
= nr_slots
;
12591 htab
->hash_table
= index_ptr
;
12592 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12594 /* Exit early if the table is empty. */
12595 if (nr_slots
== 0 || nr_units
== 0
12596 || (version
== 2 && nr_columns
== 0))
12598 /* All must be zero. */
12599 if (nr_slots
!= 0 || nr_units
!= 0
12600 || (version
== 2 && nr_columns
!= 0))
12602 complaint (&symfile_complaints
,
12603 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12604 " all zero [in modules %s]"),
12612 htab
->section_pool
.v1
.indices
=
12613 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12614 /* It's harder to decide whether the section is too small in v1.
12615 V1 is deprecated anyway so we punt. */
12619 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12620 int *ids
= htab
->section_pool
.v2
.section_ids
;
12621 /* Reverse map for error checking. */
12622 int ids_seen
[DW_SECT_MAX
+ 1];
12625 if (nr_columns
< 2)
12627 error (_("Dwarf Error: bad DWP hash table, too few columns"
12628 " in section table [in module %s]"),
12631 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12633 error (_("Dwarf Error: bad DWP hash table, too many columns"
12634 " in section table [in module %s]"),
12637 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12638 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12639 for (i
= 0; i
< nr_columns
; ++i
)
12641 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12643 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12645 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12646 " in section table [in module %s]"),
12647 id
, dwp_file
->name
);
12649 if (ids_seen
[id
] != -1)
12651 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12652 " id %d in section table [in module %s]"),
12653 id
, dwp_file
->name
);
12658 /* Must have exactly one info or types section. */
12659 if (((ids_seen
[DW_SECT_INFO
] != -1)
12660 + (ids_seen
[DW_SECT_TYPES
] != -1))
12663 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12664 " DWO info/types section [in module %s]"),
12667 /* Must have an abbrev section. */
12668 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12670 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12671 " section [in module %s]"),
12674 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12675 htab
->section_pool
.v2
.sizes
=
12676 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12677 * nr_units
* nr_columns
);
12678 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12679 * nr_units
* nr_columns
))
12682 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12683 " [in module %s]"),
12691 /* Update SECTIONS with the data from SECTP.
12693 This function is like the other "locate" section routines that are
12694 passed to bfd_map_over_sections, but in this context the sections to
12695 read comes from the DWP V1 hash table, not the full ELF section table.
12697 The result is non-zero for success, or zero if an error was found. */
12700 locate_v1_virtual_dwo_sections (asection
*sectp
,
12701 struct virtual_v1_dwo_sections
*sections
)
12703 const struct dwop_section_names
*names
= &dwop_section_names
;
12705 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12707 /* There can be only one. */
12708 if (sections
->abbrev
.s
.section
!= NULL
)
12710 sections
->abbrev
.s
.section
= sectp
;
12711 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12713 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12714 || section_is_p (sectp
->name
, &names
->types_dwo
))
12716 /* There can be only one. */
12717 if (sections
->info_or_types
.s
.section
!= NULL
)
12719 sections
->info_or_types
.s
.section
= sectp
;
12720 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12722 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12724 /* There can be only one. */
12725 if (sections
->line
.s
.section
!= NULL
)
12727 sections
->line
.s
.section
= sectp
;
12728 sections
->line
.size
= bfd_get_section_size (sectp
);
12730 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12732 /* There can be only one. */
12733 if (sections
->loc
.s
.section
!= NULL
)
12735 sections
->loc
.s
.section
= sectp
;
12736 sections
->loc
.size
= bfd_get_section_size (sectp
);
12738 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12740 /* There can be only one. */
12741 if (sections
->macinfo
.s
.section
!= NULL
)
12743 sections
->macinfo
.s
.section
= sectp
;
12744 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12746 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12748 /* There can be only one. */
12749 if (sections
->macro
.s
.section
!= NULL
)
12751 sections
->macro
.s
.section
= sectp
;
12752 sections
->macro
.size
= bfd_get_section_size (sectp
);
12754 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12756 /* There can be only one. */
12757 if (sections
->str_offsets
.s
.section
!= NULL
)
12759 sections
->str_offsets
.s
.section
= sectp
;
12760 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12764 /* No other kind of section is valid. */
12771 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12772 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12773 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12774 This is for DWP version 1 files. */
12776 static struct dwo_unit
*
12777 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12778 struct dwp_file
*dwp_file
,
12779 uint32_t unit_index
,
12780 const char *comp_dir
,
12781 ULONGEST signature
, int is_debug_types
)
12783 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12784 const struct dwp_hash_table
*dwp_htab
=
12785 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12786 bfd
*dbfd
= dwp_file
->dbfd
;
12787 const char *kind
= is_debug_types
? "TU" : "CU";
12788 struct dwo_file
*dwo_file
;
12789 struct dwo_unit
*dwo_unit
;
12790 struct virtual_v1_dwo_sections sections
;
12791 void **dwo_file_slot
;
12794 gdb_assert (dwp_file
->version
== 1);
12796 if (dwarf_read_debug
)
12798 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12800 pulongest (unit_index
), hex_string (signature
),
12804 /* Fetch the sections of this DWO unit.
12805 Put a limit on the number of sections we look for so that bad data
12806 doesn't cause us to loop forever. */
12808 #define MAX_NR_V1_DWO_SECTIONS \
12809 (1 /* .debug_info or .debug_types */ \
12810 + 1 /* .debug_abbrev */ \
12811 + 1 /* .debug_line */ \
12812 + 1 /* .debug_loc */ \
12813 + 1 /* .debug_str_offsets */ \
12814 + 1 /* .debug_macro or .debug_macinfo */ \
12815 + 1 /* trailing zero */)
12817 memset (§ions
, 0, sizeof (sections
));
12819 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12822 uint32_t section_nr
=
12823 read_4_bytes (dbfd
,
12824 dwp_htab
->section_pool
.v1
.indices
12825 + (unit_index
+ i
) * sizeof (uint32_t));
12827 if (section_nr
== 0)
12829 if (section_nr
>= dwp_file
->num_sections
)
12831 error (_("Dwarf Error: bad DWP hash table, section number too large"
12832 " [in module %s]"),
12836 sectp
= dwp_file
->elf_sections
[section_nr
];
12837 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12839 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12840 " [in module %s]"),
12846 || dwarf2_section_empty_p (§ions
.info_or_types
)
12847 || dwarf2_section_empty_p (§ions
.abbrev
))
12849 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12850 " [in module %s]"),
12853 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12855 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12856 " [in module %s]"),
12860 /* It's easier for the rest of the code if we fake a struct dwo_file and
12861 have dwo_unit "live" in that. At least for now.
12863 The DWP file can be made up of a random collection of CUs and TUs.
12864 However, for each CU + set of TUs that came from the same original DWO
12865 file, we can combine them back into a virtual DWO file to save space
12866 (fewer struct dwo_file objects to allocate). Remember that for really
12867 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12869 std::string virtual_dwo_name
=
12870 string_printf ("virtual-dwo/%d-%d-%d-%d",
12871 get_section_id (§ions
.abbrev
),
12872 get_section_id (§ions
.line
),
12873 get_section_id (§ions
.loc
),
12874 get_section_id (§ions
.str_offsets
));
12875 /* Can we use an existing virtual DWO file? */
12876 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12877 virtual_dwo_name
.c_str (),
12879 /* Create one if necessary. */
12880 if (*dwo_file_slot
== NULL
)
12882 if (dwarf_read_debug
)
12884 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12885 virtual_dwo_name
.c_str ());
12887 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12889 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12890 virtual_dwo_name
.c_str (),
12891 virtual_dwo_name
.size ());
12892 dwo_file
->comp_dir
= comp_dir
;
12893 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12894 dwo_file
->sections
.line
= sections
.line
;
12895 dwo_file
->sections
.loc
= sections
.loc
;
12896 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12897 dwo_file
->sections
.macro
= sections
.macro
;
12898 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12899 /* The "str" section is global to the entire DWP file. */
12900 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12901 /* The info or types section is assigned below to dwo_unit,
12902 there's no need to record it in dwo_file.
12903 Also, we can't simply record type sections in dwo_file because
12904 we record a pointer into the vector in dwo_unit. As we collect more
12905 types we'll grow the vector and eventually have to reallocate space
12906 for it, invalidating all copies of pointers into the previous
12908 *dwo_file_slot
= dwo_file
;
12912 if (dwarf_read_debug
)
12914 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12915 virtual_dwo_name
.c_str ());
12917 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12920 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12921 dwo_unit
->dwo_file
= dwo_file
;
12922 dwo_unit
->signature
= signature
;
12923 dwo_unit
->section
=
12924 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12925 *dwo_unit
->section
= sections
.info_or_types
;
12926 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12931 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12932 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12933 piece within that section used by a TU/CU, return a virtual section
12934 of just that piece. */
12936 static struct dwarf2_section_info
12937 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12938 struct dwarf2_section_info
*section
,
12939 bfd_size_type offset
, bfd_size_type size
)
12941 struct dwarf2_section_info result
;
12944 gdb_assert (section
!= NULL
);
12945 gdb_assert (!section
->is_virtual
);
12947 memset (&result
, 0, sizeof (result
));
12948 result
.s
.containing_section
= section
;
12949 result
.is_virtual
= 1;
12954 sectp
= get_section_bfd_section (section
);
12956 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12957 bounds of the real section. This is a pretty-rare event, so just
12958 flag an error (easier) instead of a warning and trying to cope. */
12960 || offset
+ size
> bfd_get_section_size (sectp
))
12962 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12963 " in section %s [in module %s]"),
12964 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12965 objfile_name (dwarf2_per_objfile
->objfile
));
12968 result
.virtual_offset
= offset
;
12969 result
.size
= size
;
12973 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12974 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12975 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12976 This is for DWP version 2 files. */
12978 static struct dwo_unit
*
12979 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12980 struct dwp_file
*dwp_file
,
12981 uint32_t unit_index
,
12982 const char *comp_dir
,
12983 ULONGEST signature
, int is_debug_types
)
12985 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12986 const struct dwp_hash_table
*dwp_htab
=
12987 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12988 bfd
*dbfd
= dwp_file
->dbfd
;
12989 const char *kind
= is_debug_types
? "TU" : "CU";
12990 struct dwo_file
*dwo_file
;
12991 struct dwo_unit
*dwo_unit
;
12992 struct virtual_v2_dwo_sections sections
;
12993 void **dwo_file_slot
;
12996 gdb_assert (dwp_file
->version
== 2);
12998 if (dwarf_read_debug
)
13000 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
13002 pulongest (unit_index
), hex_string (signature
),
13006 /* Fetch the section offsets of this DWO unit. */
13008 memset (§ions
, 0, sizeof (sections
));
13010 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
13012 uint32_t offset
= read_4_bytes (dbfd
,
13013 dwp_htab
->section_pool
.v2
.offsets
13014 + (((unit_index
- 1) * dwp_htab
->nr_columns
13016 * sizeof (uint32_t)));
13017 uint32_t size
= read_4_bytes (dbfd
,
13018 dwp_htab
->section_pool
.v2
.sizes
13019 + (((unit_index
- 1) * dwp_htab
->nr_columns
13021 * sizeof (uint32_t)));
13023 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
13026 case DW_SECT_TYPES
:
13027 sections
.info_or_types_offset
= offset
;
13028 sections
.info_or_types_size
= size
;
13030 case DW_SECT_ABBREV
:
13031 sections
.abbrev_offset
= offset
;
13032 sections
.abbrev_size
= size
;
13035 sections
.line_offset
= offset
;
13036 sections
.line_size
= size
;
13039 sections
.loc_offset
= offset
;
13040 sections
.loc_size
= size
;
13042 case DW_SECT_STR_OFFSETS
:
13043 sections
.str_offsets_offset
= offset
;
13044 sections
.str_offsets_size
= size
;
13046 case DW_SECT_MACINFO
:
13047 sections
.macinfo_offset
= offset
;
13048 sections
.macinfo_size
= size
;
13050 case DW_SECT_MACRO
:
13051 sections
.macro_offset
= offset
;
13052 sections
.macro_size
= size
;
13057 /* It's easier for the rest of the code if we fake a struct dwo_file and
13058 have dwo_unit "live" in that. At least for now.
13060 The DWP file can be made up of a random collection of CUs and TUs.
13061 However, for each CU + set of TUs that came from the same original DWO
13062 file, we can combine them back into a virtual DWO file to save space
13063 (fewer struct dwo_file objects to allocate). Remember that for really
13064 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
13066 std::string virtual_dwo_name
=
13067 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
13068 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
13069 (long) (sections
.line_size
? sections
.line_offset
: 0),
13070 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
13071 (long) (sections
.str_offsets_size
13072 ? sections
.str_offsets_offset
: 0));
13073 /* Can we use an existing virtual DWO file? */
13074 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13075 virtual_dwo_name
.c_str (),
13077 /* Create one if necessary. */
13078 if (*dwo_file_slot
== NULL
)
13080 if (dwarf_read_debug
)
13082 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
13083 virtual_dwo_name
.c_str ());
13085 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13087 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
13088 virtual_dwo_name
.c_str (),
13089 virtual_dwo_name
.size ());
13090 dwo_file
->comp_dir
= comp_dir
;
13091 dwo_file
->sections
.abbrev
=
13092 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
13093 sections
.abbrev_offset
, sections
.abbrev_size
);
13094 dwo_file
->sections
.line
=
13095 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
13096 sections
.line_offset
, sections
.line_size
);
13097 dwo_file
->sections
.loc
=
13098 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
13099 sections
.loc_offset
, sections
.loc_size
);
13100 dwo_file
->sections
.macinfo
=
13101 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
13102 sections
.macinfo_offset
, sections
.macinfo_size
);
13103 dwo_file
->sections
.macro
=
13104 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
13105 sections
.macro_offset
, sections
.macro_size
);
13106 dwo_file
->sections
.str_offsets
=
13107 create_dwp_v2_section (dwarf2_per_objfile
,
13108 &dwp_file
->sections
.str_offsets
,
13109 sections
.str_offsets_offset
,
13110 sections
.str_offsets_size
);
13111 /* The "str" section is global to the entire DWP file. */
13112 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
13113 /* The info or types section is assigned below to dwo_unit,
13114 there's no need to record it in dwo_file.
13115 Also, we can't simply record type sections in dwo_file because
13116 we record a pointer into the vector in dwo_unit. As we collect more
13117 types we'll grow the vector and eventually have to reallocate space
13118 for it, invalidating all copies of pointers into the previous
13120 *dwo_file_slot
= dwo_file
;
13124 if (dwarf_read_debug
)
13126 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
13127 virtual_dwo_name
.c_str ());
13129 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13132 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
13133 dwo_unit
->dwo_file
= dwo_file
;
13134 dwo_unit
->signature
= signature
;
13135 dwo_unit
->section
=
13136 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
13137 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
13139 ? &dwp_file
->sections
.types
13140 : &dwp_file
->sections
.info
,
13141 sections
.info_or_types_offset
,
13142 sections
.info_or_types_size
);
13143 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
13148 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
13149 Returns NULL if the signature isn't found. */
13151 static struct dwo_unit
*
13152 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13153 struct dwp_file
*dwp_file
, const char *comp_dir
,
13154 ULONGEST signature
, int is_debug_types
)
13156 const struct dwp_hash_table
*dwp_htab
=
13157 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13158 bfd
*dbfd
= dwp_file
->dbfd
;
13159 uint32_t mask
= dwp_htab
->nr_slots
- 1;
13160 uint32_t hash
= signature
& mask
;
13161 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
13164 struct dwo_unit find_dwo_cu
;
13166 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
13167 find_dwo_cu
.signature
= signature
;
13168 slot
= htab_find_slot (is_debug_types
13169 ? dwp_file
->loaded_tus
13170 : dwp_file
->loaded_cus
,
13171 &find_dwo_cu
, INSERT
);
13174 return (struct dwo_unit
*) *slot
;
13176 /* Use a for loop so that we don't loop forever on bad debug info. */
13177 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
13179 ULONGEST signature_in_table
;
13181 signature_in_table
=
13182 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
13183 if (signature_in_table
== signature
)
13185 uint32_t unit_index
=
13186 read_4_bytes (dbfd
,
13187 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
13189 if (dwp_file
->version
== 1)
13191 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
13192 dwp_file
, unit_index
,
13193 comp_dir
, signature
,
13198 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
13199 dwp_file
, unit_index
,
13200 comp_dir
, signature
,
13203 return (struct dwo_unit
*) *slot
;
13205 if (signature_in_table
== 0)
13207 hash
= (hash
+ hash2
) & mask
;
13210 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
13211 " [in module %s]"),
13215 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
13216 Open the file specified by FILE_NAME and hand it off to BFD for
13217 preliminary analysis. Return a newly initialized bfd *, which
13218 includes a canonicalized copy of FILE_NAME.
13219 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
13220 SEARCH_CWD is true if the current directory is to be searched.
13221 It will be searched before debug-file-directory.
13222 If successful, the file is added to the bfd include table of the
13223 objfile's bfd (see gdb_bfd_record_inclusion).
13224 If unable to find/open the file, return NULL.
13225 NOTE: This function is derived from symfile_bfd_open. */
13227 static gdb_bfd_ref_ptr
13228 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13229 const char *file_name
, int is_dwp
, int search_cwd
)
13232 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
13233 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
13234 to debug_file_directory. */
13235 const char *search_path
;
13236 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
13238 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
13241 if (*debug_file_directory
!= '\0')
13243 search_path_holder
.reset (concat (".", dirname_separator_string
,
13244 debug_file_directory
,
13246 search_path
= search_path_holder
.get ();
13252 search_path
= debug_file_directory
;
13254 openp_flags flags
= OPF_RETURN_REALPATH
;
13256 flags
|= OPF_SEARCH_IN_PATH
;
13258 gdb::unique_xmalloc_ptr
<char> absolute_name
;
13259 desc
= openp (search_path
, flags
, file_name
,
13260 O_RDONLY
| O_BINARY
, &absolute_name
);
13264 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
13266 if (sym_bfd
== NULL
)
13268 bfd_set_cacheable (sym_bfd
.get (), 1);
13270 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
13273 /* Success. Record the bfd as having been included by the objfile's bfd.
13274 This is important because things like demangled_names_hash lives in the
13275 objfile's per_bfd space and may have references to things like symbol
13276 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
13277 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
13282 /* Try to open DWO file FILE_NAME.
13283 COMP_DIR is the DW_AT_comp_dir attribute.
13284 The result is the bfd handle of the file.
13285 If there is a problem finding or opening the file, return NULL.
13286 Upon success, the canonicalized path of the file is stored in the bfd,
13287 same as symfile_bfd_open. */
13289 static gdb_bfd_ref_ptr
13290 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13291 const char *file_name
, const char *comp_dir
)
13293 if (IS_ABSOLUTE_PATH (file_name
))
13294 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13295 0 /*is_dwp*/, 0 /*search_cwd*/);
13297 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
13299 if (comp_dir
!= NULL
)
13301 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
13302 file_name
, (char *) NULL
);
13304 /* NOTE: If comp_dir is a relative path, this will also try the
13305 search path, which seems useful. */
13306 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
13309 1 /*search_cwd*/));
13310 xfree (path_to_try
);
13315 /* That didn't work, try debug-file-directory, which, despite its name,
13316 is a list of paths. */
13318 if (*debug_file_directory
== '\0')
13321 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13322 0 /*is_dwp*/, 1 /*search_cwd*/);
13325 /* This function is mapped across the sections and remembers the offset and
13326 size of each of the DWO debugging sections we are interested in. */
13329 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
13331 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
13332 const struct dwop_section_names
*names
= &dwop_section_names
;
13334 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13336 dwo_sections
->abbrev
.s
.section
= sectp
;
13337 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
13339 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13341 dwo_sections
->info
.s
.section
= sectp
;
13342 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
13344 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13346 dwo_sections
->line
.s
.section
= sectp
;
13347 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
13349 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13351 dwo_sections
->loc
.s
.section
= sectp
;
13352 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
13354 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13356 dwo_sections
->macinfo
.s
.section
= sectp
;
13357 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
13359 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13361 dwo_sections
->macro
.s
.section
= sectp
;
13362 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
13364 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13366 dwo_sections
->str
.s
.section
= sectp
;
13367 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
13369 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13371 dwo_sections
->str_offsets
.s
.section
= sectp
;
13372 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
13374 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13376 struct dwarf2_section_info type_section
;
13378 memset (&type_section
, 0, sizeof (type_section
));
13379 type_section
.s
.section
= sectp
;
13380 type_section
.size
= bfd_get_section_size (sectp
);
13381 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
13386 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13387 by PER_CU. This is for the non-DWP case.
13388 The result is NULL if DWO_NAME can't be found. */
13390 static struct dwo_file
*
13391 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13392 const char *dwo_name
, const char *comp_dir
)
13394 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13395 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13396 struct dwo_file
*dwo_file
;
13397 struct cleanup
*cleanups
;
13399 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
13402 if (dwarf_read_debug
)
13403 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13406 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13407 dwo_file
->dwo_name
= dwo_name
;
13408 dwo_file
->comp_dir
= comp_dir
;
13409 dwo_file
->dbfd
= dbfd
.release ();
13411 free_dwo_file_cleanup_data
*cleanup_data
= XNEW (free_dwo_file_cleanup_data
);
13412 cleanup_data
->dwo_file
= dwo_file
;
13413 cleanup_data
->dwarf2_per_objfile
= dwarf2_per_objfile
;
13415 cleanups
= make_cleanup (free_dwo_file_cleanup
, cleanup_data
);
13417 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13418 &dwo_file
->sections
);
13420 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13423 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
,
13424 dwo_file
->sections
.types
, dwo_file
->tus
);
13426 discard_cleanups (cleanups
);
13428 if (dwarf_read_debug
)
13429 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13434 /* This function is mapped across the sections and remembers the offset and
13435 size of each of the DWP debugging sections common to version 1 and 2 that
13436 we are interested in. */
13439 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13440 void *dwp_file_ptr
)
13442 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13443 const struct dwop_section_names
*names
= &dwop_section_names
;
13444 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13446 /* Record the ELF section number for later lookup: this is what the
13447 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13448 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13449 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13451 /* Look for specific sections that we need. */
13452 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13454 dwp_file
->sections
.str
.s
.section
= sectp
;
13455 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13457 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13459 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13460 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13462 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13464 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13465 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13469 /* This function is mapped across the sections and remembers the offset and
13470 size of each of the DWP version 2 debugging sections that we are interested
13471 in. This is split into a separate function because we don't know if we
13472 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13475 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13477 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13478 const struct dwop_section_names
*names
= &dwop_section_names
;
13479 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13481 /* Record the ELF section number for later lookup: this is what the
13482 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13483 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13484 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13486 /* Look for specific sections that we need. */
13487 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13489 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13490 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13492 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13494 dwp_file
->sections
.info
.s
.section
= sectp
;
13495 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13497 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13499 dwp_file
->sections
.line
.s
.section
= sectp
;
13500 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13502 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13504 dwp_file
->sections
.loc
.s
.section
= sectp
;
13505 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13507 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13509 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13510 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13512 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13514 dwp_file
->sections
.macro
.s
.section
= sectp
;
13515 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13517 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13519 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13520 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13522 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13524 dwp_file
->sections
.types
.s
.section
= sectp
;
13525 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13529 /* Hash function for dwp_file loaded CUs/TUs. */
13532 hash_dwp_loaded_cutus (const void *item
)
13534 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13536 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13537 return dwo_unit
->signature
;
13540 /* Equality function for dwp_file loaded CUs/TUs. */
13543 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13545 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13546 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13548 return dua
->signature
== dub
->signature
;
13551 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13554 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13556 return htab_create_alloc_ex (3,
13557 hash_dwp_loaded_cutus
,
13558 eq_dwp_loaded_cutus
,
13560 &objfile
->objfile_obstack
,
13561 hashtab_obstack_allocate
,
13562 dummy_obstack_deallocate
);
13565 /* Try to open DWP file FILE_NAME.
13566 The result is the bfd handle of the file.
13567 If there is a problem finding or opening the file, return NULL.
13568 Upon success, the canonicalized path of the file is stored in the bfd,
13569 same as symfile_bfd_open. */
13571 static gdb_bfd_ref_ptr
13572 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13573 const char *file_name
)
13575 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13577 1 /*search_cwd*/));
13581 /* Work around upstream bug 15652.
13582 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13583 [Whether that's a "bug" is debatable, but it is getting in our way.]
13584 We have no real idea where the dwp file is, because gdb's realpath-ing
13585 of the executable's path may have discarded the needed info.
13586 [IWBN if the dwp file name was recorded in the executable, akin to
13587 .gnu_debuglink, but that doesn't exist yet.]
13588 Strip the directory from FILE_NAME and search again. */
13589 if (*debug_file_directory
!= '\0')
13591 /* Don't implicitly search the current directory here.
13592 If the user wants to search "." to handle this case,
13593 it must be added to debug-file-directory. */
13594 return try_open_dwop_file (dwarf2_per_objfile
,
13595 lbasename (file_name
), 1 /*is_dwp*/,
13602 /* Initialize the use of the DWP file for the current objfile.
13603 By convention the name of the DWP file is ${objfile}.dwp.
13604 The result is NULL if it can't be found. */
13606 static struct dwp_file
*
13607 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13609 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13610 struct dwp_file
*dwp_file
;
13612 /* Try to find first .dwp for the binary file before any symbolic links
13615 /* If the objfile is a debug file, find the name of the real binary
13616 file and get the name of dwp file from there. */
13617 std::string dwp_name
;
13618 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13620 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13621 const char *backlink_basename
= lbasename (backlink
->original_name
);
13623 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13626 dwp_name
= objfile
->original_name
;
13628 dwp_name
+= ".dwp";
13630 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13632 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13634 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13635 dwp_name
= objfile_name (objfile
);
13636 dwp_name
+= ".dwp";
13637 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13642 if (dwarf_read_debug
)
13643 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13646 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13647 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13648 dwp_file
->dbfd
= dbfd
.release ();
13650 /* +1: section 0 is unused */
13651 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13652 dwp_file
->elf_sections
=
13653 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13654 dwp_file
->num_sections
, asection
*);
13656 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13659 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13661 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13663 /* The DWP file version is stored in the hash table. Oh well. */
13664 if (dwp_file
->cus
&& dwp_file
->tus
13665 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13667 /* Technically speaking, we should try to limp along, but this is
13668 pretty bizarre. We use pulongest here because that's the established
13669 portability solution (e.g, we cannot use %u for uint32_t). */
13670 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13671 " TU version %s [in DWP file %s]"),
13672 pulongest (dwp_file
->cus
->version
),
13673 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13677 dwp_file
->version
= dwp_file
->cus
->version
;
13678 else if (dwp_file
->tus
)
13679 dwp_file
->version
= dwp_file
->tus
->version
;
13681 dwp_file
->version
= 2;
13683 if (dwp_file
->version
== 2)
13684 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13687 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13688 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13690 if (dwarf_read_debug
)
13692 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13693 fprintf_unfiltered (gdb_stdlog
,
13694 " %s CUs, %s TUs\n",
13695 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13696 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13702 /* Wrapper around open_and_init_dwp_file, only open it once. */
13704 static struct dwp_file
*
13705 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13707 if (! dwarf2_per_objfile
->dwp_checked
)
13709 dwarf2_per_objfile
->dwp_file
13710 = open_and_init_dwp_file (dwarf2_per_objfile
);
13711 dwarf2_per_objfile
->dwp_checked
= 1;
13713 return dwarf2_per_objfile
->dwp_file
;
13716 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13717 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13718 or in the DWP file for the objfile, referenced by THIS_UNIT.
13719 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13720 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13722 This is called, for example, when wanting to read a variable with a
13723 complex location. Therefore we don't want to do file i/o for every call.
13724 Therefore we don't want to look for a DWO file on every call.
13725 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13726 then we check if we've already seen DWO_NAME, and only THEN do we check
13729 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13730 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13732 static struct dwo_unit
*
13733 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13734 const char *dwo_name
, const char *comp_dir
,
13735 ULONGEST signature
, int is_debug_types
)
13737 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13738 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13739 const char *kind
= is_debug_types
? "TU" : "CU";
13740 void **dwo_file_slot
;
13741 struct dwo_file
*dwo_file
;
13742 struct dwp_file
*dwp_file
;
13744 /* First see if there's a DWP file.
13745 If we have a DWP file but didn't find the DWO inside it, don't
13746 look for the original DWO file. It makes gdb behave differently
13747 depending on whether one is debugging in the build tree. */
13749 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13750 if (dwp_file
!= NULL
)
13752 const struct dwp_hash_table
*dwp_htab
=
13753 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13755 if (dwp_htab
!= NULL
)
13757 struct dwo_unit
*dwo_cutu
=
13758 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13759 signature
, is_debug_types
);
13761 if (dwo_cutu
!= NULL
)
13763 if (dwarf_read_debug
)
13765 fprintf_unfiltered (gdb_stdlog
,
13766 "Virtual DWO %s %s found: @%s\n",
13767 kind
, hex_string (signature
),
13768 host_address_to_string (dwo_cutu
));
13776 /* No DWP file, look for the DWO file. */
13778 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13779 dwo_name
, comp_dir
);
13780 if (*dwo_file_slot
== NULL
)
13782 /* Read in the file and build a table of the CUs/TUs it contains. */
13783 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13785 /* NOTE: This will be NULL if unable to open the file. */
13786 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13788 if (dwo_file
!= NULL
)
13790 struct dwo_unit
*dwo_cutu
= NULL
;
13792 if (is_debug_types
&& dwo_file
->tus
)
13794 struct dwo_unit find_dwo_cutu
;
13796 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13797 find_dwo_cutu
.signature
= signature
;
13799 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13801 else if (!is_debug_types
&& dwo_file
->cus
)
13803 struct dwo_unit find_dwo_cutu
;
13805 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13806 find_dwo_cutu
.signature
= signature
;
13807 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13811 if (dwo_cutu
!= NULL
)
13813 if (dwarf_read_debug
)
13815 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13816 kind
, dwo_name
, hex_string (signature
),
13817 host_address_to_string (dwo_cutu
));
13824 /* We didn't find it. This could mean a dwo_id mismatch, or
13825 someone deleted the DWO/DWP file, or the search path isn't set up
13826 correctly to find the file. */
13828 if (dwarf_read_debug
)
13830 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13831 kind
, dwo_name
, hex_string (signature
));
13834 /* This is a warning and not a complaint because it can be caused by
13835 pilot error (e.g., user accidentally deleting the DWO). */
13837 /* Print the name of the DWP file if we looked there, helps the user
13838 better diagnose the problem. */
13839 std::string dwp_text
;
13841 if (dwp_file
!= NULL
)
13842 dwp_text
= string_printf (" [in DWP file %s]",
13843 lbasename (dwp_file
->name
));
13845 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13846 " [in module %s]"),
13847 kind
, dwo_name
, hex_string (signature
),
13849 this_unit
->is_debug_types
? "TU" : "CU",
13850 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13855 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13856 See lookup_dwo_cutu_unit for details. */
13858 static struct dwo_unit
*
13859 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13860 const char *dwo_name
, const char *comp_dir
,
13861 ULONGEST signature
)
13863 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13866 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13867 See lookup_dwo_cutu_unit for details. */
13869 static struct dwo_unit
*
13870 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13871 const char *dwo_name
, const char *comp_dir
)
13873 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13876 /* Traversal function for queue_and_load_all_dwo_tus. */
13879 queue_and_load_dwo_tu (void **slot
, void *info
)
13881 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13882 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13883 ULONGEST signature
= dwo_unit
->signature
;
13884 struct signatured_type
*sig_type
=
13885 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13887 if (sig_type
!= NULL
)
13889 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13891 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13892 a real dependency of PER_CU on SIG_TYPE. That is detected later
13893 while processing PER_CU. */
13894 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13895 load_full_type_unit (sig_cu
);
13896 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13902 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13903 The DWO may have the only definition of the type, though it may not be
13904 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13905 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13908 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13910 struct dwo_unit
*dwo_unit
;
13911 struct dwo_file
*dwo_file
;
13913 gdb_assert (!per_cu
->is_debug_types
);
13914 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13915 gdb_assert (per_cu
->cu
!= NULL
);
13917 dwo_unit
= per_cu
->cu
->dwo_unit
;
13918 gdb_assert (dwo_unit
!= NULL
);
13920 dwo_file
= dwo_unit
->dwo_file
;
13921 if (dwo_file
->tus
!= NULL
)
13922 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13925 /* Free all resources associated with DWO_FILE.
13926 Close the DWO file and munmap the sections.
13927 All memory should be on the objfile obstack. */
13930 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
13933 /* Note: dbfd is NULL for virtual DWO files. */
13934 gdb_bfd_unref (dwo_file
->dbfd
);
13936 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13939 /* Wrapper for free_dwo_file for use in cleanups. */
13942 free_dwo_file_cleanup (void *arg
)
13944 struct free_dwo_file_cleanup_data
*data
13945 = (struct free_dwo_file_cleanup_data
*) arg
;
13946 struct objfile
*objfile
= data
->dwarf2_per_objfile
->objfile
;
13948 free_dwo_file (data
->dwo_file
, objfile
);
13953 /* Traversal function for free_dwo_files. */
13956 free_dwo_file_from_slot (void **slot
, void *info
)
13958 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13959 struct objfile
*objfile
= (struct objfile
*) info
;
13961 free_dwo_file (dwo_file
, objfile
);
13966 /* Free all resources associated with DWO_FILES. */
13969 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13971 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13974 /* Read in various DIEs. */
13976 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13977 Inherit only the children of the DW_AT_abstract_origin DIE not being
13978 already referenced by DW_AT_abstract_origin from the children of the
13982 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13984 struct die_info
*child_die
;
13985 sect_offset
*offsetp
;
13986 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13987 struct die_info
*origin_die
;
13988 /* Iterator of the ORIGIN_DIE children. */
13989 struct die_info
*origin_child_die
;
13990 struct attribute
*attr
;
13991 struct dwarf2_cu
*origin_cu
;
13992 struct pending
**origin_previous_list_in_scope
;
13994 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13998 /* Note that following die references may follow to a die in a
14002 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
14004 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
14006 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
14007 origin_cu
->list_in_scope
= cu
->list_in_scope
;
14009 if (die
->tag
!= origin_die
->tag
14010 && !(die
->tag
== DW_TAG_inlined_subroutine
14011 && origin_die
->tag
== DW_TAG_subprogram
))
14012 complaint (&symfile_complaints
,
14013 _("DIE %s and its abstract origin %s have different tags"),
14014 sect_offset_str (die
->sect_off
),
14015 sect_offset_str (origin_die
->sect_off
));
14017 std::vector
<sect_offset
> offsets
;
14019 for (child_die
= die
->child
;
14020 child_die
&& child_die
->tag
;
14021 child_die
= sibling_die (child_die
))
14023 struct die_info
*child_origin_die
;
14024 struct dwarf2_cu
*child_origin_cu
;
14026 /* We are trying to process concrete instance entries:
14027 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
14028 it's not relevant to our analysis here. i.e. detecting DIEs that are
14029 present in the abstract instance but not referenced in the concrete
14031 if (child_die
->tag
== DW_TAG_call_site
14032 || child_die
->tag
== DW_TAG_GNU_call_site
)
14035 /* For each CHILD_DIE, find the corresponding child of
14036 ORIGIN_DIE. If there is more than one layer of
14037 DW_AT_abstract_origin, follow them all; there shouldn't be,
14038 but GCC versions at least through 4.4 generate this (GCC PR
14040 child_origin_die
= child_die
;
14041 child_origin_cu
= cu
;
14044 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
14048 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
14052 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
14053 counterpart may exist. */
14054 if (child_origin_die
!= child_die
)
14056 if (child_die
->tag
!= child_origin_die
->tag
14057 && !(child_die
->tag
== DW_TAG_inlined_subroutine
14058 && child_origin_die
->tag
== DW_TAG_subprogram
))
14059 complaint (&symfile_complaints
,
14060 _("Child DIE %s and its abstract origin %s have "
14062 sect_offset_str (child_die
->sect_off
),
14063 sect_offset_str (child_origin_die
->sect_off
));
14064 if (child_origin_die
->parent
!= origin_die
)
14065 complaint (&symfile_complaints
,
14066 _("Child DIE %s and its abstract origin %s have "
14067 "different parents"),
14068 sect_offset_str (child_die
->sect_off
),
14069 sect_offset_str (child_origin_die
->sect_off
));
14071 offsets
.push_back (child_origin_die
->sect_off
);
14074 std::sort (offsets
.begin (), offsets
.end ());
14075 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
14076 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
14077 if (offsetp
[-1] == *offsetp
)
14078 complaint (&symfile_complaints
,
14079 _("Multiple children of DIE %s refer "
14080 "to DIE %s as their abstract origin"),
14081 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
14083 offsetp
= offsets
.data ();
14084 origin_child_die
= origin_die
->child
;
14085 while (origin_child_die
&& origin_child_die
->tag
)
14087 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
14088 while (offsetp
< offsets_end
14089 && *offsetp
< origin_child_die
->sect_off
)
14091 if (offsetp
>= offsets_end
14092 || *offsetp
> origin_child_die
->sect_off
)
14094 /* Found that ORIGIN_CHILD_DIE is really not referenced.
14095 Check whether we're already processing ORIGIN_CHILD_DIE.
14096 This can happen with mutually referenced abstract_origins.
14098 if (!origin_child_die
->in_process
)
14099 process_die (origin_child_die
, origin_cu
);
14101 origin_child_die
= sibling_die (origin_child_die
);
14103 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
14107 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14109 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14110 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14111 struct context_stack
*newobj
;
14114 struct die_info
*child_die
;
14115 struct attribute
*attr
, *call_line
, *call_file
;
14117 CORE_ADDR baseaddr
;
14118 struct block
*block
;
14119 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14120 std::vector
<struct symbol
*> template_args
;
14121 struct template_symbol
*templ_func
= NULL
;
14125 /* If we do not have call site information, we can't show the
14126 caller of this inlined function. That's too confusing, so
14127 only use the scope for local variables. */
14128 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
14129 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
14130 if (call_line
== NULL
|| call_file
== NULL
)
14132 read_lexical_block_scope (die
, cu
);
14137 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14139 name
= dwarf2_name (die
, cu
);
14141 /* Ignore functions with missing or empty names. These are actually
14142 illegal according to the DWARF standard. */
14145 complaint (&symfile_complaints
,
14146 _("missing name for subprogram DIE at %s"),
14147 sect_offset_str (die
->sect_off
));
14151 /* Ignore functions with missing or invalid low and high pc attributes. */
14152 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
14153 <= PC_BOUNDS_INVALID
)
14155 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
14156 if (!attr
|| !DW_UNSND (attr
))
14157 complaint (&symfile_complaints
,
14158 _("cannot get low and high bounds "
14159 "for subprogram DIE at %s"),
14160 sect_offset_str (die
->sect_off
));
14164 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14165 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
14167 /* If we have any template arguments, then we must allocate a
14168 different sort of symbol. */
14169 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
14171 if (child_die
->tag
== DW_TAG_template_type_param
14172 || child_die
->tag
== DW_TAG_template_value_param
)
14174 templ_func
= allocate_template_symbol (objfile
);
14175 templ_func
->subclass
= SYMBOL_TEMPLATE
;
14180 newobj
= push_context (0, lowpc
);
14181 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
14182 (struct symbol
*) templ_func
);
14184 /* If there is a location expression for DW_AT_frame_base, record
14186 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
14188 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
14190 /* If there is a location for the static link, record it. */
14191 newobj
->static_link
= NULL
;
14192 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
14195 newobj
->static_link
14196 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
14197 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
14200 cu
->list_in_scope
= &local_symbols
;
14202 if (die
->child
!= NULL
)
14204 child_die
= die
->child
;
14205 while (child_die
&& child_die
->tag
)
14207 if (child_die
->tag
== DW_TAG_template_type_param
14208 || child_die
->tag
== DW_TAG_template_value_param
)
14210 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
14213 template_args
.push_back (arg
);
14216 process_die (child_die
, cu
);
14217 child_die
= sibling_die (child_die
);
14221 inherit_abstract_dies (die
, cu
);
14223 /* If we have a DW_AT_specification, we might need to import using
14224 directives from the context of the specification DIE. See the
14225 comment in determine_prefix. */
14226 if (cu
->language
== language_cplus
14227 && dwarf2_attr (die
, DW_AT_specification
, cu
))
14229 struct dwarf2_cu
*spec_cu
= cu
;
14230 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
14234 child_die
= spec_die
->child
;
14235 while (child_die
&& child_die
->tag
)
14237 if (child_die
->tag
== DW_TAG_imported_module
)
14238 process_die (child_die
, spec_cu
);
14239 child_die
= sibling_die (child_die
);
14242 /* In some cases, GCC generates specification DIEs that
14243 themselves contain DW_AT_specification attributes. */
14244 spec_die
= die_specification (spec_die
, &spec_cu
);
14248 newobj
= pop_context ();
14249 /* Make a block for the local symbols within. */
14250 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
14251 newobj
->static_link
, lowpc
, highpc
);
14253 /* For C++, set the block's scope. */
14254 if ((cu
->language
== language_cplus
14255 || cu
->language
== language_fortran
14256 || cu
->language
== language_d
14257 || cu
->language
== language_rust
)
14258 && cu
->processing_has_namespace_info
)
14259 block_set_scope (block
, determine_prefix (die
, cu
),
14260 &objfile
->objfile_obstack
);
14262 /* If we have address ranges, record them. */
14263 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14265 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
14267 /* Attach template arguments to function. */
14268 if (!template_args
.empty ())
14270 gdb_assert (templ_func
!= NULL
);
14272 templ_func
->n_template_arguments
= template_args
.size ();
14273 templ_func
->template_arguments
14274 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
14275 templ_func
->n_template_arguments
);
14276 memcpy (templ_func
->template_arguments
,
14277 template_args
.data (),
14278 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
14281 /* In C++, we can have functions nested inside functions (e.g., when
14282 a function declares a class that has methods). This means that
14283 when we finish processing a function scope, we may need to go
14284 back to building a containing block's symbol lists. */
14285 local_symbols
= newobj
->locals
;
14286 local_using_directives
= newobj
->local_using_directives
;
14288 /* If we've finished processing a top-level function, subsequent
14289 symbols go in the file symbol list. */
14290 if (outermost_context_p ())
14291 cu
->list_in_scope
= &file_symbols
;
14294 /* Process all the DIES contained within a lexical block scope. Start
14295 a new scope, process the dies, and then close the scope. */
14298 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14300 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14301 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14302 struct context_stack
*newobj
;
14303 CORE_ADDR lowpc
, highpc
;
14304 struct die_info
*child_die
;
14305 CORE_ADDR baseaddr
;
14307 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14309 /* Ignore blocks with missing or invalid low and high pc attributes. */
14310 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
14311 as multiple lexical blocks? Handling children in a sane way would
14312 be nasty. Might be easier to properly extend generic blocks to
14313 describe ranges. */
14314 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
14316 case PC_BOUNDS_NOT_PRESENT
:
14317 /* DW_TAG_lexical_block has no attributes, process its children as if
14318 there was no wrapping by that DW_TAG_lexical_block.
14319 GCC does no longer produces such DWARF since GCC r224161. */
14320 for (child_die
= die
->child
;
14321 child_die
!= NULL
&& child_die
->tag
;
14322 child_die
= sibling_die (child_die
))
14323 process_die (child_die
, cu
);
14325 case PC_BOUNDS_INVALID
:
14328 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14329 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
14331 push_context (0, lowpc
);
14332 if (die
->child
!= NULL
)
14334 child_die
= die
->child
;
14335 while (child_die
&& child_die
->tag
)
14337 process_die (child_die
, cu
);
14338 child_die
= sibling_die (child_die
);
14341 inherit_abstract_dies (die
, cu
);
14342 newobj
= pop_context ();
14344 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
14346 struct block
*block
14347 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
14348 newobj
->start_addr
, highpc
);
14350 /* Note that recording ranges after traversing children, as we
14351 do here, means that recording a parent's ranges entails
14352 walking across all its children's ranges as they appear in
14353 the address map, which is quadratic behavior.
14355 It would be nicer to record the parent's ranges before
14356 traversing its children, simply overriding whatever you find
14357 there. But since we don't even decide whether to create a
14358 block until after we've traversed its children, that's hard
14360 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14362 local_symbols
= newobj
->locals
;
14363 local_using_directives
= newobj
->local_using_directives
;
14366 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
14369 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14371 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14372 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14373 CORE_ADDR pc
, baseaddr
;
14374 struct attribute
*attr
;
14375 struct call_site
*call_site
, call_site_local
;
14378 struct die_info
*child_die
;
14380 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14382 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
14385 /* This was a pre-DWARF-5 GNU extension alias
14386 for DW_AT_call_return_pc. */
14387 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14391 complaint (&symfile_complaints
,
14392 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
14393 "DIE %s [in module %s]"),
14394 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14397 pc
= attr_value_as_address (attr
) + baseaddr
;
14398 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14400 if (cu
->call_site_htab
== NULL
)
14401 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14402 NULL
, &objfile
->objfile_obstack
,
14403 hashtab_obstack_allocate
, NULL
);
14404 call_site_local
.pc
= pc
;
14405 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14408 complaint (&symfile_complaints
,
14409 _("Duplicate PC %s for DW_TAG_call_site "
14410 "DIE %s [in module %s]"),
14411 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14412 objfile_name (objfile
));
14416 /* Count parameters at the caller. */
14419 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14420 child_die
= sibling_die (child_die
))
14422 if (child_die
->tag
!= DW_TAG_call_site_parameter
14423 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14425 complaint (&symfile_complaints
,
14426 _("Tag %d is not DW_TAG_call_site_parameter in "
14427 "DW_TAG_call_site child DIE %s [in module %s]"),
14428 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14429 objfile_name (objfile
));
14437 = ((struct call_site
*)
14438 obstack_alloc (&objfile
->objfile_obstack
,
14439 sizeof (*call_site
)
14440 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14442 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14443 call_site
->pc
= pc
;
14445 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14446 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14448 struct die_info
*func_die
;
14450 /* Skip also over DW_TAG_inlined_subroutine. */
14451 for (func_die
= die
->parent
;
14452 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14453 && func_die
->tag
!= DW_TAG_subroutine_type
;
14454 func_die
= func_die
->parent
);
14456 /* DW_AT_call_all_calls is a superset
14457 of DW_AT_call_all_tail_calls. */
14459 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14460 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14461 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14462 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14464 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14465 not complete. But keep CALL_SITE for look ups via call_site_htab,
14466 both the initial caller containing the real return address PC and
14467 the final callee containing the current PC of a chain of tail
14468 calls do not need to have the tail call list complete. But any
14469 function candidate for a virtual tail call frame searched via
14470 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14471 determined unambiguously. */
14475 struct type
*func_type
= NULL
;
14478 func_type
= get_die_type (func_die
, cu
);
14479 if (func_type
!= NULL
)
14481 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14483 /* Enlist this call site to the function. */
14484 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14485 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14488 complaint (&symfile_complaints
,
14489 _("Cannot find function owning DW_TAG_call_site "
14490 "DIE %s [in module %s]"),
14491 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14495 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14497 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14499 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14502 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14503 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14505 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14506 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14507 /* Keep NULL DWARF_BLOCK. */;
14508 else if (attr_form_is_block (attr
))
14510 struct dwarf2_locexpr_baton
*dlbaton
;
14512 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14513 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14514 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14515 dlbaton
->per_cu
= cu
->per_cu
;
14517 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14519 else if (attr_form_is_ref (attr
))
14521 struct dwarf2_cu
*target_cu
= cu
;
14522 struct die_info
*target_die
;
14524 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14525 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14526 if (die_is_declaration (target_die
, target_cu
))
14528 const char *target_physname
;
14530 /* Prefer the mangled name; otherwise compute the demangled one. */
14531 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14532 if (target_physname
== NULL
)
14533 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14534 if (target_physname
== NULL
)
14535 complaint (&symfile_complaints
,
14536 _("DW_AT_call_target target DIE has invalid "
14537 "physname, for referencing DIE %s [in module %s]"),
14538 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14540 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14546 /* DW_AT_entry_pc should be preferred. */
14547 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14548 <= PC_BOUNDS_INVALID
)
14549 complaint (&symfile_complaints
,
14550 _("DW_AT_call_target target DIE has invalid "
14551 "low pc, for referencing DIE %s [in module %s]"),
14552 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14555 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14556 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14561 complaint (&symfile_complaints
,
14562 _("DW_TAG_call_site DW_AT_call_target is neither "
14563 "block nor reference, for DIE %s [in module %s]"),
14564 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14566 call_site
->per_cu
= cu
->per_cu
;
14568 for (child_die
= die
->child
;
14569 child_die
&& child_die
->tag
;
14570 child_die
= sibling_die (child_die
))
14572 struct call_site_parameter
*parameter
;
14573 struct attribute
*loc
, *origin
;
14575 if (child_die
->tag
!= DW_TAG_call_site_parameter
14576 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14578 /* Already printed the complaint above. */
14582 gdb_assert (call_site
->parameter_count
< nparams
);
14583 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14585 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14586 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14587 register is contained in DW_AT_call_value. */
14589 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14590 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14591 if (origin
== NULL
)
14593 /* This was a pre-DWARF-5 GNU extension alias
14594 for DW_AT_call_parameter. */
14595 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14597 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14599 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14601 sect_offset sect_off
14602 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14603 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14605 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14606 binding can be done only inside one CU. Such referenced DIE
14607 therefore cannot be even moved to DW_TAG_partial_unit. */
14608 complaint (&symfile_complaints
,
14609 _("DW_AT_call_parameter offset is not in CU for "
14610 "DW_TAG_call_site child DIE %s [in module %s]"),
14611 sect_offset_str (child_die
->sect_off
),
14612 objfile_name (objfile
));
14615 parameter
->u
.param_cu_off
14616 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14618 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14620 complaint (&symfile_complaints
,
14621 _("No DW_FORM_block* DW_AT_location for "
14622 "DW_TAG_call_site child DIE %s [in module %s]"),
14623 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14628 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14629 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14630 if (parameter
->u
.dwarf_reg
!= -1)
14631 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14632 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14633 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14634 ¶meter
->u
.fb_offset
))
14635 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14638 complaint (&symfile_complaints
,
14639 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14640 "for DW_FORM_block* DW_AT_location is supported for "
14641 "DW_TAG_call_site child DIE %s "
14643 sect_offset_str (child_die
->sect_off
),
14644 objfile_name (objfile
));
14649 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14651 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14652 if (!attr_form_is_block (attr
))
14654 complaint (&symfile_complaints
,
14655 _("No DW_FORM_block* DW_AT_call_value for "
14656 "DW_TAG_call_site child DIE %s [in module %s]"),
14657 sect_offset_str (child_die
->sect_off
),
14658 objfile_name (objfile
));
14661 parameter
->value
= DW_BLOCK (attr
)->data
;
14662 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14664 /* Parameters are not pre-cleared by memset above. */
14665 parameter
->data_value
= NULL
;
14666 parameter
->data_value_size
= 0;
14667 call_site
->parameter_count
++;
14669 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14671 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14674 if (!attr_form_is_block (attr
))
14675 complaint (&symfile_complaints
,
14676 _("No DW_FORM_block* DW_AT_call_data_value for "
14677 "DW_TAG_call_site child DIE %s [in module %s]"),
14678 sect_offset_str (child_die
->sect_off
),
14679 objfile_name (objfile
));
14682 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14683 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14689 /* Helper function for read_variable. If DIE represents a virtual
14690 table, then return the type of the concrete object that is
14691 associated with the virtual table. Otherwise, return NULL. */
14693 static struct type
*
14694 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14696 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14700 /* Find the type DIE. */
14701 struct die_info
*type_die
= NULL
;
14702 struct dwarf2_cu
*type_cu
= cu
;
14704 if (attr_form_is_ref (attr
))
14705 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14706 if (type_die
== NULL
)
14709 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14711 return die_containing_type (type_die
, type_cu
);
14714 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14717 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14719 struct rust_vtable_symbol
*storage
= NULL
;
14721 if (cu
->language
== language_rust
)
14723 struct type
*containing_type
= rust_containing_type (die
, cu
);
14725 if (containing_type
!= NULL
)
14727 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14729 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14730 struct rust_vtable_symbol
);
14731 initialize_objfile_symbol (storage
);
14732 storage
->concrete_type
= containing_type
;
14733 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14737 new_symbol (die
, NULL
, cu
, storage
);
14740 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14741 reading .debug_rnglists.
14742 Callback's type should be:
14743 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14744 Return true if the attributes are present and valid, otherwise,
14747 template <typename Callback
>
14749 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14750 Callback
&&callback
)
14752 struct dwarf2_per_objfile
*dwarf2_per_objfile
14753 = cu
->per_cu
->dwarf2_per_objfile
;
14754 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14755 bfd
*obfd
= objfile
->obfd
;
14756 /* Base address selection entry. */
14759 const gdb_byte
*buffer
;
14760 CORE_ADDR baseaddr
;
14761 bool overflow
= false;
14763 found_base
= cu
->base_known
;
14764 base
= cu
->base_address
;
14766 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14767 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14769 complaint (&symfile_complaints
,
14770 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14774 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14776 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14780 /* Initialize it due to a false compiler warning. */
14781 CORE_ADDR range_beginning
= 0, range_end
= 0;
14782 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14783 + dwarf2_per_objfile
->rnglists
.size
);
14784 unsigned int bytes_read
;
14786 if (buffer
== buf_end
)
14791 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14794 case DW_RLE_end_of_list
:
14796 case DW_RLE_base_address
:
14797 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14802 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14804 buffer
+= bytes_read
;
14806 case DW_RLE_start_length
:
14807 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14812 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14813 buffer
+= bytes_read
;
14814 range_end
= (range_beginning
14815 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14816 buffer
+= bytes_read
;
14817 if (buffer
> buf_end
)
14823 case DW_RLE_offset_pair
:
14824 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14825 buffer
+= bytes_read
;
14826 if (buffer
> buf_end
)
14831 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14832 buffer
+= bytes_read
;
14833 if (buffer
> buf_end
)
14839 case DW_RLE_start_end
:
14840 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14845 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14846 buffer
+= bytes_read
;
14847 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14848 buffer
+= bytes_read
;
14851 complaint (&symfile_complaints
,
14852 _("Invalid .debug_rnglists data (no base address)"));
14855 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14857 if (rlet
== DW_RLE_base_address
)
14862 /* We have no valid base address for the ranges
14864 complaint (&symfile_complaints
,
14865 _("Invalid .debug_rnglists data (no base address)"));
14869 if (range_beginning
> range_end
)
14871 /* Inverted range entries are invalid. */
14872 complaint (&symfile_complaints
,
14873 _("Invalid .debug_rnglists data (inverted range)"));
14877 /* Empty range entries have no effect. */
14878 if (range_beginning
== range_end
)
14881 range_beginning
+= base
;
14884 /* A not-uncommon case of bad debug info.
14885 Don't pollute the addrmap with bad data. */
14886 if (range_beginning
+ baseaddr
== 0
14887 && !dwarf2_per_objfile
->has_section_at_zero
)
14889 complaint (&symfile_complaints
,
14890 _(".debug_rnglists entry has start address of zero"
14891 " [in module %s]"), objfile_name (objfile
));
14895 callback (range_beginning
, range_end
);
14900 complaint (&symfile_complaints
,
14901 _("Offset %d is not terminated "
14902 "for DW_AT_ranges attribute"),
14910 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14911 Callback's type should be:
14912 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14913 Return 1 if the attributes are present and valid, otherwise, return 0. */
14915 template <typename Callback
>
14917 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14918 Callback
&&callback
)
14920 struct dwarf2_per_objfile
*dwarf2_per_objfile
14921 = cu
->per_cu
->dwarf2_per_objfile
;
14922 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14923 struct comp_unit_head
*cu_header
= &cu
->header
;
14924 bfd
*obfd
= objfile
->obfd
;
14925 unsigned int addr_size
= cu_header
->addr_size
;
14926 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14927 /* Base address selection entry. */
14930 unsigned int dummy
;
14931 const gdb_byte
*buffer
;
14932 CORE_ADDR baseaddr
;
14934 if (cu_header
->version
>= 5)
14935 return dwarf2_rnglists_process (offset
, cu
, callback
);
14937 found_base
= cu
->base_known
;
14938 base
= cu
->base_address
;
14940 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14941 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14943 complaint (&symfile_complaints
,
14944 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14948 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14950 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14954 CORE_ADDR range_beginning
, range_end
;
14956 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14957 buffer
+= addr_size
;
14958 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14959 buffer
+= addr_size
;
14960 offset
+= 2 * addr_size
;
14962 /* An end of list marker is a pair of zero addresses. */
14963 if (range_beginning
== 0 && range_end
== 0)
14964 /* Found the end of list entry. */
14967 /* Each base address selection entry is a pair of 2 values.
14968 The first is the largest possible address, the second is
14969 the base address. Check for a base address here. */
14970 if ((range_beginning
& mask
) == mask
)
14972 /* If we found the largest possible address, then we already
14973 have the base address in range_end. */
14981 /* We have no valid base address for the ranges
14983 complaint (&symfile_complaints
,
14984 _("Invalid .debug_ranges data (no base address)"));
14988 if (range_beginning
> range_end
)
14990 /* Inverted range entries are invalid. */
14991 complaint (&symfile_complaints
,
14992 _("Invalid .debug_ranges data (inverted range)"));
14996 /* Empty range entries have no effect. */
14997 if (range_beginning
== range_end
)
15000 range_beginning
+= base
;
15003 /* A not-uncommon case of bad debug info.
15004 Don't pollute the addrmap with bad data. */
15005 if (range_beginning
+ baseaddr
== 0
15006 && !dwarf2_per_objfile
->has_section_at_zero
)
15008 complaint (&symfile_complaints
,
15009 _(".debug_ranges entry has start address of zero"
15010 " [in module %s]"), objfile_name (objfile
));
15014 callback (range_beginning
, range_end
);
15020 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
15021 Return 1 if the attributes are present and valid, otherwise, return 0.
15022 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
15025 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
15026 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
15027 struct partial_symtab
*ranges_pst
)
15029 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15030 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15031 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
15032 SECT_OFF_TEXT (objfile
));
15035 CORE_ADDR high
= 0;
15038 retval
= dwarf2_ranges_process (offset
, cu
,
15039 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
15041 if (ranges_pst
!= NULL
)
15046 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
15047 range_beginning
+ baseaddr
);
15048 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
15049 range_end
+ baseaddr
);
15050 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
15054 /* FIXME: This is recording everything as a low-high
15055 segment of consecutive addresses. We should have a
15056 data structure for discontiguous block ranges
15060 low
= range_beginning
;
15066 if (range_beginning
< low
)
15067 low
= range_beginning
;
15068 if (range_end
> high
)
15076 /* If the first entry is an end-of-list marker, the range
15077 describes an empty scope, i.e. no instructions. */
15083 *high_return
= high
;
15087 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
15088 definition for the return value. *LOWPC and *HIGHPC are set iff
15089 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
15091 static enum pc_bounds_kind
15092 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
15093 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
15094 struct partial_symtab
*pst
)
15096 struct dwarf2_per_objfile
*dwarf2_per_objfile
15097 = cu
->per_cu
->dwarf2_per_objfile
;
15098 struct attribute
*attr
;
15099 struct attribute
*attr_high
;
15101 CORE_ADDR high
= 0;
15102 enum pc_bounds_kind ret
;
15104 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
15107 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15110 low
= attr_value_as_address (attr
);
15111 high
= attr_value_as_address (attr_high
);
15112 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
15116 /* Found high w/o low attribute. */
15117 return PC_BOUNDS_INVALID
;
15119 /* Found consecutive range of addresses. */
15120 ret
= PC_BOUNDS_HIGH_LOW
;
15124 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
15127 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
15128 We take advantage of the fact that DW_AT_ranges does not appear
15129 in DW_TAG_compile_unit of DWO files. */
15130 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
15131 unsigned int ranges_offset
= (DW_UNSND (attr
)
15132 + (need_ranges_base
15136 /* Value of the DW_AT_ranges attribute is the offset in the
15137 .debug_ranges section. */
15138 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
15139 return PC_BOUNDS_INVALID
;
15140 /* Found discontinuous range of addresses. */
15141 ret
= PC_BOUNDS_RANGES
;
15144 return PC_BOUNDS_NOT_PRESENT
;
15147 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
15149 return PC_BOUNDS_INVALID
;
15151 /* When using the GNU linker, .gnu.linkonce. sections are used to
15152 eliminate duplicate copies of functions and vtables and such.
15153 The linker will arbitrarily choose one and discard the others.
15154 The AT_*_pc values for such functions refer to local labels in
15155 these sections. If the section from that file was discarded, the
15156 labels are not in the output, so the relocs get a value of 0.
15157 If this is a discarded function, mark the pc bounds as invalid,
15158 so that GDB will ignore it. */
15159 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15160 return PC_BOUNDS_INVALID
;
15168 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
15169 its low and high PC addresses. Do nothing if these addresses could not
15170 be determined. Otherwise, set LOWPC to the low address if it is smaller,
15171 and HIGHPC to the high address if greater than HIGHPC. */
15174 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
15175 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
15176 struct dwarf2_cu
*cu
)
15178 CORE_ADDR low
, high
;
15179 struct die_info
*child
= die
->child
;
15181 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
15183 *lowpc
= std::min (*lowpc
, low
);
15184 *highpc
= std::max (*highpc
, high
);
15187 /* If the language does not allow nested subprograms (either inside
15188 subprograms or lexical blocks), we're done. */
15189 if (cu
->language
!= language_ada
)
15192 /* Check all the children of the given DIE. If it contains nested
15193 subprograms, then check their pc bounds. Likewise, we need to
15194 check lexical blocks as well, as they may also contain subprogram
15196 while (child
&& child
->tag
)
15198 if (child
->tag
== DW_TAG_subprogram
15199 || child
->tag
== DW_TAG_lexical_block
)
15200 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
15201 child
= sibling_die (child
);
15205 /* Get the low and high pc's represented by the scope DIE, and store
15206 them in *LOWPC and *HIGHPC. If the correct values can't be
15207 determined, set *LOWPC to -1 and *HIGHPC to 0. */
15210 get_scope_pc_bounds (struct die_info
*die
,
15211 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
15212 struct dwarf2_cu
*cu
)
15214 CORE_ADDR best_low
= (CORE_ADDR
) -1;
15215 CORE_ADDR best_high
= (CORE_ADDR
) 0;
15216 CORE_ADDR current_low
, current_high
;
15218 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
15219 >= PC_BOUNDS_RANGES
)
15221 best_low
= current_low
;
15222 best_high
= current_high
;
15226 struct die_info
*child
= die
->child
;
15228 while (child
&& child
->tag
)
15230 switch (child
->tag
) {
15231 case DW_TAG_subprogram
:
15232 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
15234 case DW_TAG_namespace
:
15235 case DW_TAG_module
:
15236 /* FIXME: carlton/2004-01-16: Should we do this for
15237 DW_TAG_class_type/DW_TAG_structure_type, too? I think
15238 that current GCC's always emit the DIEs corresponding
15239 to definitions of methods of classes as children of a
15240 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
15241 the DIEs giving the declarations, which could be
15242 anywhere). But I don't see any reason why the
15243 standards says that they have to be there. */
15244 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
15246 if (current_low
!= ((CORE_ADDR
) -1))
15248 best_low
= std::min (best_low
, current_low
);
15249 best_high
= std::max (best_high
, current_high
);
15257 child
= sibling_die (child
);
15262 *highpc
= best_high
;
15265 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
15269 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
15270 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
15272 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15273 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15274 struct attribute
*attr
;
15275 struct attribute
*attr_high
;
15277 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
15280 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15283 CORE_ADDR low
= attr_value_as_address (attr
);
15284 CORE_ADDR high
= attr_value_as_address (attr_high
);
15286 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
15289 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
15290 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
15291 record_block_range (block
, low
, high
- 1);
15295 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
15298 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
15299 We take advantage of the fact that DW_AT_ranges does not appear
15300 in DW_TAG_compile_unit of DWO files. */
15301 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
15303 /* The value of the DW_AT_ranges attribute is the offset of the
15304 address range list in the .debug_ranges section. */
15305 unsigned long offset
= (DW_UNSND (attr
)
15306 + (need_ranges_base
? cu
->ranges_base
: 0));
15307 const gdb_byte
*buffer
;
15309 /* For some target architectures, but not others, the
15310 read_address function sign-extends the addresses it returns.
15311 To recognize base address selection entries, we need a
15313 unsigned int addr_size
= cu
->header
.addr_size
;
15314 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
15316 /* The base address, to which the next pair is relative. Note
15317 that this 'base' is a DWARF concept: most entries in a range
15318 list are relative, to reduce the number of relocs against the
15319 debugging information. This is separate from this function's
15320 'baseaddr' argument, which GDB uses to relocate debugging
15321 information from a shared library based on the address at
15322 which the library was loaded. */
15323 CORE_ADDR base
= cu
->base_address
;
15324 int base_known
= cu
->base_known
;
15326 dwarf2_ranges_process (offset
, cu
,
15327 [&] (CORE_ADDR start
, CORE_ADDR end
)
15331 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
15332 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
15333 record_block_range (block
, start
, end
- 1);
15338 /* Check whether the producer field indicates either of GCC < 4.6, or the
15339 Intel C/C++ compiler, and cache the result in CU. */
15342 check_producer (struct dwarf2_cu
*cu
)
15346 if (cu
->producer
== NULL
)
15348 /* For unknown compilers expect their behavior is DWARF version
15351 GCC started to support .debug_types sections by -gdwarf-4 since
15352 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
15353 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
15354 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
15355 interpreted incorrectly by GDB now - GCC PR debug/48229. */
15357 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
15359 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
15360 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
15362 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
15363 cu
->producer_is_icc_lt_14
= major
< 14;
15366 /* For other non-GCC compilers, expect their behavior is DWARF version
15370 cu
->checked_producer
= 1;
15373 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
15374 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
15375 during 4.6.0 experimental. */
15378 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
15380 if (!cu
->checked_producer
)
15381 check_producer (cu
);
15383 return cu
->producer_is_gxx_lt_4_6
;
15386 /* Return the default accessibility type if it is not overriden by
15387 DW_AT_accessibility. */
15389 static enum dwarf_access_attribute
15390 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
15392 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15394 /* The default DWARF 2 accessibility for members is public, the default
15395 accessibility for inheritance is private. */
15397 if (die
->tag
!= DW_TAG_inheritance
)
15398 return DW_ACCESS_public
;
15400 return DW_ACCESS_private
;
15404 /* DWARF 3+ defines the default accessibility a different way. The same
15405 rules apply now for DW_TAG_inheritance as for the members and it only
15406 depends on the container kind. */
15408 if (die
->parent
->tag
== DW_TAG_class_type
)
15409 return DW_ACCESS_private
;
15411 return DW_ACCESS_public
;
15415 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15416 offset. If the attribute was not found return 0, otherwise return
15417 1. If it was found but could not properly be handled, set *OFFSET
15421 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15424 struct attribute
*attr
;
15426 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15431 /* Note that we do not check for a section offset first here.
15432 This is because DW_AT_data_member_location is new in DWARF 4,
15433 so if we see it, we can assume that a constant form is really
15434 a constant and not a section offset. */
15435 if (attr_form_is_constant (attr
))
15436 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15437 else if (attr_form_is_section_offset (attr
))
15438 dwarf2_complex_location_expr_complaint ();
15439 else if (attr_form_is_block (attr
))
15440 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15442 dwarf2_complex_location_expr_complaint ();
15450 /* Add an aggregate field to the field list. */
15453 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15454 struct dwarf2_cu
*cu
)
15456 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15457 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15458 struct nextfield
*new_field
;
15459 struct attribute
*attr
;
15461 const char *fieldname
= "";
15463 if (die
->tag
== DW_TAG_inheritance
)
15465 fip
->baseclasses
.emplace_back ();
15466 new_field
= &fip
->baseclasses
.back ();
15470 fip
->fields
.emplace_back ();
15471 new_field
= &fip
->fields
.back ();
15476 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15478 new_field
->accessibility
= DW_UNSND (attr
);
15480 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15481 if (new_field
->accessibility
!= DW_ACCESS_public
)
15482 fip
->non_public_fields
= 1;
15484 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15486 new_field
->virtuality
= DW_UNSND (attr
);
15488 new_field
->virtuality
= DW_VIRTUALITY_none
;
15490 fp
= &new_field
->field
;
15492 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15496 /* Data member other than a C++ static data member. */
15498 /* Get type of field. */
15499 fp
->type
= die_type (die
, cu
);
15501 SET_FIELD_BITPOS (*fp
, 0);
15503 /* Get bit size of field (zero if none). */
15504 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15507 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15511 FIELD_BITSIZE (*fp
) = 0;
15514 /* Get bit offset of field. */
15515 if (handle_data_member_location (die
, cu
, &offset
))
15516 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15517 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15520 if (gdbarch_bits_big_endian (gdbarch
))
15522 /* For big endian bits, the DW_AT_bit_offset gives the
15523 additional bit offset from the MSB of the containing
15524 anonymous object to the MSB of the field. We don't
15525 have to do anything special since we don't need to
15526 know the size of the anonymous object. */
15527 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15531 /* For little endian bits, compute the bit offset to the
15532 MSB of the anonymous object, subtract off the number of
15533 bits from the MSB of the field to the MSB of the
15534 object, and then subtract off the number of bits of
15535 the field itself. The result is the bit offset of
15536 the LSB of the field. */
15537 int anonymous_size
;
15538 int bit_offset
= DW_UNSND (attr
);
15540 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15543 /* The size of the anonymous object containing
15544 the bit field is explicit, so use the
15545 indicated size (in bytes). */
15546 anonymous_size
= DW_UNSND (attr
);
15550 /* The size of the anonymous object containing
15551 the bit field must be inferred from the type
15552 attribute of the data member containing the
15554 anonymous_size
= TYPE_LENGTH (fp
->type
);
15556 SET_FIELD_BITPOS (*fp
,
15557 (FIELD_BITPOS (*fp
)
15558 + anonymous_size
* bits_per_byte
15559 - bit_offset
- FIELD_BITSIZE (*fp
)));
15562 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15564 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15565 + dwarf2_get_attr_constant_value (attr
, 0)));
15567 /* Get name of field. */
15568 fieldname
= dwarf2_name (die
, cu
);
15569 if (fieldname
== NULL
)
15572 /* The name is already allocated along with this objfile, so we don't
15573 need to duplicate it for the type. */
15574 fp
->name
= fieldname
;
15576 /* Change accessibility for artificial fields (e.g. virtual table
15577 pointer or virtual base class pointer) to private. */
15578 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15580 FIELD_ARTIFICIAL (*fp
) = 1;
15581 new_field
->accessibility
= DW_ACCESS_private
;
15582 fip
->non_public_fields
= 1;
15585 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15587 /* C++ static member. */
15589 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15590 is a declaration, but all versions of G++ as of this writing
15591 (so through at least 3.2.1) incorrectly generate
15592 DW_TAG_variable tags. */
15594 const char *physname
;
15596 /* Get name of field. */
15597 fieldname
= dwarf2_name (die
, cu
);
15598 if (fieldname
== NULL
)
15601 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15603 /* Only create a symbol if this is an external value.
15604 new_symbol checks this and puts the value in the global symbol
15605 table, which we want. If it is not external, new_symbol
15606 will try to put the value in cu->list_in_scope which is wrong. */
15607 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15609 /* A static const member, not much different than an enum as far as
15610 we're concerned, except that we can support more types. */
15611 new_symbol (die
, NULL
, cu
);
15614 /* Get physical name. */
15615 physname
= dwarf2_physname (fieldname
, die
, cu
);
15617 /* The name is already allocated along with this objfile, so we don't
15618 need to duplicate it for the type. */
15619 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15620 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15621 FIELD_NAME (*fp
) = fieldname
;
15623 else if (die
->tag
== DW_TAG_inheritance
)
15627 /* C++ base class field. */
15628 if (handle_data_member_location (die
, cu
, &offset
))
15629 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15630 FIELD_BITSIZE (*fp
) = 0;
15631 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15632 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15634 else if (die
->tag
== DW_TAG_variant_part
)
15636 /* process_structure_scope will treat this DIE as a union. */
15637 process_structure_scope (die
, cu
);
15639 /* The variant part is relative to the start of the enclosing
15641 SET_FIELD_BITPOS (*fp
, 0);
15642 fp
->type
= get_die_type (die
, cu
);
15643 fp
->artificial
= 1;
15644 fp
->name
= "<<variant>>";
15647 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15650 /* Can the type given by DIE define another type? */
15653 type_can_define_types (const struct die_info
*die
)
15657 case DW_TAG_typedef
:
15658 case DW_TAG_class_type
:
15659 case DW_TAG_structure_type
:
15660 case DW_TAG_union_type
:
15661 case DW_TAG_enumeration_type
:
15669 /* Add a type definition defined in the scope of the FIP's class. */
15672 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15673 struct dwarf2_cu
*cu
)
15675 struct decl_field fp
;
15676 memset (&fp
, 0, sizeof (fp
));
15678 gdb_assert (type_can_define_types (die
));
15680 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15681 fp
.name
= dwarf2_name (die
, cu
);
15682 fp
.type
= read_type_die (die
, cu
);
15684 /* Save accessibility. */
15685 enum dwarf_access_attribute accessibility
;
15686 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15688 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15690 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15691 switch (accessibility
)
15693 case DW_ACCESS_public
:
15694 /* The assumed value if neither private nor protected. */
15696 case DW_ACCESS_private
:
15699 case DW_ACCESS_protected
:
15700 fp
.is_protected
= 1;
15703 complaint (&symfile_complaints
,
15704 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15707 if (die
->tag
== DW_TAG_typedef
)
15708 fip
->typedef_field_list
.push_back (fp
);
15710 fip
->nested_types_list
.push_back (fp
);
15713 /* Create the vector of fields, and attach it to the type. */
15716 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15717 struct dwarf2_cu
*cu
)
15719 int nfields
= fip
->nfields
;
15721 /* Record the field count, allocate space for the array of fields,
15722 and create blank accessibility bitfields if necessary. */
15723 TYPE_NFIELDS (type
) = nfields
;
15724 TYPE_FIELDS (type
) = (struct field
*)
15725 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15727 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15729 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15731 TYPE_FIELD_PRIVATE_BITS (type
) =
15732 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15733 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15735 TYPE_FIELD_PROTECTED_BITS (type
) =
15736 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15737 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15739 TYPE_FIELD_IGNORE_BITS (type
) =
15740 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15741 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15744 /* If the type has baseclasses, allocate and clear a bit vector for
15745 TYPE_FIELD_VIRTUAL_BITS. */
15746 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15748 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15749 unsigned char *pointer
;
15751 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15752 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15753 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15754 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15755 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15758 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15760 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15762 for (int index
= 0; index
< nfields
; ++index
)
15764 struct nextfield
&field
= fip
->fields
[index
];
15766 if (field
.variant
.is_discriminant
)
15767 di
->discriminant_index
= index
;
15768 else if (field
.variant
.default_branch
)
15769 di
->default_index
= index
;
15771 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15775 /* Copy the saved-up fields into the field vector. */
15776 for (int i
= 0; i
< nfields
; ++i
)
15778 struct nextfield
&field
15779 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15780 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15782 TYPE_FIELD (type
, i
) = field
.field
;
15783 switch (field
.accessibility
)
15785 case DW_ACCESS_private
:
15786 if (cu
->language
!= language_ada
)
15787 SET_TYPE_FIELD_PRIVATE (type
, i
);
15790 case DW_ACCESS_protected
:
15791 if (cu
->language
!= language_ada
)
15792 SET_TYPE_FIELD_PROTECTED (type
, i
);
15795 case DW_ACCESS_public
:
15799 /* Unknown accessibility. Complain and treat it as public. */
15801 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15802 field
.accessibility
);
15806 if (i
< fip
->baseclasses
.size ())
15808 switch (field
.virtuality
)
15810 case DW_VIRTUALITY_virtual
:
15811 case DW_VIRTUALITY_pure_virtual
:
15812 if (cu
->language
== language_ada
)
15813 error (_("unexpected virtuality in component of Ada type"));
15814 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15821 /* Return true if this member function is a constructor, false
15825 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15827 const char *fieldname
;
15828 const char *type_name
;
15831 if (die
->parent
== NULL
)
15834 if (die
->parent
->tag
!= DW_TAG_structure_type
15835 && die
->parent
->tag
!= DW_TAG_union_type
15836 && die
->parent
->tag
!= DW_TAG_class_type
)
15839 fieldname
= dwarf2_name (die
, cu
);
15840 type_name
= dwarf2_name (die
->parent
, cu
);
15841 if (fieldname
== NULL
|| type_name
== NULL
)
15844 len
= strlen (fieldname
);
15845 return (strncmp (fieldname
, type_name
, len
) == 0
15846 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15849 /* Add a member function to the proper fieldlist. */
15852 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15853 struct type
*type
, struct dwarf2_cu
*cu
)
15855 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15856 struct attribute
*attr
;
15858 struct fnfieldlist
*flp
= nullptr;
15859 struct fn_field
*fnp
;
15860 const char *fieldname
;
15861 struct type
*this_type
;
15862 enum dwarf_access_attribute accessibility
;
15864 if (cu
->language
== language_ada
)
15865 error (_("unexpected member function in Ada type"));
15867 /* Get name of member function. */
15868 fieldname
= dwarf2_name (die
, cu
);
15869 if (fieldname
== NULL
)
15872 /* Look up member function name in fieldlist. */
15873 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15875 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15877 flp
= &fip
->fnfieldlists
[i
];
15882 /* Create a new fnfieldlist if necessary. */
15883 if (flp
== nullptr)
15885 fip
->fnfieldlists
.emplace_back ();
15886 flp
= &fip
->fnfieldlists
.back ();
15887 flp
->name
= fieldname
;
15888 i
= fip
->fnfieldlists
.size () - 1;
15891 /* Create a new member function field and add it to the vector of
15893 flp
->fnfields
.emplace_back ();
15894 fnp
= &flp
->fnfields
.back ();
15896 /* Delay processing of the physname until later. */
15897 if (cu
->language
== language_cplus
)
15898 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15902 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15903 fnp
->physname
= physname
? physname
: "";
15906 fnp
->type
= alloc_type (objfile
);
15907 this_type
= read_type_die (die
, cu
);
15908 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15910 int nparams
= TYPE_NFIELDS (this_type
);
15912 /* TYPE is the domain of this method, and THIS_TYPE is the type
15913 of the method itself (TYPE_CODE_METHOD). */
15914 smash_to_method_type (fnp
->type
, type
,
15915 TYPE_TARGET_TYPE (this_type
),
15916 TYPE_FIELDS (this_type
),
15917 TYPE_NFIELDS (this_type
),
15918 TYPE_VARARGS (this_type
));
15920 /* Handle static member functions.
15921 Dwarf2 has no clean way to discern C++ static and non-static
15922 member functions. G++ helps GDB by marking the first
15923 parameter for non-static member functions (which is the this
15924 pointer) as artificial. We obtain this information from
15925 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15926 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15927 fnp
->voffset
= VOFFSET_STATIC
;
15930 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15931 dwarf2_full_name (fieldname
, die
, cu
));
15933 /* Get fcontext from DW_AT_containing_type if present. */
15934 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15935 fnp
->fcontext
= die_containing_type (die
, cu
);
15937 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15938 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15940 /* Get accessibility. */
15941 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15943 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15945 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15946 switch (accessibility
)
15948 case DW_ACCESS_private
:
15949 fnp
->is_private
= 1;
15951 case DW_ACCESS_protected
:
15952 fnp
->is_protected
= 1;
15956 /* Check for artificial methods. */
15957 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15958 if (attr
&& DW_UNSND (attr
) != 0)
15959 fnp
->is_artificial
= 1;
15961 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15963 /* Get index in virtual function table if it is a virtual member
15964 function. For older versions of GCC, this is an offset in the
15965 appropriate virtual table, as specified by DW_AT_containing_type.
15966 For everyone else, it is an expression to be evaluated relative
15967 to the object address. */
15969 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15972 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15974 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15976 /* Old-style GCC. */
15977 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15979 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15980 || (DW_BLOCK (attr
)->size
> 1
15981 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15982 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15984 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15985 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15986 dwarf2_complex_location_expr_complaint ();
15988 fnp
->voffset
/= cu
->header
.addr_size
;
15992 dwarf2_complex_location_expr_complaint ();
15994 if (!fnp
->fcontext
)
15996 /* If there is no `this' field and no DW_AT_containing_type,
15997 we cannot actually find a base class context for the
15999 if (TYPE_NFIELDS (this_type
) == 0
16000 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
16002 complaint (&symfile_complaints
,
16003 _("cannot determine context for virtual member "
16004 "function \"%s\" (offset %s)"),
16005 fieldname
, sect_offset_str (die
->sect_off
));
16010 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
16014 else if (attr_form_is_section_offset (attr
))
16016 dwarf2_complex_location_expr_complaint ();
16020 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
16026 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
16027 if (attr
&& DW_UNSND (attr
))
16029 /* GCC does this, as of 2008-08-25; PR debug/37237. */
16030 complaint (&symfile_complaints
,
16031 _("Member function \"%s\" (offset %s) is virtual "
16032 "but the vtable offset is not specified"),
16033 fieldname
, sect_offset_str (die
->sect_off
));
16034 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16035 TYPE_CPLUS_DYNAMIC (type
) = 1;
16040 /* Create the vector of member function fields, and attach it to the type. */
16043 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
16044 struct dwarf2_cu
*cu
)
16046 if (cu
->language
== language_ada
)
16047 error (_("unexpected member functions in Ada type"));
16049 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16050 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
16052 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
16054 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
16056 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
16057 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
16059 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
16060 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
16061 fn_flp
->fn_fields
= (struct fn_field
*)
16062 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
16064 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
16065 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
16068 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
16071 /* Returns non-zero if NAME is the name of a vtable member in CU's
16072 language, zero otherwise. */
16074 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
16076 static const char vptr
[] = "_vptr";
16078 /* Look for the C++ form of the vtable. */
16079 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
16085 /* GCC outputs unnamed structures that are really pointers to member
16086 functions, with the ABI-specified layout. If TYPE describes
16087 such a structure, smash it into a member function type.
16089 GCC shouldn't do this; it should just output pointer to member DIEs.
16090 This is GCC PR debug/28767. */
16093 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
16095 struct type
*pfn_type
, *self_type
, *new_type
;
16097 /* Check for a structure with no name and two children. */
16098 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
16101 /* Check for __pfn and __delta members. */
16102 if (TYPE_FIELD_NAME (type
, 0) == NULL
16103 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
16104 || TYPE_FIELD_NAME (type
, 1) == NULL
16105 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
16108 /* Find the type of the method. */
16109 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
16110 if (pfn_type
== NULL
16111 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
16112 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
16115 /* Look for the "this" argument. */
16116 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
16117 if (TYPE_NFIELDS (pfn_type
) == 0
16118 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
16119 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
16122 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
16123 new_type
= alloc_type (objfile
);
16124 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
16125 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
16126 TYPE_VARARGS (pfn_type
));
16127 smash_to_methodptr_type (type
, new_type
);
16131 /* Called when we find the DIE that starts a structure or union scope
16132 (definition) to create a type for the structure or union. Fill in
16133 the type's name and general properties; the members will not be
16134 processed until process_structure_scope. A symbol table entry for
16135 the type will also not be done until process_structure_scope (assuming
16136 the type has a name).
16138 NOTE: we need to call these functions regardless of whether or not the
16139 DIE has a DW_AT_name attribute, since it might be an anonymous
16140 structure or union. This gets the type entered into our set of
16141 user defined types. */
16143 static struct type
*
16144 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16146 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16148 struct attribute
*attr
;
16151 /* If the definition of this type lives in .debug_types, read that type.
16152 Don't follow DW_AT_specification though, that will take us back up
16153 the chain and we want to go down. */
16154 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16157 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16159 /* The type's CU may not be the same as CU.
16160 Ensure TYPE is recorded with CU in die_type_hash. */
16161 return set_die_type (die
, type
, cu
);
16164 type
= alloc_type (objfile
);
16165 INIT_CPLUS_SPECIFIC (type
);
16167 name
= dwarf2_name (die
, cu
);
16170 if (cu
->language
== language_cplus
16171 || cu
->language
== language_d
16172 || cu
->language
== language_rust
)
16174 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16176 /* dwarf2_full_name might have already finished building the DIE's
16177 type. If so, there is no need to continue. */
16178 if (get_die_type (die
, cu
) != NULL
)
16179 return get_die_type (die
, cu
);
16181 TYPE_TAG_NAME (type
) = full_name
;
16182 if (die
->tag
== DW_TAG_structure_type
16183 || die
->tag
== DW_TAG_class_type
)
16184 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
16188 /* The name is already allocated along with this objfile, so
16189 we don't need to duplicate it for the type. */
16190 TYPE_TAG_NAME (type
) = name
;
16191 if (die
->tag
== DW_TAG_class_type
)
16192 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
16196 if (die
->tag
== DW_TAG_structure_type
)
16198 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16200 else if (die
->tag
== DW_TAG_union_type
)
16202 TYPE_CODE (type
) = TYPE_CODE_UNION
;
16204 else if (die
->tag
== DW_TAG_variant_part
)
16206 TYPE_CODE (type
) = TYPE_CODE_UNION
;
16207 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
16211 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16214 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16215 TYPE_DECLARED_CLASS (type
) = 1;
16217 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16220 if (attr_form_is_constant (attr
))
16221 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16224 /* For the moment, dynamic type sizes are not supported
16225 by GDB's struct type. The actual size is determined
16226 on-demand when resolving the type of a given object,
16227 so set the type's length to zero for now. Otherwise,
16228 we record an expression as the length, and that expression
16229 could lead to a very large value, which could eventually
16230 lead to us trying to allocate that much memory when creating
16231 a value of that type. */
16232 TYPE_LENGTH (type
) = 0;
16237 TYPE_LENGTH (type
) = 0;
16240 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16242 /* ICC<14 does not output the required DW_AT_declaration on
16243 incomplete types, but gives them a size of zero. */
16244 TYPE_STUB (type
) = 1;
16247 TYPE_STUB_SUPPORTED (type
) = 1;
16249 if (die_is_declaration (die
, cu
))
16250 TYPE_STUB (type
) = 1;
16251 else if (attr
== NULL
&& die
->child
== NULL
16252 && producer_is_realview (cu
->producer
))
16253 /* RealView does not output the required DW_AT_declaration
16254 on incomplete types. */
16255 TYPE_STUB (type
) = 1;
16257 /* We need to add the type field to the die immediately so we don't
16258 infinitely recurse when dealing with pointers to the structure
16259 type within the structure itself. */
16260 set_die_type (die
, type
, cu
);
16262 /* set_die_type should be already done. */
16263 set_descriptive_type (type
, die
, cu
);
16268 /* A helper for process_structure_scope that handles a single member
16272 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16273 struct field_info
*fi
,
16274 std::vector
<struct symbol
*> *template_args
,
16275 struct dwarf2_cu
*cu
)
16277 if (child_die
->tag
== DW_TAG_member
16278 || child_die
->tag
== DW_TAG_variable
16279 || child_die
->tag
== DW_TAG_variant_part
)
16281 /* NOTE: carlton/2002-11-05: A C++ static data member
16282 should be a DW_TAG_member that is a declaration, but
16283 all versions of G++ as of this writing (so through at
16284 least 3.2.1) incorrectly generate DW_TAG_variable
16285 tags for them instead. */
16286 dwarf2_add_field (fi
, child_die
, cu
);
16288 else if (child_die
->tag
== DW_TAG_subprogram
)
16290 /* Rust doesn't have member functions in the C++ sense.
16291 However, it does emit ordinary functions as children
16292 of a struct DIE. */
16293 if (cu
->language
== language_rust
)
16294 read_func_scope (child_die
, cu
);
16297 /* C++ member function. */
16298 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16301 else if (child_die
->tag
== DW_TAG_inheritance
)
16303 /* C++ base class field. */
16304 dwarf2_add_field (fi
, child_die
, cu
);
16306 else if (type_can_define_types (child_die
))
16307 dwarf2_add_type_defn (fi
, child_die
, cu
);
16308 else if (child_die
->tag
== DW_TAG_template_type_param
16309 || child_die
->tag
== DW_TAG_template_value_param
)
16311 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16314 template_args
->push_back (arg
);
16316 else if (child_die
->tag
== DW_TAG_variant
)
16318 /* In a variant we want to get the discriminant and also add a
16319 field for our sole member child. */
16320 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16322 for (struct die_info
*variant_child
= child_die
->child
;
16323 variant_child
!= NULL
;
16324 variant_child
= sibling_die (variant_child
))
16326 if (variant_child
->tag
== DW_TAG_member
)
16328 handle_struct_member_die (variant_child
, type
, fi
,
16329 template_args
, cu
);
16330 /* Only handle the one. */
16335 /* We don't handle this but we might as well report it if we see
16337 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16338 complaint (&symfile_complaints
,
16339 _("DW_AT_discr_list is not supported yet"
16340 " - DIE at %s [in module %s]"),
16341 sect_offset_str (child_die
->sect_off
),
16342 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16344 /* The first field was just added, so we can stash the
16345 discriminant there. */
16346 gdb_assert (!fi
->fields
.empty ());
16348 fi
->fields
.back ().variant
.default_branch
= true;
16350 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16354 /* Finish creating a structure or union type, including filling in
16355 its members and creating a symbol for it. */
16358 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16360 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16361 struct die_info
*child_die
;
16364 type
= get_die_type (die
, cu
);
16366 type
= read_structure_type (die
, cu
);
16368 /* When reading a DW_TAG_variant_part, we need to notice when we
16369 read the discriminant member, so we can record it later in the
16370 discriminant_info. */
16371 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16372 sect_offset discr_offset
;
16374 if (is_variant_part
)
16376 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16379 /* Maybe it's a univariant form, an extension we support.
16380 In this case arrange not to check the offset. */
16381 is_variant_part
= false;
16383 else if (attr_form_is_ref (discr
))
16385 struct dwarf2_cu
*target_cu
= cu
;
16386 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16388 discr_offset
= target_die
->sect_off
;
16392 complaint (&symfile_complaints
,
16393 _("DW_AT_discr does not have DIE reference form"
16394 " - DIE at %s [in module %s]"),
16395 sect_offset_str (die
->sect_off
),
16396 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16397 is_variant_part
= false;
16401 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16403 struct field_info fi
;
16404 std::vector
<struct symbol
*> template_args
;
16406 child_die
= die
->child
;
16408 while (child_die
&& child_die
->tag
)
16410 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16412 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16413 fi
.fields
.back ().variant
.is_discriminant
= true;
16415 child_die
= sibling_die (child_die
);
16418 /* Attach template arguments to type. */
16419 if (!template_args
.empty ())
16421 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16422 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16423 TYPE_TEMPLATE_ARGUMENTS (type
)
16424 = XOBNEWVEC (&objfile
->objfile_obstack
,
16426 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16427 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16428 template_args
.data (),
16429 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16430 * sizeof (struct symbol
*)));
16433 /* Attach fields and member functions to the type. */
16435 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16436 if (!fi
.fnfieldlists
.empty ())
16438 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16440 /* Get the type which refers to the base class (possibly this
16441 class itself) which contains the vtable pointer for the current
16442 class from the DW_AT_containing_type attribute. This use of
16443 DW_AT_containing_type is a GNU extension. */
16445 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16447 struct type
*t
= die_containing_type (die
, cu
);
16449 set_type_vptr_basetype (type
, t
);
16454 /* Our own class provides vtbl ptr. */
16455 for (i
= TYPE_NFIELDS (t
) - 1;
16456 i
>= TYPE_N_BASECLASSES (t
);
16459 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16461 if (is_vtable_name (fieldname
, cu
))
16463 set_type_vptr_fieldno (type
, i
);
16468 /* Complain if virtual function table field not found. */
16469 if (i
< TYPE_N_BASECLASSES (t
))
16470 complaint (&symfile_complaints
,
16471 _("virtual function table pointer "
16472 "not found when defining class '%s'"),
16473 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16478 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16481 else if (cu
->producer
16482 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16484 /* The IBM XLC compiler does not provide direct indication
16485 of the containing type, but the vtable pointer is
16486 always named __vfp. */
16490 for (i
= TYPE_NFIELDS (type
) - 1;
16491 i
>= TYPE_N_BASECLASSES (type
);
16494 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16496 set_type_vptr_fieldno (type
, i
);
16497 set_type_vptr_basetype (type
, type
);
16504 /* Copy fi.typedef_field_list linked list elements content into the
16505 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16506 if (!fi
.typedef_field_list
.empty ())
16508 int count
= fi
.typedef_field_list
.size ();
16510 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16511 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16512 = ((struct decl_field
*)
16514 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16515 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16517 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16518 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16521 /* Copy fi.nested_types_list linked list elements content into the
16522 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16523 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16525 int count
= fi
.nested_types_list
.size ();
16527 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16528 TYPE_NESTED_TYPES_ARRAY (type
)
16529 = ((struct decl_field
*)
16530 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16531 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16533 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16534 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16538 quirk_gcc_member_function_pointer (type
, objfile
);
16539 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16540 cu
->rust_unions
.push_back (type
);
16542 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16543 snapshots) has been known to create a die giving a declaration
16544 for a class that has, as a child, a die giving a definition for a
16545 nested class. So we have to process our children even if the
16546 current die is a declaration. Normally, of course, a declaration
16547 won't have any children at all. */
16549 child_die
= die
->child
;
16551 while (child_die
!= NULL
&& child_die
->tag
)
16553 if (child_die
->tag
== DW_TAG_member
16554 || child_die
->tag
== DW_TAG_variable
16555 || child_die
->tag
== DW_TAG_inheritance
16556 || child_die
->tag
== DW_TAG_template_value_param
16557 || child_die
->tag
== DW_TAG_template_type_param
)
16562 process_die (child_die
, cu
);
16564 child_die
= sibling_die (child_die
);
16567 /* Do not consider external references. According to the DWARF standard,
16568 these DIEs are identified by the fact that they have no byte_size
16569 attribute, and a declaration attribute. */
16570 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16571 || !die_is_declaration (die
, cu
))
16572 new_symbol (die
, type
, cu
);
16575 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16576 update TYPE using some information only available in DIE's children. */
16579 update_enumeration_type_from_children (struct die_info
*die
,
16581 struct dwarf2_cu
*cu
)
16583 struct die_info
*child_die
;
16584 int unsigned_enum
= 1;
16588 auto_obstack obstack
;
16590 for (child_die
= die
->child
;
16591 child_die
!= NULL
&& child_die
->tag
;
16592 child_die
= sibling_die (child_die
))
16594 struct attribute
*attr
;
16596 const gdb_byte
*bytes
;
16597 struct dwarf2_locexpr_baton
*baton
;
16600 if (child_die
->tag
!= DW_TAG_enumerator
)
16603 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16607 name
= dwarf2_name (child_die
, cu
);
16609 name
= "<anonymous enumerator>";
16611 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16612 &value
, &bytes
, &baton
);
16618 else if ((mask
& value
) != 0)
16623 /* If we already know that the enum type is neither unsigned, nor
16624 a flag type, no need to look at the rest of the enumerates. */
16625 if (!unsigned_enum
&& !flag_enum
)
16630 TYPE_UNSIGNED (type
) = 1;
16632 TYPE_FLAG_ENUM (type
) = 1;
16635 /* Given a DW_AT_enumeration_type die, set its type. We do not
16636 complete the type's fields yet, or create any symbols. */
16638 static struct type
*
16639 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16641 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16643 struct attribute
*attr
;
16646 /* If the definition of this type lives in .debug_types, read that type.
16647 Don't follow DW_AT_specification though, that will take us back up
16648 the chain and we want to go down. */
16649 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16652 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16654 /* The type's CU may not be the same as CU.
16655 Ensure TYPE is recorded with CU in die_type_hash. */
16656 return set_die_type (die
, type
, cu
);
16659 type
= alloc_type (objfile
);
16661 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16662 name
= dwarf2_full_name (NULL
, die
, cu
);
16664 TYPE_TAG_NAME (type
) = name
;
16666 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16669 struct type
*underlying_type
= die_type (die
, cu
);
16671 TYPE_TARGET_TYPE (type
) = underlying_type
;
16674 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16677 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16681 TYPE_LENGTH (type
) = 0;
16684 /* The enumeration DIE can be incomplete. In Ada, any type can be
16685 declared as private in the package spec, and then defined only
16686 inside the package body. Such types are known as Taft Amendment
16687 Types. When another package uses such a type, an incomplete DIE
16688 may be generated by the compiler. */
16689 if (die_is_declaration (die
, cu
))
16690 TYPE_STUB (type
) = 1;
16692 /* Finish the creation of this type by using the enum's children.
16693 We must call this even when the underlying type has been provided
16694 so that we can determine if we're looking at a "flag" enum. */
16695 update_enumeration_type_from_children (die
, type
, cu
);
16697 /* If this type has an underlying type that is not a stub, then we
16698 may use its attributes. We always use the "unsigned" attribute
16699 in this situation, because ordinarily we guess whether the type
16700 is unsigned -- but the guess can be wrong and the underlying type
16701 can tell us the reality. However, we defer to a local size
16702 attribute if one exists, because this lets the compiler override
16703 the underlying type if needed. */
16704 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16706 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16707 if (TYPE_LENGTH (type
) == 0)
16708 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16711 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16713 return set_die_type (die
, type
, cu
);
16716 /* Given a pointer to a die which begins an enumeration, process all
16717 the dies that define the members of the enumeration, and create the
16718 symbol for the enumeration type.
16720 NOTE: We reverse the order of the element list. */
16723 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16725 struct type
*this_type
;
16727 this_type
= get_die_type (die
, cu
);
16728 if (this_type
== NULL
)
16729 this_type
= read_enumeration_type (die
, cu
);
16731 if (die
->child
!= NULL
)
16733 struct die_info
*child_die
;
16734 struct symbol
*sym
;
16735 struct field
*fields
= NULL
;
16736 int num_fields
= 0;
16739 child_die
= die
->child
;
16740 while (child_die
&& child_die
->tag
)
16742 if (child_die
->tag
!= DW_TAG_enumerator
)
16744 process_die (child_die
, cu
);
16748 name
= dwarf2_name (child_die
, cu
);
16751 sym
= new_symbol (child_die
, this_type
, cu
);
16753 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16755 fields
= (struct field
*)
16757 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16758 * sizeof (struct field
));
16761 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16762 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16763 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16764 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16770 child_die
= sibling_die (child_die
);
16775 TYPE_NFIELDS (this_type
) = num_fields
;
16776 TYPE_FIELDS (this_type
) = (struct field
*)
16777 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16778 memcpy (TYPE_FIELDS (this_type
), fields
,
16779 sizeof (struct field
) * num_fields
);
16784 /* If we are reading an enum from a .debug_types unit, and the enum
16785 is a declaration, and the enum is not the signatured type in the
16786 unit, then we do not want to add a symbol for it. Adding a
16787 symbol would in some cases obscure the true definition of the
16788 enum, giving users an incomplete type when the definition is
16789 actually available. Note that we do not want to do this for all
16790 enums which are just declarations, because C++0x allows forward
16791 enum declarations. */
16792 if (cu
->per_cu
->is_debug_types
16793 && die_is_declaration (die
, cu
))
16795 struct signatured_type
*sig_type
;
16797 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16798 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16799 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16803 new_symbol (die
, this_type
, cu
);
16806 /* Extract all information from a DW_TAG_array_type DIE and put it in
16807 the DIE's type field. For now, this only handles one dimensional
16810 static struct type
*
16811 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16813 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16814 struct die_info
*child_die
;
16816 struct type
*element_type
, *range_type
, *index_type
;
16817 struct attribute
*attr
;
16819 struct dynamic_prop
*byte_stride_prop
= NULL
;
16820 unsigned int bit_stride
= 0;
16822 element_type
= die_type (die
, cu
);
16824 /* The die_type call above may have already set the type for this DIE. */
16825 type
= get_die_type (die
, cu
);
16829 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16835 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16836 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16839 complaint (&symfile_complaints
,
16840 _("unable to read array DW_AT_byte_stride "
16841 " - DIE at %s [in module %s]"),
16842 sect_offset_str (die
->sect_off
),
16843 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16844 /* Ignore this attribute. We will likely not be able to print
16845 arrays of this type correctly, but there is little we can do
16846 to help if we cannot read the attribute's value. */
16847 byte_stride_prop
= NULL
;
16851 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16853 bit_stride
= DW_UNSND (attr
);
16855 /* Irix 6.2 native cc creates array types without children for
16856 arrays with unspecified length. */
16857 if (die
->child
== NULL
)
16859 index_type
= objfile_type (objfile
)->builtin_int
;
16860 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16861 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16862 byte_stride_prop
, bit_stride
);
16863 return set_die_type (die
, type
, cu
);
16866 std::vector
<struct type
*> range_types
;
16867 child_die
= die
->child
;
16868 while (child_die
&& child_die
->tag
)
16870 if (child_die
->tag
== DW_TAG_subrange_type
)
16872 struct type
*child_type
= read_type_die (child_die
, cu
);
16874 if (child_type
!= NULL
)
16876 /* The range type was succesfully read. Save it for the
16877 array type creation. */
16878 range_types
.push_back (child_type
);
16881 child_die
= sibling_die (child_die
);
16884 /* Dwarf2 dimensions are output from left to right, create the
16885 necessary array types in backwards order. */
16887 type
= element_type
;
16889 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16893 while (i
< range_types
.size ())
16894 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16895 byte_stride_prop
, bit_stride
);
16899 size_t ndim
= range_types
.size ();
16901 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16902 byte_stride_prop
, bit_stride
);
16905 /* Understand Dwarf2 support for vector types (like they occur on
16906 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16907 array type. This is not part of the Dwarf2/3 standard yet, but a
16908 custom vendor extension. The main difference between a regular
16909 array and the vector variant is that vectors are passed by value
16911 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16913 make_vector_type (type
);
16915 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16916 implementation may choose to implement triple vectors using this
16918 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16921 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16922 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16924 complaint (&symfile_complaints
,
16925 _("DW_AT_byte_size for array type smaller "
16926 "than the total size of elements"));
16929 name
= dwarf2_name (die
, cu
);
16931 TYPE_NAME (type
) = name
;
16933 /* Install the type in the die. */
16934 set_die_type (die
, type
, cu
);
16936 /* set_die_type should be already done. */
16937 set_descriptive_type (type
, die
, cu
);
16942 static enum dwarf_array_dim_ordering
16943 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16945 struct attribute
*attr
;
16947 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16950 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16952 /* GNU F77 is a special case, as at 08/2004 array type info is the
16953 opposite order to the dwarf2 specification, but data is still
16954 laid out as per normal fortran.
16956 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16957 version checking. */
16959 if (cu
->language
== language_fortran
16960 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16962 return DW_ORD_row_major
;
16965 switch (cu
->language_defn
->la_array_ordering
)
16967 case array_column_major
:
16968 return DW_ORD_col_major
;
16969 case array_row_major
:
16971 return DW_ORD_row_major
;
16975 /* Extract all information from a DW_TAG_set_type DIE and put it in
16976 the DIE's type field. */
16978 static struct type
*
16979 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16981 struct type
*domain_type
, *set_type
;
16982 struct attribute
*attr
;
16984 domain_type
= die_type (die
, cu
);
16986 /* The die_type call above may have already set the type for this DIE. */
16987 set_type
= get_die_type (die
, cu
);
16991 set_type
= create_set_type (NULL
, domain_type
);
16993 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16995 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16997 return set_die_type (die
, set_type
, cu
);
17000 /* A helper for read_common_block that creates a locexpr baton.
17001 SYM is the symbol which we are marking as computed.
17002 COMMON_DIE is the DIE for the common block.
17003 COMMON_LOC is the location expression attribute for the common
17005 MEMBER_LOC is the location expression attribute for the particular
17006 member of the common block that we are processing.
17007 CU is the CU from which the above come. */
17010 mark_common_block_symbol_computed (struct symbol
*sym
,
17011 struct die_info
*common_die
,
17012 struct attribute
*common_loc
,
17013 struct attribute
*member_loc
,
17014 struct dwarf2_cu
*cu
)
17016 struct dwarf2_per_objfile
*dwarf2_per_objfile
17017 = cu
->per_cu
->dwarf2_per_objfile
;
17018 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17019 struct dwarf2_locexpr_baton
*baton
;
17021 unsigned int cu_off
;
17022 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
17023 LONGEST offset
= 0;
17025 gdb_assert (common_loc
&& member_loc
);
17026 gdb_assert (attr_form_is_block (common_loc
));
17027 gdb_assert (attr_form_is_block (member_loc
)
17028 || attr_form_is_constant (member_loc
));
17030 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17031 baton
->per_cu
= cu
->per_cu
;
17032 gdb_assert (baton
->per_cu
);
17034 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17036 if (attr_form_is_constant (member_loc
))
17038 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
17039 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17042 baton
->size
+= DW_BLOCK (member_loc
)->size
;
17044 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17047 *ptr
++ = DW_OP_call4
;
17048 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17049 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17052 if (attr_form_is_constant (member_loc
))
17054 *ptr
++ = DW_OP_addr
;
17055 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17056 ptr
+= cu
->header
.addr_size
;
17060 /* We have to copy the data here, because DW_OP_call4 will only
17061 use a DW_AT_location attribute. */
17062 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
17063 ptr
+= DW_BLOCK (member_loc
)->size
;
17066 *ptr
++ = DW_OP_plus
;
17067 gdb_assert (ptr
- baton
->data
== baton
->size
);
17069 SYMBOL_LOCATION_BATON (sym
) = baton
;
17070 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17073 /* Create appropriate locally-scoped variables for all the
17074 DW_TAG_common_block entries. Also create a struct common_block
17075 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17076 is used to sepate the common blocks name namespace from regular
17080 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17082 struct attribute
*attr
;
17084 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17087 /* Support the .debug_loc offsets. */
17088 if (attr_form_is_block (attr
))
17092 else if (attr_form_is_section_offset (attr
))
17094 dwarf2_complex_location_expr_complaint ();
17099 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17100 "common block member");
17105 if (die
->child
!= NULL
)
17107 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17108 struct die_info
*child_die
;
17109 size_t n_entries
= 0, size
;
17110 struct common_block
*common_block
;
17111 struct symbol
*sym
;
17113 for (child_die
= die
->child
;
17114 child_die
&& child_die
->tag
;
17115 child_die
= sibling_die (child_die
))
17118 size
= (sizeof (struct common_block
)
17119 + (n_entries
- 1) * sizeof (struct symbol
*));
17121 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17123 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17124 common_block
->n_entries
= 0;
17126 for (child_die
= die
->child
;
17127 child_die
&& child_die
->tag
;
17128 child_die
= sibling_die (child_die
))
17130 /* Create the symbol in the DW_TAG_common_block block in the current
17132 sym
= new_symbol (child_die
, NULL
, cu
);
17135 struct attribute
*member_loc
;
17137 common_block
->contents
[common_block
->n_entries
++] = sym
;
17139 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17143 /* GDB has handled this for a long time, but it is
17144 not specified by DWARF. It seems to have been
17145 emitted by gfortran at least as recently as:
17146 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17147 complaint (&symfile_complaints
,
17148 _("Variable in common block has "
17149 "DW_AT_data_member_location "
17150 "- DIE at %s [in module %s]"),
17151 sect_offset_str (child_die
->sect_off
),
17152 objfile_name (objfile
));
17154 if (attr_form_is_section_offset (member_loc
))
17155 dwarf2_complex_location_expr_complaint ();
17156 else if (attr_form_is_constant (member_loc
)
17157 || attr_form_is_block (member_loc
))
17160 mark_common_block_symbol_computed (sym
, die
, attr
,
17164 dwarf2_complex_location_expr_complaint ();
17169 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17170 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17174 /* Create a type for a C++ namespace. */
17176 static struct type
*
17177 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17179 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17180 const char *previous_prefix
, *name
;
17184 /* For extensions, reuse the type of the original namespace. */
17185 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17187 struct die_info
*ext_die
;
17188 struct dwarf2_cu
*ext_cu
= cu
;
17190 ext_die
= dwarf2_extension (die
, &ext_cu
);
17191 type
= read_type_die (ext_die
, ext_cu
);
17193 /* EXT_CU may not be the same as CU.
17194 Ensure TYPE is recorded with CU in die_type_hash. */
17195 return set_die_type (die
, type
, cu
);
17198 name
= namespace_name (die
, &is_anonymous
, cu
);
17200 /* Now build the name of the current namespace. */
17202 previous_prefix
= determine_prefix (die
, cu
);
17203 if (previous_prefix
[0] != '\0')
17204 name
= typename_concat (&objfile
->objfile_obstack
,
17205 previous_prefix
, name
, 0, cu
);
17207 /* Create the type. */
17208 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17209 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
17211 return set_die_type (die
, type
, cu
);
17214 /* Read a namespace scope. */
17217 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17219 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17222 /* Add a symbol associated to this if we haven't seen the namespace
17223 before. Also, add a using directive if it's an anonymous
17226 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17230 type
= read_type_die (die
, cu
);
17231 new_symbol (die
, type
, cu
);
17233 namespace_name (die
, &is_anonymous
, cu
);
17236 const char *previous_prefix
= determine_prefix (die
, cu
);
17238 std::vector
<const char *> excludes
;
17239 add_using_directive (using_directives (cu
->language
),
17240 previous_prefix
, TYPE_NAME (type
), NULL
,
17241 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17245 if (die
->child
!= NULL
)
17247 struct die_info
*child_die
= die
->child
;
17249 while (child_die
&& child_die
->tag
)
17251 process_die (child_die
, cu
);
17252 child_die
= sibling_die (child_die
);
17257 /* Read a Fortran module as type. This DIE can be only a declaration used for
17258 imported module. Still we need that type as local Fortran "use ... only"
17259 declaration imports depend on the created type in determine_prefix. */
17261 static struct type
*
17262 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17264 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17265 const char *module_name
;
17268 module_name
= dwarf2_name (die
, cu
);
17270 complaint (&symfile_complaints
,
17271 _("DW_TAG_module has no name, offset %s"),
17272 sect_offset_str (die
->sect_off
));
17273 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17275 /* determine_prefix uses TYPE_TAG_NAME. */
17276 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
17278 return set_die_type (die
, type
, cu
);
17281 /* Read a Fortran module. */
17284 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17286 struct die_info
*child_die
= die
->child
;
17289 type
= read_type_die (die
, cu
);
17290 new_symbol (die
, type
, cu
);
17292 while (child_die
&& child_die
->tag
)
17294 process_die (child_die
, cu
);
17295 child_die
= sibling_die (child_die
);
17299 /* Return the name of the namespace represented by DIE. Set
17300 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17303 static const char *
17304 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17306 struct die_info
*current_die
;
17307 const char *name
= NULL
;
17309 /* Loop through the extensions until we find a name. */
17311 for (current_die
= die
;
17312 current_die
!= NULL
;
17313 current_die
= dwarf2_extension (die
, &cu
))
17315 /* We don't use dwarf2_name here so that we can detect the absence
17316 of a name -> anonymous namespace. */
17317 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17323 /* Is it an anonymous namespace? */
17325 *is_anonymous
= (name
== NULL
);
17327 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17332 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17333 the user defined type vector. */
17335 static struct type
*
17336 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17338 struct gdbarch
*gdbarch
17339 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17340 struct comp_unit_head
*cu_header
= &cu
->header
;
17342 struct attribute
*attr_byte_size
;
17343 struct attribute
*attr_address_class
;
17344 int byte_size
, addr_class
;
17345 struct type
*target_type
;
17347 target_type
= die_type (die
, cu
);
17349 /* The die_type call above may have already set the type for this DIE. */
17350 type
= get_die_type (die
, cu
);
17354 type
= lookup_pointer_type (target_type
);
17356 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17357 if (attr_byte_size
)
17358 byte_size
= DW_UNSND (attr_byte_size
);
17360 byte_size
= cu_header
->addr_size
;
17362 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17363 if (attr_address_class
)
17364 addr_class
= DW_UNSND (attr_address_class
);
17366 addr_class
= DW_ADDR_none
;
17368 /* If the pointer size or address class is different than the
17369 default, create a type variant marked as such and set the
17370 length accordingly. */
17371 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
17373 if (gdbarch_address_class_type_flags_p (gdbarch
))
17377 type_flags
= gdbarch_address_class_type_flags
17378 (gdbarch
, byte_size
, addr_class
);
17379 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17381 type
= make_type_with_address_space (type
, type_flags
);
17383 else if (TYPE_LENGTH (type
) != byte_size
)
17385 complaint (&symfile_complaints
,
17386 _("invalid pointer size %d"), byte_size
);
17390 /* Should we also complain about unhandled address classes? */
17394 TYPE_LENGTH (type
) = byte_size
;
17395 return set_die_type (die
, type
, cu
);
17398 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17399 the user defined type vector. */
17401 static struct type
*
17402 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17405 struct type
*to_type
;
17406 struct type
*domain
;
17408 to_type
= die_type (die
, cu
);
17409 domain
= die_containing_type (die
, cu
);
17411 /* The calls above may have already set the type for this DIE. */
17412 type
= get_die_type (die
, cu
);
17416 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17417 type
= lookup_methodptr_type (to_type
);
17418 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17420 struct type
*new_type
17421 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17423 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17424 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17425 TYPE_VARARGS (to_type
));
17426 type
= lookup_methodptr_type (new_type
);
17429 type
= lookup_memberptr_type (to_type
, domain
);
17431 return set_die_type (die
, type
, cu
);
17434 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17435 the user defined type vector. */
17437 static struct type
*
17438 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17439 enum type_code refcode
)
17441 struct comp_unit_head
*cu_header
= &cu
->header
;
17442 struct type
*type
, *target_type
;
17443 struct attribute
*attr
;
17445 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17447 target_type
= die_type (die
, cu
);
17449 /* The die_type call above may have already set the type for this DIE. */
17450 type
= get_die_type (die
, cu
);
17454 type
= lookup_reference_type (target_type
, refcode
);
17455 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17458 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17462 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17464 return set_die_type (die
, type
, cu
);
17467 /* Add the given cv-qualifiers to the element type of the array. GCC
17468 outputs DWARF type qualifiers that apply to an array, not the
17469 element type. But GDB relies on the array element type to carry
17470 the cv-qualifiers. This mimics section 6.7.3 of the C99
17473 static struct type
*
17474 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17475 struct type
*base_type
, int cnst
, int voltl
)
17477 struct type
*el_type
, *inner_array
;
17479 base_type
= copy_type (base_type
);
17480 inner_array
= base_type
;
17482 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17484 TYPE_TARGET_TYPE (inner_array
) =
17485 copy_type (TYPE_TARGET_TYPE (inner_array
));
17486 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17489 el_type
= TYPE_TARGET_TYPE (inner_array
);
17490 cnst
|= TYPE_CONST (el_type
);
17491 voltl
|= TYPE_VOLATILE (el_type
);
17492 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17494 return set_die_type (die
, base_type
, cu
);
17497 static struct type
*
17498 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17500 struct type
*base_type
, *cv_type
;
17502 base_type
= die_type (die
, cu
);
17504 /* The die_type call above may have already set the type for this DIE. */
17505 cv_type
= get_die_type (die
, cu
);
17509 /* In case the const qualifier is applied to an array type, the element type
17510 is so qualified, not the array type (section 6.7.3 of C99). */
17511 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17512 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17514 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17515 return set_die_type (die
, cv_type
, cu
);
17518 static struct type
*
17519 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17521 struct type
*base_type
, *cv_type
;
17523 base_type
= die_type (die
, cu
);
17525 /* The die_type call above may have already set the type for this DIE. */
17526 cv_type
= get_die_type (die
, cu
);
17530 /* In case the volatile qualifier is applied to an array type, the
17531 element type is so qualified, not the array type (section 6.7.3
17533 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17534 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17536 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17537 return set_die_type (die
, cv_type
, cu
);
17540 /* Handle DW_TAG_restrict_type. */
17542 static struct type
*
17543 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17545 struct type
*base_type
, *cv_type
;
17547 base_type
= die_type (die
, cu
);
17549 /* The die_type call above may have already set the type for this DIE. */
17550 cv_type
= get_die_type (die
, cu
);
17554 cv_type
= make_restrict_type (base_type
);
17555 return set_die_type (die
, cv_type
, cu
);
17558 /* Handle DW_TAG_atomic_type. */
17560 static struct type
*
17561 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17563 struct type
*base_type
, *cv_type
;
17565 base_type
= die_type (die
, cu
);
17567 /* The die_type call above may have already set the type for this DIE. */
17568 cv_type
= get_die_type (die
, cu
);
17572 cv_type
= make_atomic_type (base_type
);
17573 return set_die_type (die
, cv_type
, cu
);
17576 /* Extract all information from a DW_TAG_string_type DIE and add to
17577 the user defined type vector. It isn't really a user defined type,
17578 but it behaves like one, with other DIE's using an AT_user_def_type
17579 attribute to reference it. */
17581 static struct type
*
17582 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17584 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17585 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17586 struct type
*type
, *range_type
, *index_type
, *char_type
;
17587 struct attribute
*attr
;
17588 unsigned int length
;
17590 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17593 length
= DW_UNSND (attr
);
17597 /* Check for the DW_AT_byte_size attribute. */
17598 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17601 length
= DW_UNSND (attr
);
17609 index_type
= objfile_type (objfile
)->builtin_int
;
17610 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17611 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17612 type
= create_string_type (NULL
, char_type
, range_type
);
17614 return set_die_type (die
, type
, cu
);
17617 /* Assuming that DIE corresponds to a function, returns nonzero
17618 if the function is prototyped. */
17621 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17623 struct attribute
*attr
;
17625 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17626 if (attr
&& (DW_UNSND (attr
) != 0))
17629 /* The DWARF standard implies that the DW_AT_prototyped attribute
17630 is only meaninful for C, but the concept also extends to other
17631 languages that allow unprototyped functions (Eg: Objective C).
17632 For all other languages, assume that functions are always
17634 if (cu
->language
!= language_c
17635 && cu
->language
!= language_objc
17636 && cu
->language
!= language_opencl
)
17639 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17640 prototyped and unprototyped functions; default to prototyped,
17641 since that is more common in modern code (and RealView warns
17642 about unprototyped functions). */
17643 if (producer_is_realview (cu
->producer
))
17649 /* Handle DIES due to C code like:
17653 int (*funcp)(int a, long l);
17657 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17659 static struct type
*
17660 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17662 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17663 struct type
*type
; /* Type that this function returns. */
17664 struct type
*ftype
; /* Function that returns above type. */
17665 struct attribute
*attr
;
17667 type
= die_type (die
, cu
);
17669 /* The die_type call above may have already set the type for this DIE. */
17670 ftype
= get_die_type (die
, cu
);
17674 ftype
= lookup_function_type (type
);
17676 if (prototyped_function_p (die
, cu
))
17677 TYPE_PROTOTYPED (ftype
) = 1;
17679 /* Store the calling convention in the type if it's available in
17680 the subroutine die. Otherwise set the calling convention to
17681 the default value DW_CC_normal. */
17682 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17684 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17685 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17686 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17688 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17690 /* Record whether the function returns normally to its caller or not
17691 if the DWARF producer set that information. */
17692 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17693 if (attr
&& (DW_UNSND (attr
) != 0))
17694 TYPE_NO_RETURN (ftype
) = 1;
17696 /* We need to add the subroutine type to the die immediately so
17697 we don't infinitely recurse when dealing with parameters
17698 declared as the same subroutine type. */
17699 set_die_type (die
, ftype
, cu
);
17701 if (die
->child
!= NULL
)
17703 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17704 struct die_info
*child_die
;
17705 int nparams
, iparams
;
17707 /* Count the number of parameters.
17708 FIXME: GDB currently ignores vararg functions, but knows about
17709 vararg member functions. */
17711 child_die
= die
->child
;
17712 while (child_die
&& child_die
->tag
)
17714 if (child_die
->tag
== DW_TAG_formal_parameter
)
17716 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17717 TYPE_VARARGS (ftype
) = 1;
17718 child_die
= sibling_die (child_die
);
17721 /* Allocate storage for parameters and fill them in. */
17722 TYPE_NFIELDS (ftype
) = nparams
;
17723 TYPE_FIELDS (ftype
) = (struct field
*)
17724 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17726 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17727 even if we error out during the parameters reading below. */
17728 for (iparams
= 0; iparams
< nparams
; iparams
++)
17729 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17732 child_die
= die
->child
;
17733 while (child_die
&& child_die
->tag
)
17735 if (child_die
->tag
== DW_TAG_formal_parameter
)
17737 struct type
*arg_type
;
17739 /* DWARF version 2 has no clean way to discern C++
17740 static and non-static member functions. G++ helps
17741 GDB by marking the first parameter for non-static
17742 member functions (which is the this pointer) as
17743 artificial. We pass this information to
17744 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17746 DWARF version 3 added DW_AT_object_pointer, which GCC
17747 4.5 does not yet generate. */
17748 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17750 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17752 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17753 arg_type
= die_type (child_die
, cu
);
17755 /* RealView does not mark THIS as const, which the testsuite
17756 expects. GCC marks THIS as const in method definitions,
17757 but not in the class specifications (GCC PR 43053). */
17758 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17759 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17762 struct dwarf2_cu
*arg_cu
= cu
;
17763 const char *name
= dwarf2_name (child_die
, cu
);
17765 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17768 /* If the compiler emits this, use it. */
17769 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17772 else if (name
&& strcmp (name
, "this") == 0)
17773 /* Function definitions will have the argument names. */
17775 else if (name
== NULL
&& iparams
== 0)
17776 /* Declarations may not have the names, so like
17777 elsewhere in GDB, assume an artificial first
17778 argument is "this". */
17782 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17786 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17789 child_die
= sibling_die (child_die
);
17796 static struct type
*
17797 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17799 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17800 const char *name
= NULL
;
17801 struct type
*this_type
, *target_type
;
17803 name
= dwarf2_full_name (NULL
, die
, cu
);
17804 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17805 TYPE_TARGET_STUB (this_type
) = 1;
17806 set_die_type (die
, this_type
, cu
);
17807 target_type
= die_type (die
, cu
);
17808 if (target_type
!= this_type
)
17809 TYPE_TARGET_TYPE (this_type
) = target_type
;
17812 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17813 spec and cause infinite loops in GDB. */
17814 complaint (&symfile_complaints
,
17815 _("Self-referential DW_TAG_typedef "
17816 "- DIE at %s [in module %s]"),
17817 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17818 TYPE_TARGET_TYPE (this_type
) = NULL
;
17823 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17824 (which may be different from NAME) to the architecture back-end to allow
17825 it to guess the correct format if necessary. */
17827 static struct type
*
17828 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17829 const char *name_hint
)
17831 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17832 const struct floatformat
**format
;
17835 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17837 type
= init_float_type (objfile
, bits
, name
, format
);
17839 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17844 /* Find a representation of a given base type and install
17845 it in the TYPE field of the die. */
17847 static struct type
*
17848 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17850 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17852 struct attribute
*attr
;
17853 int encoding
= 0, bits
= 0;
17856 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17859 encoding
= DW_UNSND (attr
);
17861 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17864 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17866 name
= dwarf2_name (die
, cu
);
17869 complaint (&symfile_complaints
,
17870 _("DW_AT_name missing from DW_TAG_base_type"));
17875 case DW_ATE_address
:
17876 /* Turn DW_ATE_address into a void * pointer. */
17877 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17878 type
= init_pointer_type (objfile
, bits
, name
, type
);
17880 case DW_ATE_boolean
:
17881 type
= init_boolean_type (objfile
, bits
, 1, name
);
17883 case DW_ATE_complex_float
:
17884 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17885 type
= init_complex_type (objfile
, name
, type
);
17887 case DW_ATE_decimal_float
:
17888 type
= init_decfloat_type (objfile
, bits
, name
);
17891 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17893 case DW_ATE_signed
:
17894 type
= init_integer_type (objfile
, bits
, 0, name
);
17896 case DW_ATE_unsigned
:
17897 if (cu
->language
== language_fortran
17899 && startswith (name
, "character("))
17900 type
= init_character_type (objfile
, bits
, 1, name
);
17902 type
= init_integer_type (objfile
, bits
, 1, name
);
17904 case DW_ATE_signed_char
:
17905 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17906 || cu
->language
== language_pascal
17907 || cu
->language
== language_fortran
)
17908 type
= init_character_type (objfile
, bits
, 0, name
);
17910 type
= init_integer_type (objfile
, bits
, 0, name
);
17912 case DW_ATE_unsigned_char
:
17913 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17914 || cu
->language
== language_pascal
17915 || cu
->language
== language_fortran
17916 || cu
->language
== language_rust
)
17917 type
= init_character_type (objfile
, bits
, 1, name
);
17919 type
= init_integer_type (objfile
, bits
, 1, name
);
17923 gdbarch
*arch
= get_objfile_arch (objfile
);
17926 type
= builtin_type (arch
)->builtin_char16
;
17927 else if (bits
== 32)
17928 type
= builtin_type (arch
)->builtin_char32
;
17931 complaint (&symfile_complaints
,
17932 _("unsupported DW_ATE_UTF bit size: '%d'"),
17934 type
= init_integer_type (objfile
, bits
, 1, name
);
17936 return set_die_type (die
, type
, cu
);
17941 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17942 dwarf_type_encoding_name (encoding
));
17943 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17947 if (name
&& strcmp (name
, "char") == 0)
17948 TYPE_NOSIGN (type
) = 1;
17950 return set_die_type (die
, type
, cu
);
17953 /* Parse dwarf attribute if it's a block, reference or constant and put the
17954 resulting value of the attribute into struct bound_prop.
17955 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17958 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17959 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17961 struct dwarf2_property_baton
*baton
;
17962 struct obstack
*obstack
17963 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17965 if (attr
== NULL
|| prop
== NULL
)
17968 if (attr_form_is_block (attr
))
17970 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17971 baton
->referenced_type
= NULL
;
17972 baton
->locexpr
.per_cu
= cu
->per_cu
;
17973 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17974 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17975 prop
->data
.baton
= baton
;
17976 prop
->kind
= PROP_LOCEXPR
;
17977 gdb_assert (prop
->data
.baton
!= NULL
);
17979 else if (attr_form_is_ref (attr
))
17981 struct dwarf2_cu
*target_cu
= cu
;
17982 struct die_info
*target_die
;
17983 struct attribute
*target_attr
;
17985 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17986 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17987 if (target_attr
== NULL
)
17988 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17990 if (target_attr
== NULL
)
17993 switch (target_attr
->name
)
17995 case DW_AT_location
:
17996 if (attr_form_is_section_offset (target_attr
))
17998 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17999 baton
->referenced_type
= die_type (target_die
, target_cu
);
18000 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18001 prop
->data
.baton
= baton
;
18002 prop
->kind
= PROP_LOCLIST
;
18003 gdb_assert (prop
->data
.baton
!= NULL
);
18005 else if (attr_form_is_block (target_attr
))
18007 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18008 baton
->referenced_type
= die_type (target_die
, target_cu
);
18009 baton
->locexpr
.per_cu
= cu
->per_cu
;
18010 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
18011 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
18012 prop
->data
.baton
= baton
;
18013 prop
->kind
= PROP_LOCEXPR
;
18014 gdb_assert (prop
->data
.baton
!= NULL
);
18018 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18019 "dynamic property");
18023 case DW_AT_data_member_location
:
18027 if (!handle_data_member_location (target_die
, target_cu
,
18031 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18032 baton
->referenced_type
= read_type_die (target_die
->parent
,
18034 baton
->offset_info
.offset
= offset
;
18035 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18036 prop
->data
.baton
= baton
;
18037 prop
->kind
= PROP_ADDR_OFFSET
;
18042 else if (attr_form_is_constant (attr
))
18044 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18045 prop
->kind
= PROP_CONST
;
18049 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18050 dwarf2_name (die
, cu
));
18057 /* Read the given DW_AT_subrange DIE. */
18059 static struct type
*
18060 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18062 struct type
*base_type
, *orig_base_type
;
18063 struct type
*range_type
;
18064 struct attribute
*attr
;
18065 struct dynamic_prop low
, high
;
18066 int low_default_is_valid
;
18067 int high_bound_is_count
= 0;
18069 LONGEST negative_mask
;
18071 orig_base_type
= die_type (die
, cu
);
18072 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18073 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18074 creating the range type, but we use the result of check_typedef
18075 when examining properties of the type. */
18076 base_type
= check_typedef (orig_base_type
);
18078 /* The die_type call above may have already set the type for this DIE. */
18079 range_type
= get_die_type (die
, cu
);
18083 low
.kind
= PROP_CONST
;
18084 high
.kind
= PROP_CONST
;
18085 high
.data
.const_val
= 0;
18087 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18088 omitting DW_AT_lower_bound. */
18089 switch (cu
->language
)
18092 case language_cplus
:
18093 low
.data
.const_val
= 0;
18094 low_default_is_valid
= 1;
18096 case language_fortran
:
18097 low
.data
.const_val
= 1;
18098 low_default_is_valid
= 1;
18101 case language_objc
:
18102 case language_rust
:
18103 low
.data
.const_val
= 0;
18104 low_default_is_valid
= (cu
->header
.version
>= 4);
18108 case language_pascal
:
18109 low
.data
.const_val
= 1;
18110 low_default_is_valid
= (cu
->header
.version
>= 4);
18113 low
.data
.const_val
= 0;
18114 low_default_is_valid
= 0;
18118 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18120 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
18121 else if (!low_default_is_valid
)
18122 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
18123 "- DIE at %s [in module %s]"),
18124 sect_offset_str (die
->sect_off
),
18125 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18127 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18128 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
18130 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
18131 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
18133 /* If bounds are constant do the final calculation here. */
18134 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18135 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18137 high_bound_is_count
= 1;
18141 /* Dwarf-2 specifications explicitly allows to create subrange types
18142 without specifying a base type.
18143 In that case, the base type must be set to the type of
18144 the lower bound, upper bound or count, in that order, if any of these
18145 three attributes references an object that has a type.
18146 If no base type is found, the Dwarf-2 specifications say that
18147 a signed integer type of size equal to the size of an address should
18149 For the following C code: `extern char gdb_int [];'
18150 GCC produces an empty range DIE.
18151 FIXME: muller/2010-05-28: Possible references to object for low bound,
18152 high bound or count are not yet handled by this code. */
18153 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
18155 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18156 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18157 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
18158 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
18160 /* Test "int", "long int", and "long long int" objfile types,
18161 and select the first one having a size above or equal to the
18162 architecture address size. */
18163 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18164 base_type
= int_type
;
18167 int_type
= objfile_type (objfile
)->builtin_long
;
18168 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18169 base_type
= int_type
;
18172 int_type
= objfile_type (objfile
)->builtin_long_long
;
18173 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18174 base_type
= int_type
;
18179 /* Normally, the DWARF producers are expected to use a signed
18180 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18181 But this is unfortunately not always the case, as witnessed
18182 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18183 is used instead. To work around that ambiguity, we treat
18184 the bounds as signed, and thus sign-extend their values, when
18185 the base type is signed. */
18187 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18188 if (low
.kind
== PROP_CONST
18189 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18190 low
.data
.const_val
|= negative_mask
;
18191 if (high
.kind
== PROP_CONST
18192 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18193 high
.data
.const_val
|= negative_mask
;
18195 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
18197 if (high_bound_is_count
)
18198 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18200 /* Ada expects an empty array on no boundary attributes. */
18201 if (attr
== NULL
&& cu
->language
!= language_ada
)
18202 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18204 name
= dwarf2_name (die
, cu
);
18206 TYPE_NAME (range_type
) = name
;
18208 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18210 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18212 set_die_type (die
, range_type
, cu
);
18214 /* set_die_type should be already done. */
18215 set_descriptive_type (range_type
, die
, cu
);
18220 static struct type
*
18221 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18225 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18227 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18229 /* In Ada, an unspecified type is typically used when the description
18230 of the type is defered to a different unit. When encountering
18231 such a type, we treat it as a stub, and try to resolve it later on,
18233 if (cu
->language
== language_ada
)
18234 TYPE_STUB (type
) = 1;
18236 return set_die_type (die
, type
, cu
);
18239 /* Read a single die and all its descendents. Set the die's sibling
18240 field to NULL; set other fields in the die correctly, and set all
18241 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18242 location of the info_ptr after reading all of those dies. PARENT
18243 is the parent of the die in question. */
18245 static struct die_info
*
18246 read_die_and_children (const struct die_reader_specs
*reader
,
18247 const gdb_byte
*info_ptr
,
18248 const gdb_byte
**new_info_ptr
,
18249 struct die_info
*parent
)
18251 struct die_info
*die
;
18252 const gdb_byte
*cur_ptr
;
18255 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18258 *new_info_ptr
= cur_ptr
;
18261 store_in_ref_table (die
, reader
->cu
);
18264 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18268 *new_info_ptr
= cur_ptr
;
18271 die
->sibling
= NULL
;
18272 die
->parent
= parent
;
18276 /* Read a die, all of its descendents, and all of its siblings; set
18277 all of the fields of all of the dies correctly. Arguments are as
18278 in read_die_and_children. */
18280 static struct die_info
*
18281 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18282 const gdb_byte
*info_ptr
,
18283 const gdb_byte
**new_info_ptr
,
18284 struct die_info
*parent
)
18286 struct die_info
*first_die
, *last_sibling
;
18287 const gdb_byte
*cur_ptr
;
18289 cur_ptr
= info_ptr
;
18290 first_die
= last_sibling
= NULL
;
18294 struct die_info
*die
18295 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18299 *new_info_ptr
= cur_ptr
;
18306 last_sibling
->sibling
= die
;
18308 last_sibling
= die
;
18312 /* Read a die, all of its descendents, and all of its siblings; set
18313 all of the fields of all of the dies correctly. Arguments are as
18314 in read_die_and_children.
18315 This the main entry point for reading a DIE and all its children. */
18317 static struct die_info
*
18318 read_die_and_siblings (const struct die_reader_specs
*reader
,
18319 const gdb_byte
*info_ptr
,
18320 const gdb_byte
**new_info_ptr
,
18321 struct die_info
*parent
)
18323 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18324 new_info_ptr
, parent
);
18326 if (dwarf_die_debug
)
18328 fprintf_unfiltered (gdb_stdlog
,
18329 "Read die from %s@0x%x of %s:\n",
18330 get_section_name (reader
->die_section
),
18331 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18332 bfd_get_filename (reader
->abfd
));
18333 dump_die (die
, dwarf_die_debug
);
18339 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18341 The caller is responsible for filling in the extra attributes
18342 and updating (*DIEP)->num_attrs.
18343 Set DIEP to point to a newly allocated die with its information,
18344 except for its child, sibling, and parent fields.
18345 Set HAS_CHILDREN to tell whether the die has children or not. */
18347 static const gdb_byte
*
18348 read_full_die_1 (const struct die_reader_specs
*reader
,
18349 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18350 int *has_children
, int num_extra_attrs
)
18352 unsigned int abbrev_number
, bytes_read
, i
;
18353 struct abbrev_info
*abbrev
;
18354 struct die_info
*die
;
18355 struct dwarf2_cu
*cu
= reader
->cu
;
18356 bfd
*abfd
= reader
->abfd
;
18358 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18359 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18360 info_ptr
+= bytes_read
;
18361 if (!abbrev_number
)
18368 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18370 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18372 bfd_get_filename (abfd
));
18374 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18375 die
->sect_off
= sect_off
;
18376 die
->tag
= abbrev
->tag
;
18377 die
->abbrev
= abbrev_number
;
18379 /* Make the result usable.
18380 The caller needs to update num_attrs after adding the extra
18382 die
->num_attrs
= abbrev
->num_attrs
;
18384 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18385 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18389 *has_children
= abbrev
->has_children
;
18393 /* Read a die and all its attributes.
18394 Set DIEP to point to a newly allocated die with its information,
18395 except for its child, sibling, and parent fields.
18396 Set HAS_CHILDREN to tell whether the die has children or not. */
18398 static const gdb_byte
*
18399 read_full_die (const struct die_reader_specs
*reader
,
18400 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18403 const gdb_byte
*result
;
18405 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18407 if (dwarf_die_debug
)
18409 fprintf_unfiltered (gdb_stdlog
,
18410 "Read die from %s@0x%x of %s:\n",
18411 get_section_name (reader
->die_section
),
18412 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18413 bfd_get_filename (reader
->abfd
));
18414 dump_die (*diep
, dwarf_die_debug
);
18420 /* Abbreviation tables.
18422 In DWARF version 2, the description of the debugging information is
18423 stored in a separate .debug_abbrev section. Before we read any
18424 dies from a section we read in all abbreviations and install them
18425 in a hash table. */
18427 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18429 struct abbrev_info
*
18430 abbrev_table::alloc_abbrev ()
18432 struct abbrev_info
*abbrev
;
18434 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18435 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18440 /* Add an abbreviation to the table. */
18443 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18444 struct abbrev_info
*abbrev
)
18446 unsigned int hash_number
;
18448 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18449 abbrev
->next
= m_abbrevs
[hash_number
];
18450 m_abbrevs
[hash_number
] = abbrev
;
18453 /* Look up an abbrev in the table.
18454 Returns NULL if the abbrev is not found. */
18456 struct abbrev_info
*
18457 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18459 unsigned int hash_number
;
18460 struct abbrev_info
*abbrev
;
18462 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18463 abbrev
= m_abbrevs
[hash_number
];
18467 if (abbrev
->number
== abbrev_number
)
18469 abbrev
= abbrev
->next
;
18474 /* Read in an abbrev table. */
18476 static abbrev_table_up
18477 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18478 struct dwarf2_section_info
*section
,
18479 sect_offset sect_off
)
18481 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18482 bfd
*abfd
= get_section_bfd_owner (section
);
18483 const gdb_byte
*abbrev_ptr
;
18484 struct abbrev_info
*cur_abbrev
;
18485 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18486 unsigned int abbrev_form
;
18487 struct attr_abbrev
*cur_attrs
;
18488 unsigned int allocated_attrs
;
18490 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18492 dwarf2_read_section (objfile
, section
);
18493 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18494 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18495 abbrev_ptr
+= bytes_read
;
18497 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18498 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18500 /* Loop until we reach an abbrev number of 0. */
18501 while (abbrev_number
)
18503 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18505 /* read in abbrev header */
18506 cur_abbrev
->number
= abbrev_number
;
18508 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18509 abbrev_ptr
+= bytes_read
;
18510 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18513 /* now read in declarations */
18516 LONGEST implicit_const
;
18518 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18519 abbrev_ptr
+= bytes_read
;
18520 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18521 abbrev_ptr
+= bytes_read
;
18522 if (abbrev_form
== DW_FORM_implicit_const
)
18524 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18526 abbrev_ptr
+= bytes_read
;
18530 /* Initialize it due to a false compiler warning. */
18531 implicit_const
= -1;
18534 if (abbrev_name
== 0)
18537 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18539 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18541 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18544 cur_attrs
[cur_abbrev
->num_attrs
].name
18545 = (enum dwarf_attribute
) abbrev_name
;
18546 cur_attrs
[cur_abbrev
->num_attrs
].form
18547 = (enum dwarf_form
) abbrev_form
;
18548 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18549 ++cur_abbrev
->num_attrs
;
18552 cur_abbrev
->attrs
=
18553 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18554 cur_abbrev
->num_attrs
);
18555 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18556 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18558 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18560 /* Get next abbreviation.
18561 Under Irix6 the abbreviations for a compilation unit are not
18562 always properly terminated with an abbrev number of 0.
18563 Exit loop if we encounter an abbreviation which we have
18564 already read (which means we are about to read the abbreviations
18565 for the next compile unit) or if the end of the abbreviation
18566 table is reached. */
18567 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18569 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18570 abbrev_ptr
+= bytes_read
;
18571 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18576 return abbrev_table
;
18579 /* Returns nonzero if TAG represents a type that we might generate a partial
18583 is_type_tag_for_partial (int tag
)
18588 /* Some types that would be reasonable to generate partial symbols for,
18589 that we don't at present. */
18590 case DW_TAG_array_type
:
18591 case DW_TAG_file_type
:
18592 case DW_TAG_ptr_to_member_type
:
18593 case DW_TAG_set_type
:
18594 case DW_TAG_string_type
:
18595 case DW_TAG_subroutine_type
:
18597 case DW_TAG_base_type
:
18598 case DW_TAG_class_type
:
18599 case DW_TAG_interface_type
:
18600 case DW_TAG_enumeration_type
:
18601 case DW_TAG_structure_type
:
18602 case DW_TAG_subrange_type
:
18603 case DW_TAG_typedef
:
18604 case DW_TAG_union_type
:
18611 /* Load all DIEs that are interesting for partial symbols into memory. */
18613 static struct partial_die_info
*
18614 load_partial_dies (const struct die_reader_specs
*reader
,
18615 const gdb_byte
*info_ptr
, int building_psymtab
)
18617 struct dwarf2_cu
*cu
= reader
->cu
;
18618 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18619 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18620 unsigned int bytes_read
;
18621 unsigned int load_all
= 0;
18622 int nesting_level
= 1;
18627 gdb_assert (cu
->per_cu
!= NULL
);
18628 if (cu
->per_cu
->load_all_dies
)
18632 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18636 &cu
->comp_unit_obstack
,
18637 hashtab_obstack_allocate
,
18638 dummy_obstack_deallocate
);
18642 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18644 /* A NULL abbrev means the end of a series of children. */
18645 if (abbrev
== NULL
)
18647 if (--nesting_level
== 0)
18650 info_ptr
+= bytes_read
;
18651 last_die
= parent_die
;
18652 parent_die
= parent_die
->die_parent
;
18656 /* Check for template arguments. We never save these; if
18657 they're seen, we just mark the parent, and go on our way. */
18658 if (parent_die
!= NULL
18659 && cu
->language
== language_cplus
18660 && (abbrev
->tag
== DW_TAG_template_type_param
18661 || abbrev
->tag
== DW_TAG_template_value_param
))
18663 parent_die
->has_template_arguments
= 1;
18667 /* We don't need a partial DIE for the template argument. */
18668 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18673 /* We only recurse into c++ subprograms looking for template arguments.
18674 Skip their other children. */
18676 && cu
->language
== language_cplus
18677 && parent_die
!= NULL
18678 && parent_die
->tag
== DW_TAG_subprogram
)
18680 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18684 /* Check whether this DIE is interesting enough to save. Normally
18685 we would not be interested in members here, but there may be
18686 later variables referencing them via DW_AT_specification (for
18687 static members). */
18689 && !is_type_tag_for_partial (abbrev
->tag
)
18690 && abbrev
->tag
!= DW_TAG_constant
18691 && abbrev
->tag
!= DW_TAG_enumerator
18692 && abbrev
->tag
!= DW_TAG_subprogram
18693 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18694 && abbrev
->tag
!= DW_TAG_lexical_block
18695 && abbrev
->tag
!= DW_TAG_variable
18696 && abbrev
->tag
!= DW_TAG_namespace
18697 && abbrev
->tag
!= DW_TAG_module
18698 && abbrev
->tag
!= DW_TAG_member
18699 && abbrev
->tag
!= DW_TAG_imported_unit
18700 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18702 /* Otherwise we skip to the next sibling, if any. */
18703 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18707 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18710 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18712 /* This two-pass algorithm for processing partial symbols has a
18713 high cost in cache pressure. Thus, handle some simple cases
18714 here which cover the majority of C partial symbols. DIEs
18715 which neither have specification tags in them, nor could have
18716 specification tags elsewhere pointing at them, can simply be
18717 processed and discarded.
18719 This segment is also optional; scan_partial_symbols and
18720 add_partial_symbol will handle these DIEs if we chain
18721 them in normally. When compilers which do not emit large
18722 quantities of duplicate debug information are more common,
18723 this code can probably be removed. */
18725 /* Any complete simple types at the top level (pretty much all
18726 of them, for a language without namespaces), can be processed
18728 if (parent_die
== NULL
18729 && pdi
.has_specification
== 0
18730 && pdi
.is_declaration
== 0
18731 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18732 || pdi
.tag
== DW_TAG_base_type
18733 || pdi
.tag
== DW_TAG_subrange_type
))
18735 if (building_psymtab
&& pdi
.name
!= NULL
)
18736 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18737 VAR_DOMAIN
, LOC_TYPEDEF
,
18738 &objfile
->static_psymbols
,
18739 0, cu
->language
, objfile
);
18740 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18744 /* The exception for DW_TAG_typedef with has_children above is
18745 a workaround of GCC PR debug/47510. In the case of this complaint
18746 type_name_no_tag_or_error will error on such types later.
18748 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18749 it could not find the child DIEs referenced later, this is checked
18750 above. In correct DWARF DW_TAG_typedef should have no children. */
18752 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18753 complaint (&symfile_complaints
,
18754 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18755 "- DIE at %s [in module %s]"),
18756 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18758 /* If we're at the second level, and we're an enumerator, and
18759 our parent has no specification (meaning possibly lives in a
18760 namespace elsewhere), then we can add the partial symbol now
18761 instead of queueing it. */
18762 if (pdi
.tag
== DW_TAG_enumerator
18763 && parent_die
!= NULL
18764 && parent_die
->die_parent
== NULL
18765 && parent_die
->tag
== DW_TAG_enumeration_type
18766 && parent_die
->has_specification
== 0)
18768 if (pdi
.name
== NULL
)
18769 complaint (&symfile_complaints
,
18770 _("malformed enumerator DIE ignored"));
18771 else if (building_psymtab
)
18772 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18773 VAR_DOMAIN
, LOC_CONST
,
18774 cu
->language
== language_cplus
18775 ? &objfile
->global_psymbols
18776 : &objfile
->static_psymbols
,
18777 0, cu
->language
, objfile
);
18779 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18783 struct partial_die_info
*part_die
18784 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18786 /* We'll save this DIE so link it in. */
18787 part_die
->die_parent
= parent_die
;
18788 part_die
->die_sibling
= NULL
;
18789 part_die
->die_child
= NULL
;
18791 if (last_die
&& last_die
== parent_die
)
18792 last_die
->die_child
= part_die
;
18794 last_die
->die_sibling
= part_die
;
18796 last_die
= part_die
;
18798 if (first_die
== NULL
)
18799 first_die
= part_die
;
18801 /* Maybe add the DIE to the hash table. Not all DIEs that we
18802 find interesting need to be in the hash table, because we
18803 also have the parent/sibling/child chains; only those that we
18804 might refer to by offset later during partial symbol reading.
18806 For now this means things that might have be the target of a
18807 DW_AT_specification, DW_AT_abstract_origin, or
18808 DW_AT_extension. DW_AT_extension will refer only to
18809 namespaces; DW_AT_abstract_origin refers to functions (and
18810 many things under the function DIE, but we do not recurse
18811 into function DIEs during partial symbol reading) and
18812 possibly variables as well; DW_AT_specification refers to
18813 declarations. Declarations ought to have the DW_AT_declaration
18814 flag. It happens that GCC forgets to put it in sometimes, but
18815 only for functions, not for types.
18817 Adding more things than necessary to the hash table is harmless
18818 except for the performance cost. Adding too few will result in
18819 wasted time in find_partial_die, when we reread the compilation
18820 unit with load_all_dies set. */
18823 || abbrev
->tag
== DW_TAG_constant
18824 || abbrev
->tag
== DW_TAG_subprogram
18825 || abbrev
->tag
== DW_TAG_variable
18826 || abbrev
->tag
== DW_TAG_namespace
18827 || part_die
->is_declaration
)
18831 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18832 to_underlying (part_die
->sect_off
),
18837 /* For some DIEs we want to follow their children (if any). For C
18838 we have no reason to follow the children of structures; for other
18839 languages we have to, so that we can get at method physnames
18840 to infer fully qualified class names, for DW_AT_specification,
18841 and for C++ template arguments. For C++, we also look one level
18842 inside functions to find template arguments (if the name of the
18843 function does not already contain the template arguments).
18845 For Ada, we need to scan the children of subprograms and lexical
18846 blocks as well because Ada allows the definition of nested
18847 entities that could be interesting for the debugger, such as
18848 nested subprograms for instance. */
18849 if (last_die
->has_children
18851 || last_die
->tag
== DW_TAG_namespace
18852 || last_die
->tag
== DW_TAG_module
18853 || last_die
->tag
== DW_TAG_enumeration_type
18854 || (cu
->language
== language_cplus
18855 && last_die
->tag
== DW_TAG_subprogram
18856 && (last_die
->name
== NULL
18857 || strchr (last_die
->name
, '<') == NULL
))
18858 || (cu
->language
!= language_c
18859 && (last_die
->tag
== DW_TAG_class_type
18860 || last_die
->tag
== DW_TAG_interface_type
18861 || last_die
->tag
== DW_TAG_structure_type
18862 || last_die
->tag
== DW_TAG_union_type
))
18863 || (cu
->language
== language_ada
18864 && (last_die
->tag
== DW_TAG_subprogram
18865 || last_die
->tag
== DW_TAG_lexical_block
))))
18868 parent_die
= last_die
;
18872 /* Otherwise we skip to the next sibling, if any. */
18873 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18875 /* Back to the top, do it again. */
18879 partial_die_info::partial_die_info (sect_offset sect_off_
,
18880 struct abbrev_info
*abbrev
)
18881 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18885 /* Read a minimal amount of information into the minimal die structure.
18886 INFO_PTR should point just after the initial uleb128 of a DIE. */
18889 partial_die_info::read (const struct die_reader_specs
*reader
,
18890 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18892 struct dwarf2_cu
*cu
= reader
->cu
;
18893 struct dwarf2_per_objfile
*dwarf2_per_objfile
18894 = cu
->per_cu
->dwarf2_per_objfile
;
18896 int has_low_pc_attr
= 0;
18897 int has_high_pc_attr
= 0;
18898 int high_pc_relative
= 0;
18900 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18902 struct attribute attr
;
18904 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18906 /* Store the data if it is of an attribute we want to keep in a
18907 partial symbol table. */
18913 case DW_TAG_compile_unit
:
18914 case DW_TAG_partial_unit
:
18915 case DW_TAG_type_unit
:
18916 /* Compilation units have a DW_AT_name that is a filename, not
18917 a source language identifier. */
18918 case DW_TAG_enumeration_type
:
18919 case DW_TAG_enumerator
:
18920 /* These tags always have simple identifiers already; no need
18921 to canonicalize them. */
18922 name
= DW_STRING (&attr
);
18926 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18929 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18930 &objfile
->per_bfd
->storage_obstack
);
18935 case DW_AT_linkage_name
:
18936 case DW_AT_MIPS_linkage_name
:
18937 /* Note that both forms of linkage name might appear. We
18938 assume they will be the same, and we only store the last
18940 if (cu
->language
== language_ada
)
18941 name
= DW_STRING (&attr
);
18942 linkage_name
= DW_STRING (&attr
);
18945 has_low_pc_attr
= 1;
18946 lowpc
= attr_value_as_address (&attr
);
18948 case DW_AT_high_pc
:
18949 has_high_pc_attr
= 1;
18950 highpc
= attr_value_as_address (&attr
);
18951 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18952 high_pc_relative
= 1;
18954 case DW_AT_location
:
18955 /* Support the .debug_loc offsets. */
18956 if (attr_form_is_block (&attr
))
18958 d
.locdesc
= DW_BLOCK (&attr
);
18960 else if (attr_form_is_section_offset (&attr
))
18962 dwarf2_complex_location_expr_complaint ();
18966 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18967 "partial symbol information");
18970 case DW_AT_external
:
18971 is_external
= DW_UNSND (&attr
);
18973 case DW_AT_declaration
:
18974 is_declaration
= DW_UNSND (&attr
);
18979 case DW_AT_abstract_origin
:
18980 case DW_AT_specification
:
18981 case DW_AT_extension
:
18982 has_specification
= 1;
18983 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18984 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18985 || cu
->per_cu
->is_dwz
);
18987 case DW_AT_sibling
:
18988 /* Ignore absolute siblings, they might point outside of
18989 the current compile unit. */
18990 if (attr
.form
== DW_FORM_ref_addr
)
18991 complaint (&symfile_complaints
,
18992 _("ignoring absolute DW_AT_sibling"));
18995 const gdb_byte
*buffer
= reader
->buffer
;
18996 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18997 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18999 if (sibling_ptr
< info_ptr
)
19000 complaint (&symfile_complaints
,
19001 _("DW_AT_sibling points backwards"));
19002 else if (sibling_ptr
> reader
->buffer_end
)
19003 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19005 sibling
= sibling_ptr
;
19008 case DW_AT_byte_size
:
19011 case DW_AT_const_value
:
19012 has_const_value
= 1;
19014 case DW_AT_calling_convention
:
19015 /* DWARF doesn't provide a way to identify a program's source-level
19016 entry point. DW_AT_calling_convention attributes are only meant
19017 to describe functions' calling conventions.
19019 However, because it's a necessary piece of information in
19020 Fortran, and before DWARF 4 DW_CC_program was the only
19021 piece of debugging information whose definition refers to
19022 a 'main program' at all, several compilers marked Fortran
19023 main programs with DW_CC_program --- even when those
19024 functions use the standard calling conventions.
19026 Although DWARF now specifies a way to provide this
19027 information, we support this practice for backward
19029 if (DW_UNSND (&attr
) == DW_CC_program
19030 && cu
->language
== language_fortran
)
19031 main_subprogram
= 1;
19034 if (DW_UNSND (&attr
) == DW_INL_inlined
19035 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19036 may_be_inlined
= 1;
19040 if (tag
== DW_TAG_imported_unit
)
19042 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19043 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19044 || cu
->per_cu
->is_dwz
);
19048 case DW_AT_main_subprogram
:
19049 main_subprogram
= DW_UNSND (&attr
);
19057 if (high_pc_relative
)
19060 if (has_low_pc_attr
&& has_high_pc_attr
)
19062 /* When using the GNU linker, .gnu.linkonce. sections are used to
19063 eliminate duplicate copies of functions and vtables and such.
19064 The linker will arbitrarily choose one and discard the others.
19065 The AT_*_pc values for such functions refer to local labels in
19066 these sections. If the section from that file was discarded, the
19067 labels are not in the output, so the relocs get a value of 0.
19068 If this is a discarded function, mark the pc bounds as invalid,
19069 so that GDB will ignore it. */
19070 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19072 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19073 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19075 complaint (&symfile_complaints
,
19076 _("DW_AT_low_pc %s is zero "
19077 "for DIE at %s [in module %s]"),
19078 paddress (gdbarch
, lowpc
),
19079 sect_offset_str (sect_off
),
19080 objfile_name (objfile
));
19082 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19083 else if (lowpc
>= highpc
)
19085 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19086 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19088 complaint (&symfile_complaints
,
19089 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19090 "for DIE at %s [in module %s]"),
19091 paddress (gdbarch
, lowpc
),
19092 paddress (gdbarch
, highpc
),
19093 sect_offset_str (sect_off
),
19094 objfile_name (objfile
));
19103 /* Find a cached partial DIE at OFFSET in CU. */
19105 struct partial_die_info
*
19106 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19108 struct partial_die_info
*lookup_die
= NULL
;
19109 struct partial_die_info
part_die (sect_off
);
19111 lookup_die
= ((struct partial_die_info
*)
19112 htab_find_with_hash (partial_dies
, &part_die
,
19113 to_underlying (sect_off
)));
19118 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19119 except in the case of .debug_types DIEs which do not reference
19120 outside their CU (they do however referencing other types via
19121 DW_FORM_ref_sig8). */
19123 static struct partial_die_info
*
19124 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19126 struct dwarf2_per_objfile
*dwarf2_per_objfile
19127 = cu
->per_cu
->dwarf2_per_objfile
;
19128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19129 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19130 struct partial_die_info
*pd
= NULL
;
19132 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19133 && offset_in_cu_p (&cu
->header
, sect_off
))
19135 pd
= cu
->find_partial_die (sect_off
);
19138 /* We missed recording what we needed.
19139 Load all dies and try again. */
19140 per_cu
= cu
->per_cu
;
19144 /* TUs don't reference other CUs/TUs (except via type signatures). */
19145 if (cu
->per_cu
->is_debug_types
)
19147 error (_("Dwarf Error: Type Unit at offset %s contains"
19148 " external reference to offset %s [in module %s].\n"),
19149 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19150 bfd_get_filename (objfile
->obfd
));
19152 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19153 dwarf2_per_objfile
);
19155 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19156 load_partial_comp_unit (per_cu
);
19158 per_cu
->cu
->last_used
= 0;
19159 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19162 /* If we didn't find it, and not all dies have been loaded,
19163 load them all and try again. */
19165 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19167 per_cu
->load_all_dies
= 1;
19169 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19170 THIS_CU->cu may already be in use. So we can't just free it and
19171 replace its DIEs with the ones we read in. Instead, we leave those
19172 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19173 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19175 load_partial_comp_unit (per_cu
);
19177 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19181 internal_error (__FILE__
, __LINE__
,
19182 _("could not find partial DIE %s "
19183 "in cache [from module %s]\n"),
19184 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19188 /* See if we can figure out if the class lives in a namespace. We do
19189 this by looking for a member function; its demangled name will
19190 contain namespace info, if there is any. */
19193 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19194 struct dwarf2_cu
*cu
)
19196 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19197 what template types look like, because the demangler
19198 frequently doesn't give the same name as the debug info. We
19199 could fix this by only using the demangled name to get the
19200 prefix (but see comment in read_structure_type). */
19202 struct partial_die_info
*real_pdi
;
19203 struct partial_die_info
*child_pdi
;
19205 /* If this DIE (this DIE's specification, if any) has a parent, then
19206 we should not do this. We'll prepend the parent's fully qualified
19207 name when we create the partial symbol. */
19209 real_pdi
= struct_pdi
;
19210 while (real_pdi
->has_specification
)
19211 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
19212 real_pdi
->spec_is_dwz
, cu
);
19214 if (real_pdi
->die_parent
!= NULL
)
19217 for (child_pdi
= struct_pdi
->die_child
;
19219 child_pdi
= child_pdi
->die_sibling
)
19221 if (child_pdi
->tag
== DW_TAG_subprogram
19222 && child_pdi
->linkage_name
!= NULL
)
19224 char *actual_class_name
19225 = language_class_name_from_physname (cu
->language_defn
,
19226 child_pdi
->linkage_name
);
19227 if (actual_class_name
!= NULL
)
19229 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19232 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19234 strlen (actual_class_name
)));
19235 xfree (actual_class_name
);
19243 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19245 /* Once we've fixed up a die, there's no point in doing so again.
19246 This also avoids a memory leak if we were to call
19247 guess_partial_die_structure_name multiple times. */
19251 /* If we found a reference attribute and the DIE has no name, try
19252 to find a name in the referred to DIE. */
19254 if (name
== NULL
&& has_specification
)
19256 struct partial_die_info
*spec_die
;
19258 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19260 spec_die
->fixup (cu
);
19262 if (spec_die
->name
)
19264 name
= spec_die
->name
;
19266 /* Copy DW_AT_external attribute if it is set. */
19267 if (spec_die
->is_external
)
19268 is_external
= spec_die
->is_external
;
19272 /* Set default names for some unnamed DIEs. */
19274 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19275 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19277 /* If there is no parent die to provide a namespace, and there are
19278 children, see if we can determine the namespace from their linkage
19280 if (cu
->language
== language_cplus
19281 && !VEC_empty (dwarf2_section_info_def
,
19282 cu
->per_cu
->dwarf2_per_objfile
->types
)
19283 && die_parent
== NULL
19285 && (tag
== DW_TAG_class_type
19286 || tag
== DW_TAG_structure_type
19287 || tag
== DW_TAG_union_type
))
19288 guess_partial_die_structure_name (this, cu
);
19290 /* GCC might emit a nameless struct or union that has a linkage
19291 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19293 && (tag
== DW_TAG_class_type
19294 || tag
== DW_TAG_interface_type
19295 || tag
== DW_TAG_structure_type
19296 || tag
== DW_TAG_union_type
)
19297 && linkage_name
!= NULL
)
19301 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19306 /* Strip any leading namespaces/classes, keep only the base name.
19307 DW_AT_name for named DIEs does not contain the prefixes. */
19308 base
= strrchr (demangled
, ':');
19309 if (base
&& base
> demangled
&& base
[-1] == ':')
19314 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19317 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19318 base
, strlen (base
)));
19326 /* Read an attribute value described by an attribute form. */
19328 static const gdb_byte
*
19329 read_attribute_value (const struct die_reader_specs
*reader
,
19330 struct attribute
*attr
, unsigned form
,
19331 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19333 struct dwarf2_cu
*cu
= reader
->cu
;
19334 struct dwarf2_per_objfile
*dwarf2_per_objfile
19335 = cu
->per_cu
->dwarf2_per_objfile
;
19336 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19337 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19338 bfd
*abfd
= reader
->abfd
;
19339 struct comp_unit_head
*cu_header
= &cu
->header
;
19340 unsigned int bytes_read
;
19341 struct dwarf_block
*blk
;
19343 attr
->form
= (enum dwarf_form
) form
;
19346 case DW_FORM_ref_addr
:
19347 if (cu
->header
.version
== 2)
19348 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19350 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19351 &cu
->header
, &bytes_read
);
19352 info_ptr
+= bytes_read
;
19354 case DW_FORM_GNU_ref_alt
:
19355 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19356 info_ptr
+= bytes_read
;
19359 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19360 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19361 info_ptr
+= bytes_read
;
19363 case DW_FORM_block2
:
19364 blk
= dwarf_alloc_block (cu
);
19365 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19367 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19368 info_ptr
+= blk
->size
;
19369 DW_BLOCK (attr
) = blk
;
19371 case DW_FORM_block4
:
19372 blk
= dwarf_alloc_block (cu
);
19373 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19375 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19376 info_ptr
+= blk
->size
;
19377 DW_BLOCK (attr
) = blk
;
19379 case DW_FORM_data2
:
19380 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19383 case DW_FORM_data4
:
19384 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19387 case DW_FORM_data8
:
19388 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19391 case DW_FORM_data16
:
19392 blk
= dwarf_alloc_block (cu
);
19394 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19396 DW_BLOCK (attr
) = blk
;
19398 case DW_FORM_sec_offset
:
19399 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19400 info_ptr
+= bytes_read
;
19402 case DW_FORM_string
:
19403 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19404 DW_STRING_IS_CANONICAL (attr
) = 0;
19405 info_ptr
+= bytes_read
;
19408 if (!cu
->per_cu
->is_dwz
)
19410 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19411 abfd
, info_ptr
, cu_header
,
19413 DW_STRING_IS_CANONICAL (attr
) = 0;
19414 info_ptr
+= bytes_read
;
19418 case DW_FORM_line_strp
:
19419 if (!cu
->per_cu
->is_dwz
)
19421 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19423 cu_header
, &bytes_read
);
19424 DW_STRING_IS_CANONICAL (attr
) = 0;
19425 info_ptr
+= bytes_read
;
19429 case DW_FORM_GNU_strp_alt
:
19431 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19432 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19435 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19437 DW_STRING_IS_CANONICAL (attr
) = 0;
19438 info_ptr
+= bytes_read
;
19441 case DW_FORM_exprloc
:
19442 case DW_FORM_block
:
19443 blk
= dwarf_alloc_block (cu
);
19444 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19445 info_ptr
+= bytes_read
;
19446 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19447 info_ptr
+= blk
->size
;
19448 DW_BLOCK (attr
) = blk
;
19450 case DW_FORM_block1
:
19451 blk
= dwarf_alloc_block (cu
);
19452 blk
->size
= read_1_byte (abfd
, info_ptr
);
19454 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19455 info_ptr
+= blk
->size
;
19456 DW_BLOCK (attr
) = blk
;
19458 case DW_FORM_data1
:
19459 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19463 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19466 case DW_FORM_flag_present
:
19467 DW_UNSND (attr
) = 1;
19469 case DW_FORM_sdata
:
19470 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19471 info_ptr
+= bytes_read
;
19473 case DW_FORM_udata
:
19474 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19475 info_ptr
+= bytes_read
;
19478 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19479 + read_1_byte (abfd
, info_ptr
));
19483 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19484 + read_2_bytes (abfd
, info_ptr
));
19488 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19489 + read_4_bytes (abfd
, info_ptr
));
19493 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19494 + read_8_bytes (abfd
, info_ptr
));
19497 case DW_FORM_ref_sig8
:
19498 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19501 case DW_FORM_ref_udata
:
19502 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19503 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19504 info_ptr
+= bytes_read
;
19506 case DW_FORM_indirect
:
19507 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19508 info_ptr
+= bytes_read
;
19509 if (form
== DW_FORM_implicit_const
)
19511 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19512 info_ptr
+= bytes_read
;
19514 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19517 case DW_FORM_implicit_const
:
19518 DW_SND (attr
) = implicit_const
;
19520 case DW_FORM_GNU_addr_index
:
19521 if (reader
->dwo_file
== NULL
)
19523 /* For now flag a hard error.
19524 Later we can turn this into a complaint. */
19525 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19526 dwarf_form_name (form
),
19527 bfd_get_filename (abfd
));
19529 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19530 info_ptr
+= bytes_read
;
19532 case DW_FORM_GNU_str_index
:
19533 if (reader
->dwo_file
== NULL
)
19535 /* For now flag a hard error.
19536 Later we can turn this into a complaint if warranted. */
19537 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19538 dwarf_form_name (form
),
19539 bfd_get_filename (abfd
));
19542 ULONGEST str_index
=
19543 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19545 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19546 DW_STRING_IS_CANONICAL (attr
) = 0;
19547 info_ptr
+= bytes_read
;
19551 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19552 dwarf_form_name (form
),
19553 bfd_get_filename (abfd
));
19557 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19558 attr
->form
= DW_FORM_GNU_ref_alt
;
19560 /* We have seen instances where the compiler tried to emit a byte
19561 size attribute of -1 which ended up being encoded as an unsigned
19562 0xffffffff. Although 0xffffffff is technically a valid size value,
19563 an object of this size seems pretty unlikely so we can relatively
19564 safely treat these cases as if the size attribute was invalid and
19565 treat them as zero by default. */
19566 if (attr
->name
== DW_AT_byte_size
19567 && form
== DW_FORM_data4
19568 && DW_UNSND (attr
) >= 0xffffffff)
19571 (&symfile_complaints
,
19572 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19573 hex_string (DW_UNSND (attr
)));
19574 DW_UNSND (attr
) = 0;
19580 /* Read an attribute described by an abbreviated attribute. */
19582 static const gdb_byte
*
19583 read_attribute (const struct die_reader_specs
*reader
,
19584 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19585 const gdb_byte
*info_ptr
)
19587 attr
->name
= abbrev
->name
;
19588 return read_attribute_value (reader
, attr
, abbrev
->form
,
19589 abbrev
->implicit_const
, info_ptr
);
19592 /* Read dwarf information from a buffer. */
19594 static unsigned int
19595 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19597 return bfd_get_8 (abfd
, buf
);
19601 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19603 return bfd_get_signed_8 (abfd
, buf
);
19606 static unsigned int
19607 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19609 return bfd_get_16 (abfd
, buf
);
19613 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19615 return bfd_get_signed_16 (abfd
, buf
);
19618 static unsigned int
19619 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19621 return bfd_get_32 (abfd
, buf
);
19625 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19627 return bfd_get_signed_32 (abfd
, buf
);
19631 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19633 return bfd_get_64 (abfd
, buf
);
19637 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19638 unsigned int *bytes_read
)
19640 struct comp_unit_head
*cu_header
= &cu
->header
;
19641 CORE_ADDR retval
= 0;
19643 if (cu_header
->signed_addr_p
)
19645 switch (cu_header
->addr_size
)
19648 retval
= bfd_get_signed_16 (abfd
, buf
);
19651 retval
= bfd_get_signed_32 (abfd
, buf
);
19654 retval
= bfd_get_signed_64 (abfd
, buf
);
19657 internal_error (__FILE__
, __LINE__
,
19658 _("read_address: bad switch, signed [in module %s]"),
19659 bfd_get_filename (abfd
));
19664 switch (cu_header
->addr_size
)
19667 retval
= bfd_get_16 (abfd
, buf
);
19670 retval
= bfd_get_32 (abfd
, buf
);
19673 retval
= bfd_get_64 (abfd
, buf
);
19676 internal_error (__FILE__
, __LINE__
,
19677 _("read_address: bad switch, "
19678 "unsigned [in module %s]"),
19679 bfd_get_filename (abfd
));
19683 *bytes_read
= cu_header
->addr_size
;
19687 /* Read the initial length from a section. The (draft) DWARF 3
19688 specification allows the initial length to take up either 4 bytes
19689 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19690 bytes describe the length and all offsets will be 8 bytes in length
19693 An older, non-standard 64-bit format is also handled by this
19694 function. The older format in question stores the initial length
19695 as an 8-byte quantity without an escape value. Lengths greater
19696 than 2^32 aren't very common which means that the initial 4 bytes
19697 is almost always zero. Since a length value of zero doesn't make
19698 sense for the 32-bit format, this initial zero can be considered to
19699 be an escape value which indicates the presence of the older 64-bit
19700 format. As written, the code can't detect (old format) lengths
19701 greater than 4GB. If it becomes necessary to handle lengths
19702 somewhat larger than 4GB, we could allow other small values (such
19703 as the non-sensical values of 1, 2, and 3) to also be used as
19704 escape values indicating the presence of the old format.
19706 The value returned via bytes_read should be used to increment the
19707 relevant pointer after calling read_initial_length().
19709 [ Note: read_initial_length() and read_offset() are based on the
19710 document entitled "DWARF Debugging Information Format", revision
19711 3, draft 8, dated November 19, 2001. This document was obtained
19714 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19716 This document is only a draft and is subject to change. (So beware.)
19718 Details regarding the older, non-standard 64-bit format were
19719 determined empirically by examining 64-bit ELF files produced by
19720 the SGI toolchain on an IRIX 6.5 machine.
19722 - Kevin, July 16, 2002
19726 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19728 LONGEST length
= bfd_get_32 (abfd
, buf
);
19730 if (length
== 0xffffffff)
19732 length
= bfd_get_64 (abfd
, buf
+ 4);
19735 else if (length
== 0)
19737 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19738 length
= bfd_get_64 (abfd
, buf
);
19749 /* Cover function for read_initial_length.
19750 Returns the length of the object at BUF, and stores the size of the
19751 initial length in *BYTES_READ and stores the size that offsets will be in
19753 If the initial length size is not equivalent to that specified in
19754 CU_HEADER then issue a complaint.
19755 This is useful when reading non-comp-unit headers. */
19758 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19759 const struct comp_unit_head
*cu_header
,
19760 unsigned int *bytes_read
,
19761 unsigned int *offset_size
)
19763 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19765 gdb_assert (cu_header
->initial_length_size
== 4
19766 || cu_header
->initial_length_size
== 8
19767 || cu_header
->initial_length_size
== 12);
19769 if (cu_header
->initial_length_size
!= *bytes_read
)
19770 complaint (&symfile_complaints
,
19771 _("intermixed 32-bit and 64-bit DWARF sections"));
19773 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19777 /* Read an offset from the data stream. The size of the offset is
19778 given by cu_header->offset_size. */
19781 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19782 const struct comp_unit_head
*cu_header
,
19783 unsigned int *bytes_read
)
19785 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19787 *bytes_read
= cu_header
->offset_size
;
19791 /* Read an offset from the data stream. */
19794 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19796 LONGEST retval
= 0;
19798 switch (offset_size
)
19801 retval
= bfd_get_32 (abfd
, buf
);
19804 retval
= bfd_get_64 (abfd
, buf
);
19807 internal_error (__FILE__
, __LINE__
,
19808 _("read_offset_1: bad switch [in module %s]"),
19809 bfd_get_filename (abfd
));
19815 static const gdb_byte
*
19816 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19818 /* If the size of a host char is 8 bits, we can return a pointer
19819 to the buffer, otherwise we have to copy the data to a buffer
19820 allocated on the temporary obstack. */
19821 gdb_assert (HOST_CHAR_BIT
== 8);
19825 static const char *
19826 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19827 unsigned int *bytes_read_ptr
)
19829 /* If the size of a host char is 8 bits, we can return a pointer
19830 to the string, otherwise we have to copy the string to a buffer
19831 allocated on the temporary obstack. */
19832 gdb_assert (HOST_CHAR_BIT
== 8);
19835 *bytes_read_ptr
= 1;
19838 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19839 return (const char *) buf
;
19842 /* Return pointer to string at section SECT offset STR_OFFSET with error
19843 reporting strings FORM_NAME and SECT_NAME. */
19845 static const char *
19846 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19847 bfd
*abfd
, LONGEST str_offset
,
19848 struct dwarf2_section_info
*sect
,
19849 const char *form_name
,
19850 const char *sect_name
)
19852 dwarf2_read_section (objfile
, sect
);
19853 if (sect
->buffer
== NULL
)
19854 error (_("%s used without %s section [in module %s]"),
19855 form_name
, sect_name
, bfd_get_filename (abfd
));
19856 if (str_offset
>= sect
->size
)
19857 error (_("%s pointing outside of %s section [in module %s]"),
19858 form_name
, sect_name
, bfd_get_filename (abfd
));
19859 gdb_assert (HOST_CHAR_BIT
== 8);
19860 if (sect
->buffer
[str_offset
] == '\0')
19862 return (const char *) (sect
->buffer
+ str_offset
);
19865 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19867 static const char *
19868 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19869 bfd
*abfd
, LONGEST str_offset
)
19871 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19873 &dwarf2_per_objfile
->str
,
19874 "DW_FORM_strp", ".debug_str");
19877 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19879 static const char *
19880 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19881 bfd
*abfd
, LONGEST str_offset
)
19883 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19885 &dwarf2_per_objfile
->line_str
,
19886 "DW_FORM_line_strp",
19887 ".debug_line_str");
19890 /* Read a string at offset STR_OFFSET in the .debug_str section from
19891 the .dwz file DWZ. Throw an error if the offset is too large. If
19892 the string consists of a single NUL byte, return NULL; otherwise
19893 return a pointer to the string. */
19895 static const char *
19896 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19897 LONGEST str_offset
)
19899 dwarf2_read_section (objfile
, &dwz
->str
);
19901 if (dwz
->str
.buffer
== NULL
)
19902 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19903 "section [in module %s]"),
19904 bfd_get_filename (dwz
->dwz_bfd
));
19905 if (str_offset
>= dwz
->str
.size
)
19906 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19907 ".debug_str section [in module %s]"),
19908 bfd_get_filename (dwz
->dwz_bfd
));
19909 gdb_assert (HOST_CHAR_BIT
== 8);
19910 if (dwz
->str
.buffer
[str_offset
] == '\0')
19912 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19915 /* Return pointer to string at .debug_str offset as read from BUF.
19916 BUF is assumed to be in a compilation unit described by CU_HEADER.
19917 Return *BYTES_READ_PTR count of bytes read from BUF. */
19919 static const char *
19920 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19921 const gdb_byte
*buf
,
19922 const struct comp_unit_head
*cu_header
,
19923 unsigned int *bytes_read_ptr
)
19925 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19927 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19930 /* Return pointer to string at .debug_line_str offset as read from BUF.
19931 BUF is assumed to be in a compilation unit described by CU_HEADER.
19932 Return *BYTES_READ_PTR count of bytes read from BUF. */
19934 static const char *
19935 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19936 bfd
*abfd
, const gdb_byte
*buf
,
19937 const struct comp_unit_head
*cu_header
,
19938 unsigned int *bytes_read_ptr
)
19940 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19942 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19947 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19948 unsigned int *bytes_read_ptr
)
19951 unsigned int num_read
;
19953 unsigned char byte
;
19960 byte
= bfd_get_8 (abfd
, buf
);
19963 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19964 if ((byte
& 128) == 0)
19970 *bytes_read_ptr
= num_read
;
19975 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19976 unsigned int *bytes_read_ptr
)
19979 int shift
, num_read
;
19980 unsigned char byte
;
19987 byte
= bfd_get_8 (abfd
, buf
);
19990 result
|= ((LONGEST
) (byte
& 127) << shift
);
19992 if ((byte
& 128) == 0)
19997 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19998 result
|= -(((LONGEST
) 1) << shift
);
19999 *bytes_read_ptr
= num_read
;
20003 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20004 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20005 ADDR_SIZE is the size of addresses from the CU header. */
20008 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20009 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20011 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20012 bfd
*abfd
= objfile
->obfd
;
20013 const gdb_byte
*info_ptr
;
20015 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20016 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20017 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20018 objfile_name (objfile
));
20019 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20020 error (_("DW_FORM_addr_index pointing outside of "
20021 ".debug_addr section [in module %s]"),
20022 objfile_name (objfile
));
20023 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20024 + addr_base
+ addr_index
* addr_size
);
20025 if (addr_size
== 4)
20026 return bfd_get_32 (abfd
, info_ptr
);
20028 return bfd_get_64 (abfd
, info_ptr
);
20031 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20034 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20036 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20037 cu
->addr_base
, cu
->header
.addr_size
);
20040 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20043 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20044 unsigned int *bytes_read
)
20046 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20047 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20049 return read_addr_index (cu
, addr_index
);
20052 /* Data structure to pass results from dwarf2_read_addr_index_reader
20053 back to dwarf2_read_addr_index. */
20055 struct dwarf2_read_addr_index_data
20057 ULONGEST addr_base
;
20061 /* die_reader_func for dwarf2_read_addr_index. */
20064 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20065 const gdb_byte
*info_ptr
,
20066 struct die_info
*comp_unit_die
,
20070 struct dwarf2_cu
*cu
= reader
->cu
;
20071 struct dwarf2_read_addr_index_data
*aidata
=
20072 (struct dwarf2_read_addr_index_data
*) data
;
20074 aidata
->addr_base
= cu
->addr_base
;
20075 aidata
->addr_size
= cu
->header
.addr_size
;
20078 /* Given an index in .debug_addr, fetch the value.
20079 NOTE: This can be called during dwarf expression evaluation,
20080 long after the debug information has been read, and thus per_cu->cu
20081 may no longer exist. */
20084 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20085 unsigned int addr_index
)
20087 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20088 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20089 struct dwarf2_cu
*cu
= per_cu
->cu
;
20090 ULONGEST addr_base
;
20093 /* We need addr_base and addr_size.
20094 If we don't have PER_CU->cu, we have to get it.
20095 Nasty, but the alternative is storing the needed info in PER_CU,
20096 which at this point doesn't seem justified: it's not clear how frequently
20097 it would get used and it would increase the size of every PER_CU.
20098 Entry points like dwarf2_per_cu_addr_size do a similar thing
20099 so we're not in uncharted territory here.
20100 Alas we need to be a bit more complicated as addr_base is contained
20103 We don't need to read the entire CU(/TU).
20104 We just need the header and top level die.
20106 IWBN to use the aging mechanism to let us lazily later discard the CU.
20107 For now we skip this optimization. */
20111 addr_base
= cu
->addr_base
;
20112 addr_size
= cu
->header
.addr_size
;
20116 struct dwarf2_read_addr_index_data aidata
;
20118 /* Note: We can't use init_cutu_and_read_dies_simple here,
20119 we need addr_base. */
20120 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
20121 dwarf2_read_addr_index_reader
, &aidata
);
20122 addr_base
= aidata
.addr_base
;
20123 addr_size
= aidata
.addr_size
;
20126 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20130 /* Given a DW_FORM_GNU_str_index, fetch the string.
20131 This is only used by the Fission support. */
20133 static const char *
20134 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20136 struct dwarf2_cu
*cu
= reader
->cu
;
20137 struct dwarf2_per_objfile
*dwarf2_per_objfile
20138 = cu
->per_cu
->dwarf2_per_objfile
;
20139 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20140 const char *objf_name
= objfile_name (objfile
);
20141 bfd
*abfd
= objfile
->obfd
;
20142 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20143 struct dwarf2_section_info
*str_offsets_section
=
20144 &reader
->dwo_file
->sections
.str_offsets
;
20145 const gdb_byte
*info_ptr
;
20146 ULONGEST str_offset
;
20147 static const char form_name
[] = "DW_FORM_GNU_str_index";
20149 dwarf2_read_section (objfile
, str_section
);
20150 dwarf2_read_section (objfile
, str_offsets_section
);
20151 if (str_section
->buffer
== NULL
)
20152 error (_("%s used without .debug_str.dwo section"
20153 " in CU at offset %s [in module %s]"),
20154 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20155 if (str_offsets_section
->buffer
== NULL
)
20156 error (_("%s used without .debug_str_offsets.dwo section"
20157 " in CU at offset %s [in module %s]"),
20158 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20159 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20160 error (_("%s pointing outside of .debug_str_offsets.dwo"
20161 " section in CU at offset %s [in module %s]"),
20162 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20163 info_ptr
= (str_offsets_section
->buffer
20164 + str_index
* cu
->header
.offset_size
);
20165 if (cu
->header
.offset_size
== 4)
20166 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20168 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20169 if (str_offset
>= str_section
->size
)
20170 error (_("Offset from %s pointing outside of"
20171 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20172 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20173 return (const char *) (str_section
->buffer
+ str_offset
);
20176 /* Return the length of an LEB128 number in BUF. */
20179 leb128_size (const gdb_byte
*buf
)
20181 const gdb_byte
*begin
= buf
;
20187 if ((byte
& 128) == 0)
20188 return buf
- begin
;
20193 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20202 cu
->language
= language_c
;
20205 case DW_LANG_C_plus_plus
:
20206 case DW_LANG_C_plus_plus_11
:
20207 case DW_LANG_C_plus_plus_14
:
20208 cu
->language
= language_cplus
;
20211 cu
->language
= language_d
;
20213 case DW_LANG_Fortran77
:
20214 case DW_LANG_Fortran90
:
20215 case DW_LANG_Fortran95
:
20216 case DW_LANG_Fortran03
:
20217 case DW_LANG_Fortran08
:
20218 cu
->language
= language_fortran
;
20221 cu
->language
= language_go
;
20223 case DW_LANG_Mips_Assembler
:
20224 cu
->language
= language_asm
;
20226 case DW_LANG_Ada83
:
20227 case DW_LANG_Ada95
:
20228 cu
->language
= language_ada
;
20230 case DW_LANG_Modula2
:
20231 cu
->language
= language_m2
;
20233 case DW_LANG_Pascal83
:
20234 cu
->language
= language_pascal
;
20237 cu
->language
= language_objc
;
20240 case DW_LANG_Rust_old
:
20241 cu
->language
= language_rust
;
20243 case DW_LANG_Cobol74
:
20244 case DW_LANG_Cobol85
:
20246 cu
->language
= language_minimal
;
20249 cu
->language_defn
= language_def (cu
->language
);
20252 /* Return the named attribute or NULL if not there. */
20254 static struct attribute
*
20255 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20260 struct attribute
*spec
= NULL
;
20262 for (i
= 0; i
< die
->num_attrs
; ++i
)
20264 if (die
->attrs
[i
].name
== name
)
20265 return &die
->attrs
[i
];
20266 if (die
->attrs
[i
].name
== DW_AT_specification
20267 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20268 spec
= &die
->attrs
[i
];
20274 die
= follow_die_ref (die
, spec
, &cu
);
20280 /* Return the named attribute or NULL if not there,
20281 but do not follow DW_AT_specification, etc.
20282 This is for use in contexts where we're reading .debug_types dies.
20283 Following DW_AT_specification, DW_AT_abstract_origin will take us
20284 back up the chain, and we want to go down. */
20286 static struct attribute
*
20287 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20291 for (i
= 0; i
< die
->num_attrs
; ++i
)
20292 if (die
->attrs
[i
].name
== name
)
20293 return &die
->attrs
[i
];
20298 /* Return the string associated with a string-typed attribute, or NULL if it
20299 is either not found or is of an incorrect type. */
20301 static const char *
20302 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20304 struct attribute
*attr
;
20305 const char *str
= NULL
;
20307 attr
= dwarf2_attr (die
, name
, cu
);
20311 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20312 || attr
->form
== DW_FORM_string
20313 || attr
->form
== DW_FORM_GNU_str_index
20314 || attr
->form
== DW_FORM_GNU_strp_alt
)
20315 str
= DW_STRING (attr
);
20317 complaint (&symfile_complaints
,
20318 _("string type expected for attribute %s for "
20319 "DIE at %s in module %s"),
20320 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20321 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20327 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20328 and holds a non-zero value. This function should only be used for
20329 DW_FORM_flag or DW_FORM_flag_present attributes. */
20332 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20334 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20336 return (attr
&& DW_UNSND (attr
));
20340 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20342 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20343 which value is non-zero. However, we have to be careful with
20344 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20345 (via dwarf2_flag_true_p) follows this attribute. So we may
20346 end up accidently finding a declaration attribute that belongs
20347 to a different DIE referenced by the specification attribute,
20348 even though the given DIE does not have a declaration attribute. */
20349 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20350 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20353 /* Return the die giving the specification for DIE, if there is
20354 one. *SPEC_CU is the CU containing DIE on input, and the CU
20355 containing the return value on output. If there is no
20356 specification, but there is an abstract origin, that is
20359 static struct die_info
*
20360 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20362 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20365 if (spec_attr
== NULL
)
20366 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20368 if (spec_attr
== NULL
)
20371 return follow_die_ref (die
, spec_attr
, spec_cu
);
20374 /* Stub for free_line_header to match void * callback types. */
20377 free_line_header_voidp (void *arg
)
20379 struct line_header
*lh
= (struct line_header
*) arg
;
20385 line_header::add_include_dir (const char *include_dir
)
20387 if (dwarf_line_debug
>= 2)
20388 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20389 include_dirs
.size () + 1, include_dir
);
20391 include_dirs
.push_back (include_dir
);
20395 line_header::add_file_name (const char *name
,
20397 unsigned int mod_time
,
20398 unsigned int length
)
20400 if (dwarf_line_debug
>= 2)
20401 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20402 (unsigned) file_names
.size () + 1, name
);
20404 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20407 /* A convenience function to find the proper .debug_line section for a CU. */
20409 static struct dwarf2_section_info
*
20410 get_debug_line_section (struct dwarf2_cu
*cu
)
20412 struct dwarf2_section_info
*section
;
20413 struct dwarf2_per_objfile
*dwarf2_per_objfile
20414 = cu
->per_cu
->dwarf2_per_objfile
;
20416 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20418 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20419 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20420 else if (cu
->per_cu
->is_dwz
)
20422 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20424 section
= &dwz
->line
;
20427 section
= &dwarf2_per_objfile
->line
;
20432 /* Read directory or file name entry format, starting with byte of
20433 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20434 entries count and the entries themselves in the described entry
20438 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20439 bfd
*abfd
, const gdb_byte
**bufp
,
20440 struct line_header
*lh
,
20441 const struct comp_unit_head
*cu_header
,
20442 void (*callback
) (struct line_header
*lh
,
20445 unsigned int mod_time
,
20446 unsigned int length
))
20448 gdb_byte format_count
, formati
;
20449 ULONGEST data_count
, datai
;
20450 const gdb_byte
*buf
= *bufp
;
20451 const gdb_byte
*format_header_data
;
20452 unsigned int bytes_read
;
20454 format_count
= read_1_byte (abfd
, buf
);
20456 format_header_data
= buf
;
20457 for (formati
= 0; formati
< format_count
; formati
++)
20459 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20461 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20465 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20467 for (datai
= 0; datai
< data_count
; datai
++)
20469 const gdb_byte
*format
= format_header_data
;
20470 struct file_entry fe
;
20472 for (formati
= 0; formati
< format_count
; formati
++)
20474 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20475 format
+= bytes_read
;
20477 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20478 format
+= bytes_read
;
20480 gdb::optional
<const char *> string
;
20481 gdb::optional
<unsigned int> uint
;
20485 case DW_FORM_string
:
20486 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20490 case DW_FORM_line_strp
:
20491 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20498 case DW_FORM_data1
:
20499 uint
.emplace (read_1_byte (abfd
, buf
));
20503 case DW_FORM_data2
:
20504 uint
.emplace (read_2_bytes (abfd
, buf
));
20508 case DW_FORM_data4
:
20509 uint
.emplace (read_4_bytes (abfd
, buf
));
20513 case DW_FORM_data8
:
20514 uint
.emplace (read_8_bytes (abfd
, buf
));
20518 case DW_FORM_udata
:
20519 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20523 case DW_FORM_block
:
20524 /* It is valid only for DW_LNCT_timestamp which is ignored by
20529 switch (content_type
)
20532 if (string
.has_value ())
20535 case DW_LNCT_directory_index
:
20536 if (uint
.has_value ())
20537 fe
.d_index
= (dir_index
) *uint
;
20539 case DW_LNCT_timestamp
:
20540 if (uint
.has_value ())
20541 fe
.mod_time
= *uint
;
20544 if (uint
.has_value ())
20550 complaint (&symfile_complaints
,
20551 _("Unknown format content type %s"),
20552 pulongest (content_type
));
20556 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20562 /* Read the statement program header starting at OFFSET in
20563 .debug_line, or .debug_line.dwo. Return a pointer
20564 to a struct line_header, allocated using xmalloc.
20565 Returns NULL if there is a problem reading the header, e.g., if it
20566 has a version we don't understand.
20568 NOTE: the strings in the include directory and file name tables of
20569 the returned object point into the dwarf line section buffer,
20570 and must not be freed. */
20572 static line_header_up
20573 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20575 const gdb_byte
*line_ptr
;
20576 unsigned int bytes_read
, offset_size
;
20578 const char *cur_dir
, *cur_file
;
20579 struct dwarf2_section_info
*section
;
20581 struct dwarf2_per_objfile
*dwarf2_per_objfile
20582 = cu
->per_cu
->dwarf2_per_objfile
;
20584 section
= get_debug_line_section (cu
);
20585 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20586 if (section
->buffer
== NULL
)
20588 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20589 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20591 complaint (&symfile_complaints
, _("missing .debug_line section"));
20595 /* We can't do this until we know the section is non-empty.
20596 Only then do we know we have such a section. */
20597 abfd
= get_section_bfd_owner (section
);
20599 /* Make sure that at least there's room for the total_length field.
20600 That could be 12 bytes long, but we're just going to fudge that. */
20601 if (to_underlying (sect_off
) + 4 >= section
->size
)
20603 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20607 line_header_up
lh (new line_header ());
20609 lh
->sect_off
= sect_off
;
20610 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20612 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20614 /* Read in the header. */
20616 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20617 &bytes_read
, &offset_size
);
20618 line_ptr
+= bytes_read
;
20619 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20621 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20624 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20625 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20627 if (lh
->version
> 5)
20629 /* This is a version we don't understand. The format could have
20630 changed in ways we don't handle properly so just punt. */
20631 complaint (&symfile_complaints
,
20632 _("unsupported version in .debug_line section"));
20635 if (lh
->version
>= 5)
20637 gdb_byte segment_selector_size
;
20639 /* Skip address size. */
20640 read_1_byte (abfd
, line_ptr
);
20643 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20645 if (segment_selector_size
!= 0)
20647 complaint (&symfile_complaints
,
20648 _("unsupported segment selector size %u "
20649 "in .debug_line section"),
20650 segment_selector_size
);
20654 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20655 line_ptr
+= offset_size
;
20656 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20658 if (lh
->version
>= 4)
20660 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20664 lh
->maximum_ops_per_instruction
= 1;
20666 if (lh
->maximum_ops_per_instruction
== 0)
20668 lh
->maximum_ops_per_instruction
= 1;
20669 complaint (&symfile_complaints
,
20670 _("invalid maximum_ops_per_instruction "
20671 "in `.debug_line' section"));
20674 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20676 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20678 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20680 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20682 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20684 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20685 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20687 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20691 if (lh
->version
>= 5)
20693 /* Read directory table. */
20694 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20696 [] (struct line_header
*lh
, const char *name
,
20697 dir_index d_index
, unsigned int mod_time
,
20698 unsigned int length
)
20700 lh
->add_include_dir (name
);
20703 /* Read file name table. */
20704 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20706 [] (struct line_header
*lh
, const char *name
,
20707 dir_index d_index
, unsigned int mod_time
,
20708 unsigned int length
)
20710 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20715 /* Read directory table. */
20716 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20718 line_ptr
+= bytes_read
;
20719 lh
->add_include_dir (cur_dir
);
20721 line_ptr
+= bytes_read
;
20723 /* Read file name table. */
20724 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20726 unsigned int mod_time
, length
;
20729 line_ptr
+= bytes_read
;
20730 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20731 line_ptr
+= bytes_read
;
20732 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20733 line_ptr
+= bytes_read
;
20734 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20735 line_ptr
+= bytes_read
;
20737 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20739 line_ptr
+= bytes_read
;
20741 lh
->statement_program_start
= line_ptr
;
20743 if (line_ptr
> (section
->buffer
+ section
->size
))
20744 complaint (&symfile_complaints
,
20745 _("line number info header doesn't "
20746 "fit in `.debug_line' section"));
20751 /* Subroutine of dwarf_decode_lines to simplify it.
20752 Return the file name of the psymtab for included file FILE_INDEX
20753 in line header LH of PST.
20754 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20755 If space for the result is malloc'd, *NAME_HOLDER will be set.
20756 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20758 static const char *
20759 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20760 const struct partial_symtab
*pst
,
20761 const char *comp_dir
,
20762 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20764 const file_entry
&fe
= lh
->file_names
[file_index
];
20765 const char *include_name
= fe
.name
;
20766 const char *include_name_to_compare
= include_name
;
20767 const char *pst_filename
;
20770 const char *dir_name
= fe
.include_dir (lh
);
20772 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20773 if (!IS_ABSOLUTE_PATH (include_name
)
20774 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20776 /* Avoid creating a duplicate psymtab for PST.
20777 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20778 Before we do the comparison, however, we need to account
20779 for DIR_NAME and COMP_DIR.
20780 First prepend dir_name (if non-NULL). If we still don't
20781 have an absolute path prepend comp_dir (if non-NULL).
20782 However, the directory we record in the include-file's
20783 psymtab does not contain COMP_DIR (to match the
20784 corresponding symtab(s)).
20789 bash$ gcc -g ./hello.c
20790 include_name = "hello.c"
20792 DW_AT_comp_dir = comp_dir = "/tmp"
20793 DW_AT_name = "./hello.c"
20797 if (dir_name
!= NULL
)
20799 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20800 include_name
, (char *) NULL
));
20801 include_name
= name_holder
->get ();
20802 include_name_to_compare
= include_name
;
20804 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20806 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20807 include_name
, (char *) NULL
));
20808 include_name_to_compare
= hold_compare
.get ();
20812 pst_filename
= pst
->filename
;
20813 gdb::unique_xmalloc_ptr
<char> copied_name
;
20814 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20816 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20817 pst_filename
, (char *) NULL
));
20818 pst_filename
= copied_name
.get ();
20821 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20825 return include_name
;
20828 /* State machine to track the state of the line number program. */
20830 class lnp_state_machine
20833 /* Initialize a machine state for the start of a line number
20835 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20837 file_entry
*current_file ()
20839 /* lh->file_names is 0-based, but the file name numbers in the
20840 statement program are 1-based. */
20841 return m_line_header
->file_name_at (m_file
);
20844 /* Record the line in the state machine. END_SEQUENCE is true if
20845 we're processing the end of a sequence. */
20846 void record_line (bool end_sequence
);
20848 /* Check address and if invalid nop-out the rest of the lines in this
20850 void check_line_address (struct dwarf2_cu
*cu
,
20851 const gdb_byte
*line_ptr
,
20852 CORE_ADDR lowpc
, CORE_ADDR address
);
20854 void handle_set_discriminator (unsigned int discriminator
)
20856 m_discriminator
= discriminator
;
20857 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20860 /* Handle DW_LNE_set_address. */
20861 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20864 address
+= baseaddr
;
20865 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20868 /* Handle DW_LNS_advance_pc. */
20869 void handle_advance_pc (CORE_ADDR adjust
);
20871 /* Handle a special opcode. */
20872 void handle_special_opcode (unsigned char op_code
);
20874 /* Handle DW_LNS_advance_line. */
20875 void handle_advance_line (int line_delta
)
20877 advance_line (line_delta
);
20880 /* Handle DW_LNS_set_file. */
20881 void handle_set_file (file_name_index file
);
20883 /* Handle DW_LNS_negate_stmt. */
20884 void handle_negate_stmt ()
20886 m_is_stmt
= !m_is_stmt
;
20889 /* Handle DW_LNS_const_add_pc. */
20890 void handle_const_add_pc ();
20892 /* Handle DW_LNS_fixed_advance_pc. */
20893 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20895 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20899 /* Handle DW_LNS_copy. */
20900 void handle_copy ()
20902 record_line (false);
20903 m_discriminator
= 0;
20906 /* Handle DW_LNE_end_sequence. */
20907 void handle_end_sequence ()
20909 m_record_line_callback
= ::record_line
;
20913 /* Advance the line by LINE_DELTA. */
20914 void advance_line (int line_delta
)
20916 m_line
+= line_delta
;
20918 if (line_delta
!= 0)
20919 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20922 gdbarch
*m_gdbarch
;
20924 /* True if we're recording lines.
20925 Otherwise we're building partial symtabs and are just interested in
20926 finding include files mentioned by the line number program. */
20927 bool m_record_lines_p
;
20929 /* The line number header. */
20930 line_header
*m_line_header
;
20932 /* These are part of the standard DWARF line number state machine,
20933 and initialized according to the DWARF spec. */
20935 unsigned char m_op_index
= 0;
20936 /* The line table index (1-based) of the current file. */
20937 file_name_index m_file
= (file_name_index
) 1;
20938 unsigned int m_line
= 1;
20940 /* These are initialized in the constructor. */
20942 CORE_ADDR m_address
;
20944 unsigned int m_discriminator
;
20946 /* Additional bits of state we need to track. */
20948 /* The last file that we called dwarf2_start_subfile for.
20949 This is only used for TLLs. */
20950 unsigned int m_last_file
= 0;
20951 /* The last file a line number was recorded for. */
20952 struct subfile
*m_last_subfile
= NULL
;
20954 /* The function to call to record a line. */
20955 record_line_ftype
*m_record_line_callback
= NULL
;
20957 /* The last line number that was recorded, used to coalesce
20958 consecutive entries for the same line. This can happen, for
20959 example, when discriminators are present. PR 17276. */
20960 unsigned int m_last_line
= 0;
20961 bool m_line_has_non_zero_discriminator
= false;
20965 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20967 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20968 / m_line_header
->maximum_ops_per_instruction
)
20969 * m_line_header
->minimum_instruction_length
);
20970 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20971 m_op_index
= ((m_op_index
+ adjust
)
20972 % m_line_header
->maximum_ops_per_instruction
);
20976 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20978 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20979 CORE_ADDR addr_adj
= (((m_op_index
20980 + (adj_opcode
/ m_line_header
->line_range
))
20981 / m_line_header
->maximum_ops_per_instruction
)
20982 * m_line_header
->minimum_instruction_length
);
20983 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20984 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20985 % m_line_header
->maximum_ops_per_instruction
);
20987 int line_delta
= (m_line_header
->line_base
20988 + (adj_opcode
% m_line_header
->line_range
));
20989 advance_line (line_delta
);
20990 record_line (false);
20991 m_discriminator
= 0;
20995 lnp_state_machine::handle_set_file (file_name_index file
)
20999 const file_entry
*fe
= current_file ();
21001 dwarf2_debug_line_missing_file_complaint ();
21002 else if (m_record_lines_p
)
21004 const char *dir
= fe
->include_dir (m_line_header
);
21006 m_last_subfile
= current_subfile
;
21007 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21008 dwarf2_start_subfile (fe
->name
, dir
);
21013 lnp_state_machine::handle_const_add_pc ()
21016 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21019 = (((m_op_index
+ adjust
)
21020 / m_line_header
->maximum_ops_per_instruction
)
21021 * m_line_header
->minimum_instruction_length
);
21023 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21024 m_op_index
= ((m_op_index
+ adjust
)
21025 % m_line_header
->maximum_ops_per_instruction
);
21028 /* Ignore this record_line request. */
21031 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
21036 /* Return non-zero if we should add LINE to the line number table.
21037 LINE is the line to add, LAST_LINE is the last line that was added,
21038 LAST_SUBFILE is the subfile for LAST_LINE.
21039 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21040 had a non-zero discriminator.
21042 We have to be careful in the presence of discriminators.
21043 E.g., for this line:
21045 for (i = 0; i < 100000; i++);
21047 clang can emit four line number entries for that one line,
21048 each with a different discriminator.
21049 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21051 However, we want gdb to coalesce all four entries into one.
21052 Otherwise the user could stepi into the middle of the line and
21053 gdb would get confused about whether the pc really was in the
21054 middle of the line.
21056 Things are further complicated by the fact that two consecutive
21057 line number entries for the same line is a heuristic used by gcc
21058 to denote the end of the prologue. So we can't just discard duplicate
21059 entries, we have to be selective about it. The heuristic we use is
21060 that we only collapse consecutive entries for the same line if at least
21061 one of those entries has a non-zero discriminator. PR 17276.
21063 Note: Addresses in the line number state machine can never go backwards
21064 within one sequence, thus this coalescing is ok. */
21067 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
21068 int line_has_non_zero_discriminator
,
21069 struct subfile
*last_subfile
)
21071 if (current_subfile
!= last_subfile
)
21073 if (line
!= last_line
)
21075 /* Same line for the same file that we've seen already.
21076 As a last check, for pr 17276, only record the line if the line
21077 has never had a non-zero discriminator. */
21078 if (!line_has_non_zero_discriminator
)
21083 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
21084 in the line table of subfile SUBFILE. */
21087 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21088 unsigned int line
, CORE_ADDR address
,
21089 record_line_ftype p_record_line
)
21091 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21093 if (dwarf_line_debug
)
21095 fprintf_unfiltered (gdb_stdlog
,
21096 "Recording line %u, file %s, address %s\n",
21097 line
, lbasename (subfile
->name
),
21098 paddress (gdbarch
, address
));
21101 (*p_record_line
) (subfile
, line
, addr
);
21104 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21105 Mark the end of a set of line number records.
21106 The arguments are the same as for dwarf_record_line_1.
21107 If SUBFILE is NULL the request is ignored. */
21110 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21111 CORE_ADDR address
, record_line_ftype p_record_line
)
21113 if (subfile
== NULL
)
21116 if (dwarf_line_debug
)
21118 fprintf_unfiltered (gdb_stdlog
,
21119 "Finishing current line, file %s, address %s\n",
21120 lbasename (subfile
->name
),
21121 paddress (gdbarch
, address
));
21124 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
21128 lnp_state_machine::record_line (bool end_sequence
)
21130 if (dwarf_line_debug
)
21132 fprintf_unfiltered (gdb_stdlog
,
21133 "Processing actual line %u: file %u,"
21134 " address %s, is_stmt %u, discrim %u\n",
21135 m_line
, to_underlying (m_file
),
21136 paddress (m_gdbarch
, m_address
),
21137 m_is_stmt
, m_discriminator
);
21140 file_entry
*fe
= current_file ();
21143 dwarf2_debug_line_missing_file_complaint ();
21144 /* For now we ignore lines not starting on an instruction boundary.
21145 But not when processing end_sequence for compatibility with the
21146 previous version of the code. */
21147 else if (m_op_index
== 0 || end_sequence
)
21149 fe
->included_p
= 1;
21150 if (m_record_lines_p
&& m_is_stmt
)
21152 if (m_last_subfile
!= current_subfile
|| end_sequence
)
21154 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
21155 m_address
, m_record_line_callback
);
21160 if (dwarf_record_line_p (m_line
, m_last_line
,
21161 m_line_has_non_zero_discriminator
,
21164 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
21166 m_record_line_callback
);
21168 m_last_subfile
= current_subfile
;
21169 m_last_line
= m_line
;
21175 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
21176 bool record_lines_p
)
21179 m_record_lines_p
= record_lines_p
;
21180 m_line_header
= lh
;
21182 m_record_line_callback
= ::record_line
;
21184 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21185 was a line entry for it so that the backend has a chance to adjust it
21186 and also record it in case it needs it. This is currently used by MIPS
21187 code, cf. `mips_adjust_dwarf2_line'. */
21188 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21189 m_is_stmt
= lh
->default_is_stmt
;
21190 m_discriminator
= 0;
21194 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21195 const gdb_byte
*line_ptr
,
21196 CORE_ADDR lowpc
, CORE_ADDR address
)
21198 /* If address < lowpc then it's not a usable value, it's outside the
21199 pc range of the CU. However, we restrict the test to only address
21200 values of zero to preserve GDB's previous behaviour which is to
21201 handle the specific case of a function being GC'd by the linker. */
21203 if (address
== 0 && address
< lowpc
)
21205 /* This line table is for a function which has been
21206 GCd by the linker. Ignore it. PR gdb/12528 */
21208 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21209 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21211 complaint (&symfile_complaints
,
21212 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21213 line_offset
, objfile_name (objfile
));
21214 m_record_line_callback
= noop_record_line
;
21215 /* Note: record_line_callback is left as noop_record_line until
21216 we see DW_LNE_end_sequence. */
21220 /* Subroutine of dwarf_decode_lines to simplify it.
21221 Process the line number information in LH.
21222 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21223 program in order to set included_p for every referenced header. */
21226 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21227 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21229 const gdb_byte
*line_ptr
, *extended_end
;
21230 const gdb_byte
*line_end
;
21231 unsigned int bytes_read
, extended_len
;
21232 unsigned char op_code
, extended_op
;
21233 CORE_ADDR baseaddr
;
21234 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21235 bfd
*abfd
= objfile
->obfd
;
21236 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21237 /* True if we're recording line info (as opposed to building partial
21238 symtabs and just interested in finding include files mentioned by
21239 the line number program). */
21240 bool record_lines_p
= !decode_for_pst_p
;
21242 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21244 line_ptr
= lh
->statement_program_start
;
21245 line_end
= lh
->statement_program_end
;
21247 /* Read the statement sequences until there's nothing left. */
21248 while (line_ptr
< line_end
)
21250 /* The DWARF line number program state machine. Reset the state
21251 machine at the start of each sequence. */
21252 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
21253 bool end_sequence
= false;
21255 if (record_lines_p
)
21257 /* Start a subfile for the current file of the state
21259 const file_entry
*fe
= state_machine
.current_file ();
21262 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
21265 /* Decode the table. */
21266 while (line_ptr
< line_end
&& !end_sequence
)
21268 op_code
= read_1_byte (abfd
, line_ptr
);
21271 if (op_code
>= lh
->opcode_base
)
21273 /* Special opcode. */
21274 state_machine
.handle_special_opcode (op_code
);
21276 else switch (op_code
)
21278 case DW_LNS_extended_op
:
21279 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21281 line_ptr
+= bytes_read
;
21282 extended_end
= line_ptr
+ extended_len
;
21283 extended_op
= read_1_byte (abfd
, line_ptr
);
21285 switch (extended_op
)
21287 case DW_LNE_end_sequence
:
21288 state_machine
.handle_end_sequence ();
21289 end_sequence
= true;
21291 case DW_LNE_set_address
:
21294 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21295 line_ptr
+= bytes_read
;
21297 state_machine
.check_line_address (cu
, line_ptr
,
21299 state_machine
.handle_set_address (baseaddr
, address
);
21302 case DW_LNE_define_file
:
21304 const char *cur_file
;
21305 unsigned int mod_time
, length
;
21308 cur_file
= read_direct_string (abfd
, line_ptr
,
21310 line_ptr
+= bytes_read
;
21311 dindex
= (dir_index
)
21312 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21313 line_ptr
+= bytes_read
;
21315 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21316 line_ptr
+= bytes_read
;
21318 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21319 line_ptr
+= bytes_read
;
21320 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21323 case DW_LNE_set_discriminator
:
21325 /* The discriminator is not interesting to the
21326 debugger; just ignore it. We still need to
21327 check its value though:
21328 if there are consecutive entries for the same
21329 (non-prologue) line we want to coalesce them.
21332 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21333 line_ptr
+= bytes_read
;
21335 state_machine
.handle_set_discriminator (discr
);
21339 complaint (&symfile_complaints
,
21340 _("mangled .debug_line section"));
21343 /* Make sure that we parsed the extended op correctly. If e.g.
21344 we expected a different address size than the producer used,
21345 we may have read the wrong number of bytes. */
21346 if (line_ptr
!= extended_end
)
21348 complaint (&symfile_complaints
,
21349 _("mangled .debug_line section"));
21354 state_machine
.handle_copy ();
21356 case DW_LNS_advance_pc
:
21359 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21360 line_ptr
+= bytes_read
;
21362 state_machine
.handle_advance_pc (adjust
);
21365 case DW_LNS_advance_line
:
21368 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21369 line_ptr
+= bytes_read
;
21371 state_machine
.handle_advance_line (line_delta
);
21374 case DW_LNS_set_file
:
21376 file_name_index file
21377 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21379 line_ptr
+= bytes_read
;
21381 state_machine
.handle_set_file (file
);
21384 case DW_LNS_set_column
:
21385 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21386 line_ptr
+= bytes_read
;
21388 case DW_LNS_negate_stmt
:
21389 state_machine
.handle_negate_stmt ();
21391 case DW_LNS_set_basic_block
:
21393 /* Add to the address register of the state machine the
21394 address increment value corresponding to special opcode
21395 255. I.e., this value is scaled by the minimum
21396 instruction length since special opcode 255 would have
21397 scaled the increment. */
21398 case DW_LNS_const_add_pc
:
21399 state_machine
.handle_const_add_pc ();
21401 case DW_LNS_fixed_advance_pc
:
21403 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21406 state_machine
.handle_fixed_advance_pc (addr_adj
);
21411 /* Unknown standard opcode, ignore it. */
21414 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21416 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21417 line_ptr
+= bytes_read
;
21424 dwarf2_debug_line_missing_end_sequence_complaint ();
21426 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21427 in which case we still finish recording the last line). */
21428 state_machine
.record_line (true);
21432 /* Decode the Line Number Program (LNP) for the given line_header
21433 structure and CU. The actual information extracted and the type
21434 of structures created from the LNP depends on the value of PST.
21436 1. If PST is NULL, then this procedure uses the data from the program
21437 to create all necessary symbol tables, and their linetables.
21439 2. If PST is not NULL, this procedure reads the program to determine
21440 the list of files included by the unit represented by PST, and
21441 builds all the associated partial symbol tables.
21443 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21444 It is used for relative paths in the line table.
21445 NOTE: When processing partial symtabs (pst != NULL),
21446 comp_dir == pst->dirname.
21448 NOTE: It is important that psymtabs have the same file name (via strcmp)
21449 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21450 symtab we don't use it in the name of the psymtabs we create.
21451 E.g. expand_line_sal requires this when finding psymtabs to expand.
21452 A good testcase for this is mb-inline.exp.
21454 LOWPC is the lowest address in CU (or 0 if not known).
21456 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21457 for its PC<->lines mapping information. Otherwise only the filename
21458 table is read in. */
21461 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21462 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21463 CORE_ADDR lowpc
, int decode_mapping
)
21465 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21466 const int decode_for_pst_p
= (pst
!= NULL
);
21468 if (decode_mapping
)
21469 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21471 if (decode_for_pst_p
)
21475 /* Now that we're done scanning the Line Header Program, we can
21476 create the psymtab of each included file. */
21477 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21478 if (lh
->file_names
[file_index
].included_p
== 1)
21480 gdb::unique_xmalloc_ptr
<char> name_holder
;
21481 const char *include_name
=
21482 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21484 if (include_name
!= NULL
)
21485 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21490 /* Make sure a symtab is created for every file, even files
21491 which contain only variables (i.e. no code with associated
21493 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21496 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21498 file_entry
&fe
= lh
->file_names
[i
];
21500 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21502 if (current_subfile
->symtab
== NULL
)
21504 current_subfile
->symtab
21505 = allocate_symtab (cust
, current_subfile
->name
);
21507 fe
.symtab
= current_subfile
->symtab
;
21512 /* Start a subfile for DWARF. FILENAME is the name of the file and
21513 DIRNAME the name of the source directory which contains FILENAME
21514 or NULL if not known.
21515 This routine tries to keep line numbers from identical absolute and
21516 relative file names in a common subfile.
21518 Using the `list' example from the GDB testsuite, which resides in
21519 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21520 of /srcdir/list0.c yields the following debugging information for list0.c:
21522 DW_AT_name: /srcdir/list0.c
21523 DW_AT_comp_dir: /compdir
21524 files.files[0].name: list0.h
21525 files.files[0].dir: /srcdir
21526 files.files[1].name: list0.c
21527 files.files[1].dir: /srcdir
21529 The line number information for list0.c has to end up in a single
21530 subfile, so that `break /srcdir/list0.c:1' works as expected.
21531 start_subfile will ensure that this happens provided that we pass the
21532 concatenation of files.files[1].dir and files.files[1].name as the
21536 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21540 /* In order not to lose the line information directory,
21541 we concatenate it to the filename when it makes sense.
21542 Note that the Dwarf3 standard says (speaking of filenames in line
21543 information): ``The directory index is ignored for file names
21544 that represent full path names''. Thus ignoring dirname in the
21545 `else' branch below isn't an issue. */
21547 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21549 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21553 start_subfile (filename
);
21559 /* Start a symtab for DWARF.
21560 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21562 static struct compunit_symtab
*
21563 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21564 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21566 struct compunit_symtab
*cust
21567 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21568 low_pc
, cu
->language
);
21570 record_debugformat ("DWARF 2");
21571 record_producer (cu
->producer
);
21573 /* We assume that we're processing GCC output. */
21574 processing_gcc_compilation
= 2;
21576 cu
->processing_has_namespace_info
= 0;
21582 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21583 struct dwarf2_cu
*cu
)
21585 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21586 struct comp_unit_head
*cu_header
= &cu
->header
;
21588 /* NOTE drow/2003-01-30: There used to be a comment and some special
21589 code here to turn a symbol with DW_AT_external and a
21590 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21591 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21592 with some versions of binutils) where shared libraries could have
21593 relocations against symbols in their debug information - the
21594 minimal symbol would have the right address, but the debug info
21595 would not. It's no longer necessary, because we will explicitly
21596 apply relocations when we read in the debug information now. */
21598 /* A DW_AT_location attribute with no contents indicates that a
21599 variable has been optimized away. */
21600 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21602 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21606 /* Handle one degenerate form of location expression specially, to
21607 preserve GDB's previous behavior when section offsets are
21608 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21609 then mark this symbol as LOC_STATIC. */
21611 if (attr_form_is_block (attr
)
21612 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21613 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21614 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21615 && (DW_BLOCK (attr
)->size
21616 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21618 unsigned int dummy
;
21620 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21621 SYMBOL_VALUE_ADDRESS (sym
) =
21622 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21624 SYMBOL_VALUE_ADDRESS (sym
) =
21625 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21626 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21627 fixup_symbol_section (sym
, objfile
);
21628 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21629 SYMBOL_SECTION (sym
));
21633 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21634 expression evaluator, and use LOC_COMPUTED only when necessary
21635 (i.e. when the value of a register or memory location is
21636 referenced, or a thread-local block, etc.). Then again, it might
21637 not be worthwhile. I'm assuming that it isn't unless performance
21638 or memory numbers show me otherwise. */
21640 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21642 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21643 cu
->has_loclist
= 1;
21646 /* Given a pointer to a DWARF information entry, figure out if we need
21647 to make a symbol table entry for it, and if so, create a new entry
21648 and return a pointer to it.
21649 If TYPE is NULL, determine symbol type from the die, otherwise
21650 used the passed type.
21651 If SPACE is not NULL, use it to hold the new symbol. If it is
21652 NULL, allocate a new symbol on the objfile's obstack. */
21654 static struct symbol
*
21655 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21656 struct symbol
*space
)
21658 struct dwarf2_per_objfile
*dwarf2_per_objfile
21659 = cu
->per_cu
->dwarf2_per_objfile
;
21660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21661 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21662 struct symbol
*sym
= NULL
;
21664 struct attribute
*attr
= NULL
;
21665 struct attribute
*attr2
= NULL
;
21666 CORE_ADDR baseaddr
;
21667 struct pending
**list_to_add
= NULL
;
21669 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21671 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21673 name
= dwarf2_name (die
, cu
);
21676 const char *linkagename
;
21677 int suppress_add
= 0;
21682 sym
= allocate_symbol (objfile
);
21683 OBJSTAT (objfile
, n_syms
++);
21685 /* Cache this symbol's name and the name's demangled form (if any). */
21686 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21687 linkagename
= dwarf2_physname (name
, die
, cu
);
21688 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21690 /* Fortran does not have mangling standard and the mangling does differ
21691 between gfortran, iFort etc. */
21692 if (cu
->language
== language_fortran
21693 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21694 symbol_set_demangled_name (&(sym
->ginfo
),
21695 dwarf2_full_name (name
, die
, cu
),
21698 /* Default assumptions.
21699 Use the passed type or decode it from the die. */
21700 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21701 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21703 SYMBOL_TYPE (sym
) = type
;
21705 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21706 attr
= dwarf2_attr (die
,
21707 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21711 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21714 attr
= dwarf2_attr (die
,
21715 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21719 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21720 struct file_entry
*fe
;
21722 if (cu
->line_header
!= NULL
)
21723 fe
= cu
->line_header
->file_name_at (file_index
);
21728 complaint (&symfile_complaints
,
21729 _("file index out of range"));
21731 symbol_set_symtab (sym
, fe
->symtab
);
21737 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21742 addr
= attr_value_as_address (attr
);
21743 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21744 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21746 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21747 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21748 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21749 add_symbol_to_list (sym
, cu
->list_in_scope
);
21751 case DW_TAG_subprogram
:
21752 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21754 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21755 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21756 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21757 || cu
->language
== language_ada
)
21759 /* Subprograms marked external are stored as a global symbol.
21760 Ada subprograms, whether marked external or not, are always
21761 stored as a global symbol, because we want to be able to
21762 access them globally. For instance, we want to be able
21763 to break on a nested subprogram without having to
21764 specify the context. */
21765 list_to_add
= &global_symbols
;
21769 list_to_add
= cu
->list_in_scope
;
21772 case DW_TAG_inlined_subroutine
:
21773 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21775 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21776 SYMBOL_INLINED (sym
) = 1;
21777 list_to_add
= cu
->list_in_scope
;
21779 case DW_TAG_template_value_param
:
21781 /* Fall through. */
21782 case DW_TAG_constant
:
21783 case DW_TAG_variable
:
21784 case DW_TAG_member
:
21785 /* Compilation with minimal debug info may result in
21786 variables with missing type entries. Change the
21787 misleading `void' type to something sensible. */
21788 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21789 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21791 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21792 /* In the case of DW_TAG_member, we should only be called for
21793 static const members. */
21794 if (die
->tag
== DW_TAG_member
)
21796 /* dwarf2_add_field uses die_is_declaration,
21797 so we do the same. */
21798 gdb_assert (die_is_declaration (die
, cu
));
21803 dwarf2_const_value (attr
, sym
, cu
);
21804 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21807 if (attr2
&& (DW_UNSND (attr2
) != 0))
21808 list_to_add
= &global_symbols
;
21810 list_to_add
= cu
->list_in_scope
;
21814 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21817 var_decode_location (attr
, sym
, cu
);
21818 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21820 /* Fortran explicitly imports any global symbols to the local
21821 scope by DW_TAG_common_block. */
21822 if (cu
->language
== language_fortran
&& die
->parent
21823 && die
->parent
->tag
== DW_TAG_common_block
)
21826 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21827 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21828 && !dwarf2_per_objfile
->has_section_at_zero
)
21830 /* When a static variable is eliminated by the linker,
21831 the corresponding debug information is not stripped
21832 out, but the variable address is set to null;
21833 do not add such variables into symbol table. */
21835 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21837 /* Workaround gfortran PR debug/40040 - it uses
21838 DW_AT_location for variables in -fPIC libraries which may
21839 get overriden by other libraries/executable and get
21840 a different address. Resolve it by the minimal symbol
21841 which may come from inferior's executable using copy
21842 relocation. Make this workaround only for gfortran as for
21843 other compilers GDB cannot guess the minimal symbol
21844 Fortran mangling kind. */
21845 if (cu
->language
== language_fortran
&& die
->parent
21846 && die
->parent
->tag
== DW_TAG_module
21848 && startswith (cu
->producer
, "GNU Fortran"))
21849 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21851 /* A variable with DW_AT_external is never static,
21852 but it may be block-scoped. */
21853 list_to_add
= (cu
->list_in_scope
== &file_symbols
21854 ? &global_symbols
: cu
->list_in_scope
);
21857 list_to_add
= cu
->list_in_scope
;
21861 /* We do not know the address of this symbol.
21862 If it is an external symbol and we have type information
21863 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21864 The address of the variable will then be determined from
21865 the minimal symbol table whenever the variable is
21867 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21869 /* Fortran explicitly imports any global symbols to the local
21870 scope by DW_TAG_common_block. */
21871 if (cu
->language
== language_fortran
&& die
->parent
21872 && die
->parent
->tag
== DW_TAG_common_block
)
21874 /* SYMBOL_CLASS doesn't matter here because
21875 read_common_block is going to reset it. */
21877 list_to_add
= cu
->list_in_scope
;
21879 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21880 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21882 /* A variable with DW_AT_external is never static, but it
21883 may be block-scoped. */
21884 list_to_add
= (cu
->list_in_scope
== &file_symbols
21885 ? &global_symbols
: cu
->list_in_scope
);
21887 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21889 else if (!die_is_declaration (die
, cu
))
21891 /* Use the default LOC_OPTIMIZED_OUT class. */
21892 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21894 list_to_add
= cu
->list_in_scope
;
21898 case DW_TAG_formal_parameter
:
21899 /* If we are inside a function, mark this as an argument. If
21900 not, we might be looking at an argument to an inlined function
21901 when we do not have enough information to show inlined frames;
21902 pretend it's a local variable in that case so that the user can
21904 if (context_stack_depth
> 0
21905 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21906 SYMBOL_IS_ARGUMENT (sym
) = 1;
21907 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21910 var_decode_location (attr
, sym
, cu
);
21912 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21915 dwarf2_const_value (attr
, sym
, cu
);
21918 list_to_add
= cu
->list_in_scope
;
21920 case DW_TAG_unspecified_parameters
:
21921 /* From varargs functions; gdb doesn't seem to have any
21922 interest in this information, so just ignore it for now.
21925 case DW_TAG_template_type_param
:
21927 /* Fall through. */
21928 case DW_TAG_class_type
:
21929 case DW_TAG_interface_type
:
21930 case DW_TAG_structure_type
:
21931 case DW_TAG_union_type
:
21932 case DW_TAG_set_type
:
21933 case DW_TAG_enumeration_type
:
21934 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21935 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21938 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21939 really ever be static objects: otherwise, if you try
21940 to, say, break of a class's method and you're in a file
21941 which doesn't mention that class, it won't work unless
21942 the check for all static symbols in lookup_symbol_aux
21943 saves you. See the OtherFileClass tests in
21944 gdb.c++/namespace.exp. */
21948 list_to_add
= (cu
->list_in_scope
== &file_symbols
21949 && cu
->language
== language_cplus
21950 ? &global_symbols
: cu
->list_in_scope
);
21952 /* The semantics of C++ state that "struct foo {
21953 ... }" also defines a typedef for "foo". */
21954 if (cu
->language
== language_cplus
21955 || cu
->language
== language_ada
21956 || cu
->language
== language_d
21957 || cu
->language
== language_rust
)
21959 /* The symbol's name is already allocated along
21960 with this objfile, so we don't need to
21961 duplicate it for the type. */
21962 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21963 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21968 case DW_TAG_typedef
:
21969 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21970 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21971 list_to_add
= cu
->list_in_scope
;
21973 case DW_TAG_base_type
:
21974 case DW_TAG_subrange_type
:
21975 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21976 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21977 list_to_add
= cu
->list_in_scope
;
21979 case DW_TAG_enumerator
:
21980 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21983 dwarf2_const_value (attr
, sym
, cu
);
21986 /* NOTE: carlton/2003-11-10: See comment above in the
21987 DW_TAG_class_type, etc. block. */
21989 list_to_add
= (cu
->list_in_scope
== &file_symbols
21990 && cu
->language
== language_cplus
21991 ? &global_symbols
: cu
->list_in_scope
);
21994 case DW_TAG_imported_declaration
:
21995 case DW_TAG_namespace
:
21996 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21997 list_to_add
= &global_symbols
;
21999 case DW_TAG_module
:
22000 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22001 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22002 list_to_add
= &global_symbols
;
22004 case DW_TAG_common_block
:
22005 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22006 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22007 add_symbol_to_list (sym
, cu
->list_in_scope
);
22010 /* Not a tag we recognize. Hopefully we aren't processing
22011 trash data, but since we must specifically ignore things
22012 we don't recognize, there is nothing else we should do at
22014 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
22015 dwarf_tag_name (die
->tag
));
22021 sym
->hash_next
= objfile
->template_symbols
;
22022 objfile
->template_symbols
= sym
;
22023 list_to_add
= NULL
;
22026 if (list_to_add
!= NULL
)
22027 add_symbol_to_list (sym
, list_to_add
);
22029 /* For the benefit of old versions of GCC, check for anonymous
22030 namespaces based on the demangled name. */
22031 if (!cu
->processing_has_namespace_info
22032 && cu
->language
== language_cplus
)
22033 cp_scan_for_anonymous_namespaces (sym
, objfile
);
22038 /* Given an attr with a DW_FORM_dataN value in host byte order,
22039 zero-extend it as appropriate for the symbol's type. The DWARF
22040 standard (v4) is not entirely clear about the meaning of using
22041 DW_FORM_dataN for a constant with a signed type, where the type is
22042 wider than the data. The conclusion of a discussion on the DWARF
22043 list was that this is unspecified. We choose to always zero-extend
22044 because that is the interpretation long in use by GCC. */
22047 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22048 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22050 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22051 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22052 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22053 LONGEST l
= DW_UNSND (attr
);
22055 if (bits
< sizeof (*value
) * 8)
22057 l
&= ((LONGEST
) 1 << bits
) - 1;
22060 else if (bits
== sizeof (*value
) * 8)
22064 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22065 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22072 /* Read a constant value from an attribute. Either set *VALUE, or if
22073 the value does not fit in *VALUE, set *BYTES - either already
22074 allocated on the objfile obstack, or newly allocated on OBSTACK,
22075 or, set *BATON, if we translated the constant to a location
22079 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22080 const char *name
, struct obstack
*obstack
,
22081 struct dwarf2_cu
*cu
,
22082 LONGEST
*value
, const gdb_byte
**bytes
,
22083 struct dwarf2_locexpr_baton
**baton
)
22085 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22086 struct comp_unit_head
*cu_header
= &cu
->header
;
22087 struct dwarf_block
*blk
;
22088 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22089 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22095 switch (attr
->form
)
22098 case DW_FORM_GNU_addr_index
:
22102 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22103 dwarf2_const_value_length_mismatch_complaint (name
,
22104 cu_header
->addr_size
,
22105 TYPE_LENGTH (type
));
22106 /* Symbols of this form are reasonably rare, so we just
22107 piggyback on the existing location code rather than writing
22108 a new implementation of symbol_computed_ops. */
22109 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22110 (*baton
)->per_cu
= cu
->per_cu
;
22111 gdb_assert ((*baton
)->per_cu
);
22113 (*baton
)->size
= 2 + cu_header
->addr_size
;
22114 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22115 (*baton
)->data
= data
;
22117 data
[0] = DW_OP_addr
;
22118 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22119 byte_order
, DW_ADDR (attr
));
22120 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22123 case DW_FORM_string
:
22125 case DW_FORM_GNU_str_index
:
22126 case DW_FORM_GNU_strp_alt
:
22127 /* DW_STRING is already allocated on the objfile obstack, point
22129 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22131 case DW_FORM_block1
:
22132 case DW_FORM_block2
:
22133 case DW_FORM_block4
:
22134 case DW_FORM_block
:
22135 case DW_FORM_exprloc
:
22136 case DW_FORM_data16
:
22137 blk
= DW_BLOCK (attr
);
22138 if (TYPE_LENGTH (type
) != blk
->size
)
22139 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22140 TYPE_LENGTH (type
));
22141 *bytes
= blk
->data
;
22144 /* The DW_AT_const_value attributes are supposed to carry the
22145 symbol's value "represented as it would be on the target
22146 architecture." By the time we get here, it's already been
22147 converted to host endianness, so we just need to sign- or
22148 zero-extend it as appropriate. */
22149 case DW_FORM_data1
:
22150 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22152 case DW_FORM_data2
:
22153 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22155 case DW_FORM_data4
:
22156 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22158 case DW_FORM_data8
:
22159 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22162 case DW_FORM_sdata
:
22163 case DW_FORM_implicit_const
:
22164 *value
= DW_SND (attr
);
22167 case DW_FORM_udata
:
22168 *value
= DW_UNSND (attr
);
22172 complaint (&symfile_complaints
,
22173 _("unsupported const value attribute form: '%s'"),
22174 dwarf_form_name (attr
->form
));
22181 /* Copy constant value from an attribute to a symbol. */
22184 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22185 struct dwarf2_cu
*cu
)
22187 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22189 const gdb_byte
*bytes
;
22190 struct dwarf2_locexpr_baton
*baton
;
22192 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22193 SYMBOL_PRINT_NAME (sym
),
22194 &objfile
->objfile_obstack
, cu
,
22195 &value
, &bytes
, &baton
);
22199 SYMBOL_LOCATION_BATON (sym
) = baton
;
22200 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22202 else if (bytes
!= NULL
)
22204 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22205 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22209 SYMBOL_VALUE (sym
) = value
;
22210 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22214 /* Return the type of the die in question using its DW_AT_type attribute. */
22216 static struct type
*
22217 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22219 struct attribute
*type_attr
;
22221 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22224 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22225 /* A missing DW_AT_type represents a void type. */
22226 return objfile_type (objfile
)->builtin_void
;
22229 return lookup_die_type (die
, type_attr
, cu
);
22232 /* True iff CU's producer generates GNAT Ada auxiliary information
22233 that allows to find parallel types through that information instead
22234 of having to do expensive parallel lookups by type name. */
22237 need_gnat_info (struct dwarf2_cu
*cu
)
22239 /* Assume that the Ada compiler was GNAT, which always produces
22240 the auxiliary information. */
22241 return (cu
->language
== language_ada
);
22244 /* Return the auxiliary type of the die in question using its
22245 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22246 attribute is not present. */
22248 static struct type
*
22249 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22251 struct attribute
*type_attr
;
22253 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22257 return lookup_die_type (die
, type_attr
, cu
);
22260 /* If DIE has a descriptive_type attribute, then set the TYPE's
22261 descriptive type accordingly. */
22264 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22265 struct dwarf2_cu
*cu
)
22267 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22269 if (descriptive_type
)
22271 ALLOCATE_GNAT_AUX_TYPE (type
);
22272 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22276 /* Return the containing type of the die in question using its
22277 DW_AT_containing_type attribute. */
22279 static struct type
*
22280 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22282 struct attribute
*type_attr
;
22283 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22285 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22287 error (_("Dwarf Error: Problem turning containing type into gdb type "
22288 "[in module %s]"), objfile_name (objfile
));
22290 return lookup_die_type (die
, type_attr
, cu
);
22293 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22295 static struct type
*
22296 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22298 struct dwarf2_per_objfile
*dwarf2_per_objfile
22299 = cu
->per_cu
->dwarf2_per_objfile
;
22300 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22301 char *message
, *saved
;
22303 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
22304 objfile_name (objfile
),
22305 sect_offset_str (cu
->header
.sect_off
),
22306 sect_offset_str (die
->sect_off
));
22307 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
22308 message
, strlen (message
));
22311 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22314 /* Look up the type of DIE in CU using its type attribute ATTR.
22315 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22316 DW_AT_containing_type.
22317 If there is no type substitute an error marker. */
22319 static struct type
*
22320 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22321 struct dwarf2_cu
*cu
)
22323 struct dwarf2_per_objfile
*dwarf2_per_objfile
22324 = cu
->per_cu
->dwarf2_per_objfile
;
22325 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22326 struct type
*this_type
;
22328 gdb_assert (attr
->name
== DW_AT_type
22329 || attr
->name
== DW_AT_GNAT_descriptive_type
22330 || attr
->name
== DW_AT_containing_type
);
22332 /* First see if we have it cached. */
22334 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22336 struct dwarf2_per_cu_data
*per_cu
;
22337 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22339 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22340 dwarf2_per_objfile
);
22341 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22343 else if (attr_form_is_ref (attr
))
22345 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22347 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22349 else if (attr
->form
== DW_FORM_ref_sig8
)
22351 ULONGEST signature
= DW_SIGNATURE (attr
);
22353 return get_signatured_type (die
, signature
, cu
);
22357 complaint (&symfile_complaints
,
22358 _("Dwarf Error: Bad type attribute %s in DIE"
22359 " at %s [in module %s]"),
22360 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22361 objfile_name (objfile
));
22362 return build_error_marker_type (cu
, die
);
22365 /* If not cached we need to read it in. */
22367 if (this_type
== NULL
)
22369 struct die_info
*type_die
= NULL
;
22370 struct dwarf2_cu
*type_cu
= cu
;
22372 if (attr_form_is_ref (attr
))
22373 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22374 if (type_die
== NULL
)
22375 return build_error_marker_type (cu
, die
);
22376 /* If we find the type now, it's probably because the type came
22377 from an inter-CU reference and the type's CU got expanded before
22379 this_type
= read_type_die (type_die
, type_cu
);
22382 /* If we still don't have a type use an error marker. */
22384 if (this_type
== NULL
)
22385 return build_error_marker_type (cu
, die
);
22390 /* Return the type in DIE, CU.
22391 Returns NULL for invalid types.
22393 This first does a lookup in die_type_hash,
22394 and only reads the die in if necessary.
22396 NOTE: This can be called when reading in partial or full symbols. */
22398 static struct type
*
22399 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22401 struct type
*this_type
;
22403 this_type
= get_die_type (die
, cu
);
22407 return read_type_die_1 (die
, cu
);
22410 /* Read the type in DIE, CU.
22411 Returns NULL for invalid types. */
22413 static struct type
*
22414 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22416 struct type
*this_type
= NULL
;
22420 case DW_TAG_class_type
:
22421 case DW_TAG_interface_type
:
22422 case DW_TAG_structure_type
:
22423 case DW_TAG_union_type
:
22424 this_type
= read_structure_type (die
, cu
);
22426 case DW_TAG_enumeration_type
:
22427 this_type
= read_enumeration_type (die
, cu
);
22429 case DW_TAG_subprogram
:
22430 case DW_TAG_subroutine_type
:
22431 case DW_TAG_inlined_subroutine
:
22432 this_type
= read_subroutine_type (die
, cu
);
22434 case DW_TAG_array_type
:
22435 this_type
= read_array_type (die
, cu
);
22437 case DW_TAG_set_type
:
22438 this_type
= read_set_type (die
, cu
);
22440 case DW_TAG_pointer_type
:
22441 this_type
= read_tag_pointer_type (die
, cu
);
22443 case DW_TAG_ptr_to_member_type
:
22444 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22446 case DW_TAG_reference_type
:
22447 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22449 case DW_TAG_rvalue_reference_type
:
22450 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22452 case DW_TAG_const_type
:
22453 this_type
= read_tag_const_type (die
, cu
);
22455 case DW_TAG_volatile_type
:
22456 this_type
= read_tag_volatile_type (die
, cu
);
22458 case DW_TAG_restrict_type
:
22459 this_type
= read_tag_restrict_type (die
, cu
);
22461 case DW_TAG_string_type
:
22462 this_type
= read_tag_string_type (die
, cu
);
22464 case DW_TAG_typedef
:
22465 this_type
= read_typedef (die
, cu
);
22467 case DW_TAG_subrange_type
:
22468 this_type
= read_subrange_type (die
, cu
);
22470 case DW_TAG_base_type
:
22471 this_type
= read_base_type (die
, cu
);
22473 case DW_TAG_unspecified_type
:
22474 this_type
= read_unspecified_type (die
, cu
);
22476 case DW_TAG_namespace
:
22477 this_type
= read_namespace_type (die
, cu
);
22479 case DW_TAG_module
:
22480 this_type
= read_module_type (die
, cu
);
22482 case DW_TAG_atomic_type
:
22483 this_type
= read_tag_atomic_type (die
, cu
);
22486 complaint (&symfile_complaints
,
22487 _("unexpected tag in read_type_die: '%s'"),
22488 dwarf_tag_name (die
->tag
));
22495 /* See if we can figure out if the class lives in a namespace. We do
22496 this by looking for a member function; its demangled name will
22497 contain namespace info, if there is any.
22498 Return the computed name or NULL.
22499 Space for the result is allocated on the objfile's obstack.
22500 This is the full-die version of guess_partial_die_structure_name.
22501 In this case we know DIE has no useful parent. */
22504 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22506 struct die_info
*spec_die
;
22507 struct dwarf2_cu
*spec_cu
;
22508 struct die_info
*child
;
22509 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22512 spec_die
= die_specification (die
, &spec_cu
);
22513 if (spec_die
!= NULL
)
22519 for (child
= die
->child
;
22521 child
= child
->sibling
)
22523 if (child
->tag
== DW_TAG_subprogram
)
22525 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22527 if (linkage_name
!= NULL
)
22530 = language_class_name_from_physname (cu
->language_defn
,
22534 if (actual_name
!= NULL
)
22536 const char *die_name
= dwarf2_name (die
, cu
);
22538 if (die_name
!= NULL
22539 && strcmp (die_name
, actual_name
) != 0)
22541 /* Strip off the class name from the full name.
22542 We want the prefix. */
22543 int die_name_len
= strlen (die_name
);
22544 int actual_name_len
= strlen (actual_name
);
22546 /* Test for '::' as a sanity check. */
22547 if (actual_name_len
> die_name_len
+ 2
22548 && actual_name
[actual_name_len
22549 - die_name_len
- 1] == ':')
22550 name
= (char *) obstack_copy0 (
22551 &objfile
->per_bfd
->storage_obstack
,
22552 actual_name
, actual_name_len
- die_name_len
- 2);
22555 xfree (actual_name
);
22564 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22565 prefix part in such case. See
22566 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22568 static const char *
22569 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22571 struct attribute
*attr
;
22574 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22575 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22578 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22581 attr
= dw2_linkage_name_attr (die
, cu
);
22582 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22585 /* dwarf2_name had to be already called. */
22586 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22588 /* Strip the base name, keep any leading namespaces/classes. */
22589 base
= strrchr (DW_STRING (attr
), ':');
22590 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22593 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22594 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22596 &base
[-1] - DW_STRING (attr
));
22599 /* Return the name of the namespace/class that DIE is defined within,
22600 or "" if we can't tell. The caller should not xfree the result.
22602 For example, if we're within the method foo() in the following
22612 then determine_prefix on foo's die will return "N::C". */
22614 static const char *
22615 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22617 struct dwarf2_per_objfile
*dwarf2_per_objfile
22618 = cu
->per_cu
->dwarf2_per_objfile
;
22619 struct die_info
*parent
, *spec_die
;
22620 struct dwarf2_cu
*spec_cu
;
22621 struct type
*parent_type
;
22622 const char *retval
;
22624 if (cu
->language
!= language_cplus
22625 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22626 && cu
->language
!= language_rust
)
22629 retval
= anonymous_struct_prefix (die
, cu
);
22633 /* We have to be careful in the presence of DW_AT_specification.
22634 For example, with GCC 3.4, given the code
22638 // Definition of N::foo.
22642 then we'll have a tree of DIEs like this:
22644 1: DW_TAG_compile_unit
22645 2: DW_TAG_namespace // N
22646 3: DW_TAG_subprogram // declaration of N::foo
22647 4: DW_TAG_subprogram // definition of N::foo
22648 DW_AT_specification // refers to die #3
22650 Thus, when processing die #4, we have to pretend that we're in
22651 the context of its DW_AT_specification, namely the contex of die
22654 spec_die
= die_specification (die
, &spec_cu
);
22655 if (spec_die
== NULL
)
22656 parent
= die
->parent
;
22659 parent
= spec_die
->parent
;
22663 if (parent
== NULL
)
22665 else if (parent
->building_fullname
)
22668 const char *parent_name
;
22670 /* It has been seen on RealView 2.2 built binaries,
22671 DW_TAG_template_type_param types actually _defined_ as
22672 children of the parent class:
22675 template class <class Enum> Class{};
22676 Class<enum E> class_e;
22678 1: DW_TAG_class_type (Class)
22679 2: DW_TAG_enumeration_type (E)
22680 3: DW_TAG_enumerator (enum1:0)
22681 3: DW_TAG_enumerator (enum2:1)
22683 2: DW_TAG_template_type_param
22684 DW_AT_type DW_FORM_ref_udata (E)
22686 Besides being broken debug info, it can put GDB into an
22687 infinite loop. Consider:
22689 When we're building the full name for Class<E>, we'll start
22690 at Class, and go look over its template type parameters,
22691 finding E. We'll then try to build the full name of E, and
22692 reach here. We're now trying to build the full name of E,
22693 and look over the parent DIE for containing scope. In the
22694 broken case, if we followed the parent DIE of E, we'd again
22695 find Class, and once again go look at its template type
22696 arguments, etc., etc. Simply don't consider such parent die
22697 as source-level parent of this die (it can't be, the language
22698 doesn't allow it), and break the loop here. */
22699 name
= dwarf2_name (die
, cu
);
22700 parent_name
= dwarf2_name (parent
, cu
);
22701 complaint (&symfile_complaints
,
22702 _("template param type '%s' defined within parent '%s'"),
22703 name
? name
: "<unknown>",
22704 parent_name
? parent_name
: "<unknown>");
22708 switch (parent
->tag
)
22710 case DW_TAG_namespace
:
22711 parent_type
= read_type_die (parent
, cu
);
22712 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22713 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22714 Work around this problem here. */
22715 if (cu
->language
== language_cplus
22716 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22718 /* We give a name to even anonymous namespaces. */
22719 return TYPE_TAG_NAME (parent_type
);
22720 case DW_TAG_class_type
:
22721 case DW_TAG_interface_type
:
22722 case DW_TAG_structure_type
:
22723 case DW_TAG_union_type
:
22724 case DW_TAG_module
:
22725 parent_type
= read_type_die (parent
, cu
);
22726 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22727 return TYPE_TAG_NAME (parent_type
);
22729 /* An anonymous structure is only allowed non-static data
22730 members; no typedefs, no member functions, et cetera.
22731 So it does not need a prefix. */
22733 case DW_TAG_compile_unit
:
22734 case DW_TAG_partial_unit
:
22735 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22736 if (cu
->language
== language_cplus
22737 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22738 && die
->child
!= NULL
22739 && (die
->tag
== DW_TAG_class_type
22740 || die
->tag
== DW_TAG_structure_type
22741 || die
->tag
== DW_TAG_union_type
))
22743 char *name
= guess_full_die_structure_name (die
, cu
);
22748 case DW_TAG_enumeration_type
:
22749 parent_type
= read_type_die (parent
, cu
);
22750 if (TYPE_DECLARED_CLASS (parent_type
))
22752 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22753 return TYPE_TAG_NAME (parent_type
);
22756 /* Fall through. */
22758 return determine_prefix (parent
, cu
);
22762 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22763 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22764 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22765 an obconcat, otherwise allocate storage for the result. The CU argument is
22766 used to determine the language and hence, the appropriate separator. */
22768 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22771 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22772 int physname
, struct dwarf2_cu
*cu
)
22774 const char *lead
= "";
22777 if (suffix
== NULL
|| suffix
[0] == '\0'
22778 || prefix
== NULL
|| prefix
[0] == '\0')
22780 else if (cu
->language
== language_d
)
22782 /* For D, the 'main' function could be defined in any module, but it
22783 should never be prefixed. */
22784 if (strcmp (suffix
, "D main") == 0)
22792 else if (cu
->language
== language_fortran
&& physname
)
22794 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22795 DW_AT_MIPS_linkage_name is preferred and used instead. */
22803 if (prefix
== NULL
)
22805 if (suffix
== NULL
)
22812 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22814 strcpy (retval
, lead
);
22815 strcat (retval
, prefix
);
22816 strcat (retval
, sep
);
22817 strcat (retval
, suffix
);
22822 /* We have an obstack. */
22823 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22827 /* Return sibling of die, NULL if no sibling. */
22829 static struct die_info
*
22830 sibling_die (struct die_info
*die
)
22832 return die
->sibling
;
22835 /* Get name of a die, return NULL if not found. */
22837 static const char *
22838 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22839 struct obstack
*obstack
)
22841 if (name
&& cu
->language
== language_cplus
)
22843 std::string canon_name
= cp_canonicalize_string (name
);
22845 if (!canon_name
.empty ())
22847 if (canon_name
!= name
)
22848 name
= (const char *) obstack_copy0 (obstack
,
22849 canon_name
.c_str (),
22850 canon_name
.length ());
22857 /* Get name of a die, return NULL if not found.
22858 Anonymous namespaces are converted to their magic string. */
22860 static const char *
22861 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22863 struct attribute
*attr
;
22864 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22866 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22867 if ((!attr
|| !DW_STRING (attr
))
22868 && die
->tag
!= DW_TAG_namespace
22869 && die
->tag
!= DW_TAG_class_type
22870 && die
->tag
!= DW_TAG_interface_type
22871 && die
->tag
!= DW_TAG_structure_type
22872 && die
->tag
!= DW_TAG_union_type
)
22877 case DW_TAG_compile_unit
:
22878 case DW_TAG_partial_unit
:
22879 /* Compilation units have a DW_AT_name that is a filename, not
22880 a source language identifier. */
22881 case DW_TAG_enumeration_type
:
22882 case DW_TAG_enumerator
:
22883 /* These tags always have simple identifiers already; no need
22884 to canonicalize them. */
22885 return DW_STRING (attr
);
22887 case DW_TAG_namespace
:
22888 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22889 return DW_STRING (attr
);
22890 return CP_ANONYMOUS_NAMESPACE_STR
;
22892 case DW_TAG_class_type
:
22893 case DW_TAG_interface_type
:
22894 case DW_TAG_structure_type
:
22895 case DW_TAG_union_type
:
22896 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22897 structures or unions. These were of the form "._%d" in GCC 4.1,
22898 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22899 and GCC 4.4. We work around this problem by ignoring these. */
22900 if (attr
&& DW_STRING (attr
)
22901 && (startswith (DW_STRING (attr
), "._")
22902 || startswith (DW_STRING (attr
), "<anonymous")))
22905 /* GCC might emit a nameless typedef that has a linkage name. See
22906 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22907 if (!attr
|| DW_STRING (attr
) == NULL
)
22909 char *demangled
= NULL
;
22911 attr
= dw2_linkage_name_attr (die
, cu
);
22912 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22915 /* Avoid demangling DW_STRING (attr) the second time on a second
22916 call for the same DIE. */
22917 if (!DW_STRING_IS_CANONICAL (attr
))
22918 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22924 /* FIXME: we already did this for the partial symbol... */
22927 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22928 demangled
, strlen (demangled
)));
22929 DW_STRING_IS_CANONICAL (attr
) = 1;
22932 /* Strip any leading namespaces/classes, keep only the base name.
22933 DW_AT_name for named DIEs does not contain the prefixes. */
22934 base
= strrchr (DW_STRING (attr
), ':');
22935 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22938 return DW_STRING (attr
);
22947 if (!DW_STRING_IS_CANONICAL (attr
))
22950 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22951 &objfile
->per_bfd
->storage_obstack
);
22952 DW_STRING_IS_CANONICAL (attr
) = 1;
22954 return DW_STRING (attr
);
22957 /* Return the die that this die in an extension of, or NULL if there
22958 is none. *EXT_CU is the CU containing DIE on input, and the CU
22959 containing the return value on output. */
22961 static struct die_info
*
22962 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22964 struct attribute
*attr
;
22966 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22970 return follow_die_ref (die
, attr
, ext_cu
);
22973 /* Convert a DIE tag into its string name. */
22975 static const char *
22976 dwarf_tag_name (unsigned tag
)
22978 const char *name
= get_DW_TAG_name (tag
);
22981 return "DW_TAG_<unknown>";
22986 /* Convert a DWARF attribute code into its string name. */
22988 static const char *
22989 dwarf_attr_name (unsigned attr
)
22993 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22994 if (attr
== DW_AT_MIPS_fde
)
22995 return "DW_AT_MIPS_fde";
22997 if (attr
== DW_AT_HP_block_index
)
22998 return "DW_AT_HP_block_index";
23001 name
= get_DW_AT_name (attr
);
23004 return "DW_AT_<unknown>";
23009 /* Convert a DWARF value form code into its string name. */
23011 static const char *
23012 dwarf_form_name (unsigned form
)
23014 const char *name
= get_DW_FORM_name (form
);
23017 return "DW_FORM_<unknown>";
23022 static const char *
23023 dwarf_bool_name (unsigned mybool
)
23031 /* Convert a DWARF type code into its string name. */
23033 static const char *
23034 dwarf_type_encoding_name (unsigned enc
)
23036 const char *name
= get_DW_ATE_name (enc
);
23039 return "DW_ATE_<unknown>";
23045 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23049 print_spaces (indent
, f
);
23050 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23051 dwarf_tag_name (die
->tag
), die
->abbrev
,
23052 sect_offset_str (die
->sect_off
));
23054 if (die
->parent
!= NULL
)
23056 print_spaces (indent
, f
);
23057 fprintf_unfiltered (f
, " parent at offset: %s\n",
23058 sect_offset_str (die
->parent
->sect_off
));
23061 print_spaces (indent
, f
);
23062 fprintf_unfiltered (f
, " has children: %s\n",
23063 dwarf_bool_name (die
->child
!= NULL
));
23065 print_spaces (indent
, f
);
23066 fprintf_unfiltered (f
, " attributes:\n");
23068 for (i
= 0; i
< die
->num_attrs
; ++i
)
23070 print_spaces (indent
, f
);
23071 fprintf_unfiltered (f
, " %s (%s) ",
23072 dwarf_attr_name (die
->attrs
[i
].name
),
23073 dwarf_form_name (die
->attrs
[i
].form
));
23075 switch (die
->attrs
[i
].form
)
23078 case DW_FORM_GNU_addr_index
:
23079 fprintf_unfiltered (f
, "address: ");
23080 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23082 case DW_FORM_block2
:
23083 case DW_FORM_block4
:
23084 case DW_FORM_block
:
23085 case DW_FORM_block1
:
23086 fprintf_unfiltered (f
, "block: size %s",
23087 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23089 case DW_FORM_exprloc
:
23090 fprintf_unfiltered (f
, "expression: size %s",
23091 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23093 case DW_FORM_data16
:
23094 fprintf_unfiltered (f
, "constant of 16 bytes");
23096 case DW_FORM_ref_addr
:
23097 fprintf_unfiltered (f
, "ref address: ");
23098 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23100 case DW_FORM_GNU_ref_alt
:
23101 fprintf_unfiltered (f
, "alt ref address: ");
23102 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23108 case DW_FORM_ref_udata
:
23109 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23110 (long) (DW_UNSND (&die
->attrs
[i
])));
23112 case DW_FORM_data1
:
23113 case DW_FORM_data2
:
23114 case DW_FORM_data4
:
23115 case DW_FORM_data8
:
23116 case DW_FORM_udata
:
23117 case DW_FORM_sdata
:
23118 fprintf_unfiltered (f
, "constant: %s",
23119 pulongest (DW_UNSND (&die
->attrs
[i
])));
23121 case DW_FORM_sec_offset
:
23122 fprintf_unfiltered (f
, "section offset: %s",
23123 pulongest (DW_UNSND (&die
->attrs
[i
])));
23125 case DW_FORM_ref_sig8
:
23126 fprintf_unfiltered (f
, "signature: %s",
23127 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23129 case DW_FORM_string
:
23131 case DW_FORM_line_strp
:
23132 case DW_FORM_GNU_str_index
:
23133 case DW_FORM_GNU_strp_alt
:
23134 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23135 DW_STRING (&die
->attrs
[i
])
23136 ? DW_STRING (&die
->attrs
[i
]) : "",
23137 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23140 if (DW_UNSND (&die
->attrs
[i
]))
23141 fprintf_unfiltered (f
, "flag: TRUE");
23143 fprintf_unfiltered (f
, "flag: FALSE");
23145 case DW_FORM_flag_present
:
23146 fprintf_unfiltered (f
, "flag: TRUE");
23148 case DW_FORM_indirect
:
23149 /* The reader will have reduced the indirect form to
23150 the "base form" so this form should not occur. */
23151 fprintf_unfiltered (f
,
23152 "unexpected attribute form: DW_FORM_indirect");
23154 case DW_FORM_implicit_const
:
23155 fprintf_unfiltered (f
, "constant: %s",
23156 plongest (DW_SND (&die
->attrs
[i
])));
23159 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23160 die
->attrs
[i
].form
);
23163 fprintf_unfiltered (f
, "\n");
23168 dump_die_for_error (struct die_info
*die
)
23170 dump_die_shallow (gdb_stderr
, 0, die
);
23174 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23176 int indent
= level
* 4;
23178 gdb_assert (die
!= NULL
);
23180 if (level
>= max_level
)
23183 dump_die_shallow (f
, indent
, die
);
23185 if (die
->child
!= NULL
)
23187 print_spaces (indent
, f
);
23188 fprintf_unfiltered (f
, " Children:");
23189 if (level
+ 1 < max_level
)
23191 fprintf_unfiltered (f
, "\n");
23192 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23196 fprintf_unfiltered (f
,
23197 " [not printed, max nesting level reached]\n");
23201 if (die
->sibling
!= NULL
&& level
> 0)
23203 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23207 /* This is called from the pdie macro in gdbinit.in.
23208 It's not static so gcc will keep a copy callable from gdb. */
23211 dump_die (struct die_info
*die
, int max_level
)
23213 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23217 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23221 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23222 to_underlying (die
->sect_off
),
23228 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23232 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23234 if (attr_form_is_ref (attr
))
23235 return (sect_offset
) DW_UNSND (attr
);
23237 complaint (&symfile_complaints
,
23238 _("unsupported die ref attribute form: '%s'"),
23239 dwarf_form_name (attr
->form
));
23243 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23244 * the value held by the attribute is not constant. */
23247 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23249 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23250 return DW_SND (attr
);
23251 else if (attr
->form
== DW_FORM_udata
23252 || attr
->form
== DW_FORM_data1
23253 || attr
->form
== DW_FORM_data2
23254 || attr
->form
== DW_FORM_data4
23255 || attr
->form
== DW_FORM_data8
)
23256 return DW_UNSND (attr
);
23259 /* For DW_FORM_data16 see attr_form_is_constant. */
23260 complaint (&symfile_complaints
,
23261 _("Attribute value is not a constant (%s)"),
23262 dwarf_form_name (attr
->form
));
23263 return default_value
;
23267 /* Follow reference or signature attribute ATTR of SRC_DIE.
23268 On entry *REF_CU is the CU of SRC_DIE.
23269 On exit *REF_CU is the CU of the result. */
23271 static struct die_info
*
23272 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23273 struct dwarf2_cu
**ref_cu
)
23275 struct die_info
*die
;
23277 if (attr_form_is_ref (attr
))
23278 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23279 else if (attr
->form
== DW_FORM_ref_sig8
)
23280 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23283 dump_die_for_error (src_die
);
23284 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23285 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23291 /* Follow reference OFFSET.
23292 On entry *REF_CU is the CU of the source die referencing OFFSET.
23293 On exit *REF_CU is the CU of the result.
23294 Returns NULL if OFFSET is invalid. */
23296 static struct die_info
*
23297 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23298 struct dwarf2_cu
**ref_cu
)
23300 struct die_info temp_die
;
23301 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23302 struct dwarf2_per_objfile
*dwarf2_per_objfile
23303 = cu
->per_cu
->dwarf2_per_objfile
;
23304 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23306 gdb_assert (cu
->per_cu
!= NULL
);
23310 if (cu
->per_cu
->is_debug_types
)
23312 /* .debug_types CUs cannot reference anything outside their CU.
23313 If they need to, they have to reference a signatured type via
23314 DW_FORM_ref_sig8. */
23315 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23318 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23319 || !offset_in_cu_p (&cu
->header
, sect_off
))
23321 struct dwarf2_per_cu_data
*per_cu
;
23323 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23324 dwarf2_per_objfile
);
23326 /* If necessary, add it to the queue and load its DIEs. */
23327 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23328 load_full_comp_unit (per_cu
, cu
->language
);
23330 target_cu
= per_cu
->cu
;
23332 else if (cu
->dies
== NULL
)
23334 /* We're loading full DIEs during partial symbol reading. */
23335 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23336 load_full_comp_unit (cu
->per_cu
, language_minimal
);
23339 *ref_cu
= target_cu
;
23340 temp_die
.sect_off
= sect_off
;
23341 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23343 to_underlying (sect_off
));
23346 /* Follow reference attribute ATTR of SRC_DIE.
23347 On entry *REF_CU is the CU of SRC_DIE.
23348 On exit *REF_CU is the CU of the result. */
23350 static struct die_info
*
23351 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23352 struct dwarf2_cu
**ref_cu
)
23354 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23355 struct dwarf2_cu
*cu
= *ref_cu
;
23356 struct die_info
*die
;
23358 die
= follow_die_offset (sect_off
,
23359 (attr
->form
== DW_FORM_GNU_ref_alt
23360 || cu
->per_cu
->is_dwz
),
23363 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23364 "at %s [in module %s]"),
23365 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23366 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23371 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23372 Returned value is intended for DW_OP_call*. Returned
23373 dwarf2_locexpr_baton->data has lifetime of
23374 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23376 struct dwarf2_locexpr_baton
23377 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23378 struct dwarf2_per_cu_data
*per_cu
,
23379 CORE_ADDR (*get_frame_pc
) (void *baton
),
23382 struct dwarf2_cu
*cu
;
23383 struct die_info
*die
;
23384 struct attribute
*attr
;
23385 struct dwarf2_locexpr_baton retval
;
23386 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23387 struct dwarf2_per_objfile
*dwarf2_per_objfile
23388 = get_dwarf2_per_objfile (objfile
);
23390 if (per_cu
->cu
== NULL
)
23395 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23396 Instead just throw an error, not much else we can do. */
23397 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23398 sect_offset_str (sect_off
), objfile_name (objfile
));
23401 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23403 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23404 sect_offset_str (sect_off
), objfile_name (objfile
));
23406 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23409 /* DWARF: "If there is no such attribute, then there is no effect.".
23410 DATA is ignored if SIZE is 0. */
23412 retval
.data
= NULL
;
23415 else if (attr_form_is_section_offset (attr
))
23417 struct dwarf2_loclist_baton loclist_baton
;
23418 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23421 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23423 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23425 retval
.size
= size
;
23429 if (!attr_form_is_block (attr
))
23430 error (_("Dwarf Error: DIE at %s referenced in module %s "
23431 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23432 sect_offset_str (sect_off
), objfile_name (objfile
));
23434 retval
.data
= DW_BLOCK (attr
)->data
;
23435 retval
.size
= DW_BLOCK (attr
)->size
;
23437 retval
.per_cu
= cu
->per_cu
;
23439 age_cached_comp_units (dwarf2_per_objfile
);
23444 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23447 struct dwarf2_locexpr_baton
23448 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23449 struct dwarf2_per_cu_data
*per_cu
,
23450 CORE_ADDR (*get_frame_pc
) (void *baton
),
23453 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23455 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23458 /* Write a constant of a given type as target-ordered bytes into
23461 static const gdb_byte
*
23462 write_constant_as_bytes (struct obstack
*obstack
,
23463 enum bfd_endian byte_order
,
23470 *len
= TYPE_LENGTH (type
);
23471 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23472 store_unsigned_integer (result
, *len
, byte_order
, value
);
23477 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23478 pointer to the constant bytes and set LEN to the length of the
23479 data. If memory is needed, allocate it on OBSTACK. If the DIE
23480 does not have a DW_AT_const_value, return NULL. */
23483 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23484 struct dwarf2_per_cu_data
*per_cu
,
23485 struct obstack
*obstack
,
23488 struct dwarf2_cu
*cu
;
23489 struct die_info
*die
;
23490 struct attribute
*attr
;
23491 const gdb_byte
*result
= NULL
;
23494 enum bfd_endian byte_order
;
23495 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23497 if (per_cu
->cu
== NULL
)
23502 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23503 Instead just throw an error, not much else we can do. */
23504 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23505 sect_offset_str (sect_off
), objfile_name (objfile
));
23508 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23510 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23511 sect_offset_str (sect_off
), objfile_name (objfile
));
23513 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23517 byte_order
= (bfd_big_endian (objfile
->obfd
)
23518 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23520 switch (attr
->form
)
23523 case DW_FORM_GNU_addr_index
:
23527 *len
= cu
->header
.addr_size
;
23528 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23529 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23533 case DW_FORM_string
:
23535 case DW_FORM_GNU_str_index
:
23536 case DW_FORM_GNU_strp_alt
:
23537 /* DW_STRING is already allocated on the objfile obstack, point
23539 result
= (const gdb_byte
*) DW_STRING (attr
);
23540 *len
= strlen (DW_STRING (attr
));
23542 case DW_FORM_block1
:
23543 case DW_FORM_block2
:
23544 case DW_FORM_block4
:
23545 case DW_FORM_block
:
23546 case DW_FORM_exprloc
:
23547 case DW_FORM_data16
:
23548 result
= DW_BLOCK (attr
)->data
;
23549 *len
= DW_BLOCK (attr
)->size
;
23552 /* The DW_AT_const_value attributes are supposed to carry the
23553 symbol's value "represented as it would be on the target
23554 architecture." By the time we get here, it's already been
23555 converted to host endianness, so we just need to sign- or
23556 zero-extend it as appropriate. */
23557 case DW_FORM_data1
:
23558 type
= die_type (die
, cu
);
23559 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23560 if (result
== NULL
)
23561 result
= write_constant_as_bytes (obstack
, byte_order
,
23564 case DW_FORM_data2
:
23565 type
= die_type (die
, cu
);
23566 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23567 if (result
== NULL
)
23568 result
= write_constant_as_bytes (obstack
, byte_order
,
23571 case DW_FORM_data4
:
23572 type
= die_type (die
, cu
);
23573 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23574 if (result
== NULL
)
23575 result
= write_constant_as_bytes (obstack
, byte_order
,
23578 case DW_FORM_data8
:
23579 type
= die_type (die
, cu
);
23580 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23581 if (result
== NULL
)
23582 result
= write_constant_as_bytes (obstack
, byte_order
,
23586 case DW_FORM_sdata
:
23587 case DW_FORM_implicit_const
:
23588 type
= die_type (die
, cu
);
23589 result
= write_constant_as_bytes (obstack
, byte_order
,
23590 type
, DW_SND (attr
), len
);
23593 case DW_FORM_udata
:
23594 type
= die_type (die
, cu
);
23595 result
= write_constant_as_bytes (obstack
, byte_order
,
23596 type
, DW_UNSND (attr
), len
);
23600 complaint (&symfile_complaints
,
23601 _("unsupported const value attribute form: '%s'"),
23602 dwarf_form_name (attr
->form
));
23609 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23610 valid type for this die is found. */
23613 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23614 struct dwarf2_per_cu_data
*per_cu
)
23616 struct dwarf2_cu
*cu
;
23617 struct die_info
*die
;
23619 if (per_cu
->cu
== NULL
)
23625 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23629 return die_type (die
, cu
);
23632 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23636 dwarf2_get_die_type (cu_offset die_offset
,
23637 struct dwarf2_per_cu_data
*per_cu
)
23639 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23640 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23643 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23644 On entry *REF_CU is the CU of SRC_DIE.
23645 On exit *REF_CU is the CU of the result.
23646 Returns NULL if the referenced DIE isn't found. */
23648 static struct die_info
*
23649 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23650 struct dwarf2_cu
**ref_cu
)
23652 struct die_info temp_die
;
23653 struct dwarf2_cu
*sig_cu
;
23654 struct die_info
*die
;
23656 /* While it might be nice to assert sig_type->type == NULL here,
23657 we can get here for DW_AT_imported_declaration where we need
23658 the DIE not the type. */
23660 /* If necessary, add it to the queue and load its DIEs. */
23662 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23663 read_signatured_type (sig_type
);
23665 sig_cu
= sig_type
->per_cu
.cu
;
23666 gdb_assert (sig_cu
!= NULL
);
23667 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23668 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23669 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23670 to_underlying (temp_die
.sect_off
));
23673 struct dwarf2_per_objfile
*dwarf2_per_objfile
23674 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23676 /* For .gdb_index version 7 keep track of included TUs.
23677 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23678 if (dwarf2_per_objfile
->index_table
!= NULL
23679 && dwarf2_per_objfile
->index_table
->version
<= 7)
23681 VEC_safe_push (dwarf2_per_cu_ptr
,
23682 (*ref_cu
)->per_cu
->imported_symtabs
,
23693 /* Follow signatured type referenced by ATTR in SRC_DIE.
23694 On entry *REF_CU is the CU of SRC_DIE.
23695 On exit *REF_CU is the CU of the result.
23696 The result is the DIE of the type.
23697 If the referenced type cannot be found an error is thrown. */
23699 static struct die_info
*
23700 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23701 struct dwarf2_cu
**ref_cu
)
23703 ULONGEST signature
= DW_SIGNATURE (attr
);
23704 struct signatured_type
*sig_type
;
23705 struct die_info
*die
;
23707 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23709 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23710 /* sig_type will be NULL if the signatured type is missing from
23712 if (sig_type
== NULL
)
23714 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23715 " from DIE at %s [in module %s]"),
23716 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23717 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23720 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23723 dump_die_for_error (src_die
);
23724 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23725 " from DIE at %s [in module %s]"),
23726 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23727 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23733 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23734 reading in and processing the type unit if necessary. */
23736 static struct type
*
23737 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23738 struct dwarf2_cu
*cu
)
23740 struct dwarf2_per_objfile
*dwarf2_per_objfile
23741 = cu
->per_cu
->dwarf2_per_objfile
;
23742 struct signatured_type
*sig_type
;
23743 struct dwarf2_cu
*type_cu
;
23744 struct die_info
*type_die
;
23747 sig_type
= lookup_signatured_type (cu
, signature
);
23748 /* sig_type will be NULL if the signatured type is missing from
23750 if (sig_type
== NULL
)
23752 complaint (&symfile_complaints
,
23753 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23754 " from DIE at %s [in module %s]"),
23755 hex_string (signature
), sect_offset_str (die
->sect_off
),
23756 objfile_name (dwarf2_per_objfile
->objfile
));
23757 return build_error_marker_type (cu
, die
);
23760 /* If we already know the type we're done. */
23761 if (sig_type
->type
!= NULL
)
23762 return sig_type
->type
;
23765 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23766 if (type_die
!= NULL
)
23768 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23769 is created. This is important, for example, because for c++ classes
23770 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23771 type
= read_type_die (type_die
, type_cu
);
23774 complaint (&symfile_complaints
,
23775 _("Dwarf Error: Cannot build signatured type %s"
23776 " referenced from DIE at %s [in module %s]"),
23777 hex_string (signature
), sect_offset_str (die
->sect_off
),
23778 objfile_name (dwarf2_per_objfile
->objfile
));
23779 type
= build_error_marker_type (cu
, die
);
23784 complaint (&symfile_complaints
,
23785 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23786 " from DIE at %s [in module %s]"),
23787 hex_string (signature
), sect_offset_str (die
->sect_off
),
23788 objfile_name (dwarf2_per_objfile
->objfile
));
23789 type
= build_error_marker_type (cu
, die
);
23791 sig_type
->type
= type
;
23796 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23797 reading in and processing the type unit if necessary. */
23799 static struct type
*
23800 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23801 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23803 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23804 if (attr_form_is_ref (attr
))
23806 struct dwarf2_cu
*type_cu
= cu
;
23807 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23809 return read_type_die (type_die
, type_cu
);
23811 else if (attr
->form
== DW_FORM_ref_sig8
)
23813 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23817 struct dwarf2_per_objfile
*dwarf2_per_objfile
23818 = cu
->per_cu
->dwarf2_per_objfile
;
23820 complaint (&symfile_complaints
,
23821 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23822 " at %s [in module %s]"),
23823 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23824 objfile_name (dwarf2_per_objfile
->objfile
));
23825 return build_error_marker_type (cu
, die
);
23829 /* Load the DIEs associated with type unit PER_CU into memory. */
23832 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23834 struct signatured_type
*sig_type
;
23836 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23837 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23839 /* We have the per_cu, but we need the signatured_type.
23840 Fortunately this is an easy translation. */
23841 gdb_assert (per_cu
->is_debug_types
);
23842 sig_type
= (struct signatured_type
*) per_cu
;
23844 gdb_assert (per_cu
->cu
== NULL
);
23846 read_signatured_type (sig_type
);
23848 gdb_assert (per_cu
->cu
!= NULL
);
23851 /* die_reader_func for read_signatured_type.
23852 This is identical to load_full_comp_unit_reader,
23853 but is kept separate for now. */
23856 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23857 const gdb_byte
*info_ptr
,
23858 struct die_info
*comp_unit_die
,
23862 struct dwarf2_cu
*cu
= reader
->cu
;
23864 gdb_assert (cu
->die_hash
== NULL
);
23866 htab_create_alloc_ex (cu
->header
.length
/ 12,
23870 &cu
->comp_unit_obstack
,
23871 hashtab_obstack_allocate
,
23872 dummy_obstack_deallocate
);
23875 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23876 &info_ptr
, comp_unit_die
);
23877 cu
->dies
= comp_unit_die
;
23878 /* comp_unit_die is not stored in die_hash, no need. */
23880 /* We try not to read any attributes in this function, because not
23881 all CUs needed for references have been loaded yet, and symbol
23882 table processing isn't initialized. But we have to set the CU language,
23883 or we won't be able to build types correctly.
23884 Similarly, if we do not read the producer, we can not apply
23885 producer-specific interpretation. */
23886 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23889 /* Read in a signatured type and build its CU and DIEs.
23890 If the type is a stub for the real type in a DWO file,
23891 read in the real type from the DWO file as well. */
23894 read_signatured_type (struct signatured_type
*sig_type
)
23896 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23898 gdb_assert (per_cu
->is_debug_types
);
23899 gdb_assert (per_cu
->cu
== NULL
);
23901 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23902 read_signatured_type_reader
, NULL
);
23903 sig_type
->per_cu
.tu_read
= 1;
23906 /* Decode simple location descriptions.
23907 Given a pointer to a dwarf block that defines a location, compute
23908 the location and return the value.
23910 NOTE drow/2003-11-18: This function is called in two situations
23911 now: for the address of static or global variables (partial symbols
23912 only) and for offsets into structures which are expected to be
23913 (more or less) constant. The partial symbol case should go away,
23914 and only the constant case should remain. That will let this
23915 function complain more accurately. A few special modes are allowed
23916 without complaint for global variables (for instance, global
23917 register values and thread-local values).
23919 A location description containing no operations indicates that the
23920 object is optimized out. The return value is 0 for that case.
23921 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23922 callers will only want a very basic result and this can become a
23925 Note that stack[0] is unused except as a default error return. */
23928 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23930 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23932 size_t size
= blk
->size
;
23933 const gdb_byte
*data
= blk
->data
;
23934 CORE_ADDR stack
[64];
23936 unsigned int bytes_read
, unsnd
;
23942 stack
[++stacki
] = 0;
23981 stack
[++stacki
] = op
- DW_OP_lit0
;
24016 stack
[++stacki
] = op
- DW_OP_reg0
;
24018 dwarf2_complex_location_expr_complaint ();
24022 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24024 stack
[++stacki
] = unsnd
;
24026 dwarf2_complex_location_expr_complaint ();
24030 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24035 case DW_OP_const1u
:
24036 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24040 case DW_OP_const1s
:
24041 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24045 case DW_OP_const2u
:
24046 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24050 case DW_OP_const2s
:
24051 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24055 case DW_OP_const4u
:
24056 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24060 case DW_OP_const4s
:
24061 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24065 case DW_OP_const8u
:
24066 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24071 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24077 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24082 stack
[stacki
+ 1] = stack
[stacki
];
24087 stack
[stacki
- 1] += stack
[stacki
];
24091 case DW_OP_plus_uconst
:
24092 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24098 stack
[stacki
- 1] -= stack
[stacki
];
24103 /* If we're not the last op, then we definitely can't encode
24104 this using GDB's address_class enum. This is valid for partial
24105 global symbols, although the variable's address will be bogus
24108 dwarf2_complex_location_expr_complaint ();
24111 case DW_OP_GNU_push_tls_address
:
24112 case DW_OP_form_tls_address
:
24113 /* The top of the stack has the offset from the beginning
24114 of the thread control block at which the variable is located. */
24115 /* Nothing should follow this operator, so the top of stack would
24117 /* This is valid for partial global symbols, but the variable's
24118 address will be bogus in the psymtab. Make it always at least
24119 non-zero to not look as a variable garbage collected by linker
24120 which have DW_OP_addr 0. */
24122 dwarf2_complex_location_expr_complaint ();
24126 case DW_OP_GNU_uninit
:
24129 case DW_OP_GNU_addr_index
:
24130 case DW_OP_GNU_const_index
:
24131 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24138 const char *name
= get_DW_OP_name (op
);
24141 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
24144 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
24148 return (stack
[stacki
]);
24151 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24152 outside of the allocated space. Also enforce minimum>0. */
24153 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24155 complaint (&symfile_complaints
,
24156 _("location description stack overflow"));
24162 complaint (&symfile_complaints
,
24163 _("location description stack underflow"));
24167 return (stack
[stacki
]);
24170 /* memory allocation interface */
24172 static struct dwarf_block
*
24173 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24175 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24178 static struct die_info
*
24179 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24181 struct die_info
*die
;
24182 size_t size
= sizeof (struct die_info
);
24185 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24187 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24188 memset (die
, 0, sizeof (struct die_info
));
24193 /* Macro support. */
24195 /* Return file name relative to the compilation directory of file number I in
24196 *LH's file name table. The result is allocated using xmalloc; the caller is
24197 responsible for freeing it. */
24200 file_file_name (int file
, struct line_header
*lh
)
24202 /* Is the file number a valid index into the line header's file name
24203 table? Remember that file numbers start with one, not zero. */
24204 if (1 <= file
&& file
<= lh
->file_names
.size ())
24206 const file_entry
&fe
= lh
->file_names
[file
- 1];
24208 if (!IS_ABSOLUTE_PATH (fe
.name
))
24210 const char *dir
= fe
.include_dir (lh
);
24212 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
24214 return xstrdup (fe
.name
);
24218 /* The compiler produced a bogus file number. We can at least
24219 record the macro definitions made in the file, even if we
24220 won't be able to find the file by name. */
24221 char fake_name
[80];
24223 xsnprintf (fake_name
, sizeof (fake_name
),
24224 "<bad macro file number %d>", file
);
24226 complaint (&symfile_complaints
,
24227 _("bad file number in macro information (%d)"),
24230 return xstrdup (fake_name
);
24234 /* Return the full name of file number I in *LH's file name table.
24235 Use COMP_DIR as the name of the current directory of the
24236 compilation. The result is allocated using xmalloc; the caller is
24237 responsible for freeing it. */
24239 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24241 /* Is the file number a valid index into the line header's file name
24242 table? Remember that file numbers start with one, not zero. */
24243 if (1 <= file
&& file
<= lh
->file_names
.size ())
24245 char *relative
= file_file_name (file
, lh
);
24247 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24249 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24250 relative
, (char *) NULL
);
24253 return file_file_name (file
, lh
);
24257 static struct macro_source_file
*
24258 macro_start_file (int file
, int line
,
24259 struct macro_source_file
*current_file
,
24260 struct line_header
*lh
)
24262 /* File name relative to the compilation directory of this source file. */
24263 char *file_name
= file_file_name (file
, lh
);
24265 if (! current_file
)
24267 /* Note: We don't create a macro table for this compilation unit
24268 at all until we actually get a filename. */
24269 struct macro_table
*macro_table
= get_macro_table ();
24271 /* If we have no current file, then this must be the start_file
24272 directive for the compilation unit's main source file. */
24273 current_file
= macro_set_main (macro_table
, file_name
);
24274 macro_define_special (macro_table
);
24277 current_file
= macro_include (current_file
, line
, file_name
);
24281 return current_file
;
24284 static const char *
24285 consume_improper_spaces (const char *p
, const char *body
)
24289 complaint (&symfile_complaints
,
24290 _("macro definition contains spaces "
24291 "in formal argument list:\n`%s'"),
24303 parse_macro_definition (struct macro_source_file
*file
, int line
,
24308 /* The body string takes one of two forms. For object-like macro
24309 definitions, it should be:
24311 <macro name> " " <definition>
24313 For function-like macro definitions, it should be:
24315 <macro name> "() " <definition>
24317 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24319 Spaces may appear only where explicitly indicated, and in the
24322 The Dwarf 2 spec says that an object-like macro's name is always
24323 followed by a space, but versions of GCC around March 2002 omit
24324 the space when the macro's definition is the empty string.
24326 The Dwarf 2 spec says that there should be no spaces between the
24327 formal arguments in a function-like macro's formal argument list,
24328 but versions of GCC around March 2002 include spaces after the
24332 /* Find the extent of the macro name. The macro name is terminated
24333 by either a space or null character (for an object-like macro) or
24334 an opening paren (for a function-like macro). */
24335 for (p
= body
; *p
; p
++)
24336 if (*p
== ' ' || *p
== '(')
24339 if (*p
== ' ' || *p
== '\0')
24341 /* It's an object-like macro. */
24342 int name_len
= p
- body
;
24343 char *name
= savestring (body
, name_len
);
24344 const char *replacement
;
24347 replacement
= body
+ name_len
+ 1;
24350 dwarf2_macro_malformed_definition_complaint (body
);
24351 replacement
= body
+ name_len
;
24354 macro_define_object (file
, line
, name
, replacement
);
24358 else if (*p
== '(')
24360 /* It's a function-like macro. */
24361 char *name
= savestring (body
, p
- body
);
24364 char **argv
= XNEWVEC (char *, argv_size
);
24368 p
= consume_improper_spaces (p
, body
);
24370 /* Parse the formal argument list. */
24371 while (*p
&& *p
!= ')')
24373 /* Find the extent of the current argument name. */
24374 const char *arg_start
= p
;
24376 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24379 if (! *p
|| p
== arg_start
)
24380 dwarf2_macro_malformed_definition_complaint (body
);
24383 /* Make sure argv has room for the new argument. */
24384 if (argc
>= argv_size
)
24387 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24390 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24393 p
= consume_improper_spaces (p
, body
);
24395 /* Consume the comma, if present. */
24400 p
= consume_improper_spaces (p
, body
);
24409 /* Perfectly formed definition, no complaints. */
24410 macro_define_function (file
, line
, name
,
24411 argc
, (const char **) argv
,
24413 else if (*p
== '\0')
24415 /* Complain, but do define it. */
24416 dwarf2_macro_malformed_definition_complaint (body
);
24417 macro_define_function (file
, line
, name
,
24418 argc
, (const char **) argv
,
24422 /* Just complain. */
24423 dwarf2_macro_malformed_definition_complaint (body
);
24426 /* Just complain. */
24427 dwarf2_macro_malformed_definition_complaint (body
);
24433 for (i
= 0; i
< argc
; i
++)
24439 dwarf2_macro_malformed_definition_complaint (body
);
24442 /* Skip some bytes from BYTES according to the form given in FORM.
24443 Returns the new pointer. */
24445 static const gdb_byte
*
24446 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24447 enum dwarf_form form
,
24448 unsigned int offset_size
,
24449 struct dwarf2_section_info
*section
)
24451 unsigned int bytes_read
;
24455 case DW_FORM_data1
:
24460 case DW_FORM_data2
:
24464 case DW_FORM_data4
:
24468 case DW_FORM_data8
:
24472 case DW_FORM_data16
:
24476 case DW_FORM_string
:
24477 read_direct_string (abfd
, bytes
, &bytes_read
);
24478 bytes
+= bytes_read
;
24481 case DW_FORM_sec_offset
:
24483 case DW_FORM_GNU_strp_alt
:
24484 bytes
+= offset_size
;
24487 case DW_FORM_block
:
24488 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24489 bytes
+= bytes_read
;
24492 case DW_FORM_block1
:
24493 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24495 case DW_FORM_block2
:
24496 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24498 case DW_FORM_block4
:
24499 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24502 case DW_FORM_sdata
:
24503 case DW_FORM_udata
:
24504 case DW_FORM_GNU_addr_index
:
24505 case DW_FORM_GNU_str_index
:
24506 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24509 dwarf2_section_buffer_overflow_complaint (section
);
24514 case DW_FORM_implicit_const
:
24519 complaint (&symfile_complaints
,
24520 _("invalid form 0x%x in `%s'"),
24521 form
, get_section_name (section
));
24529 /* A helper for dwarf_decode_macros that handles skipping an unknown
24530 opcode. Returns an updated pointer to the macro data buffer; or,
24531 on error, issues a complaint and returns NULL. */
24533 static const gdb_byte
*
24534 skip_unknown_opcode (unsigned int opcode
,
24535 const gdb_byte
**opcode_definitions
,
24536 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24538 unsigned int offset_size
,
24539 struct dwarf2_section_info
*section
)
24541 unsigned int bytes_read
, i
;
24543 const gdb_byte
*defn
;
24545 if (opcode_definitions
[opcode
] == NULL
)
24547 complaint (&symfile_complaints
,
24548 _("unrecognized DW_MACFINO opcode 0x%x"),
24553 defn
= opcode_definitions
[opcode
];
24554 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24555 defn
+= bytes_read
;
24557 for (i
= 0; i
< arg
; ++i
)
24559 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24560 (enum dwarf_form
) defn
[i
], offset_size
,
24562 if (mac_ptr
== NULL
)
24564 /* skip_form_bytes already issued the complaint. */
24572 /* A helper function which parses the header of a macro section.
24573 If the macro section is the extended (for now called "GNU") type,
24574 then this updates *OFFSET_SIZE. Returns a pointer to just after
24575 the header, or issues a complaint and returns NULL on error. */
24577 static const gdb_byte
*
24578 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24580 const gdb_byte
*mac_ptr
,
24581 unsigned int *offset_size
,
24582 int section_is_gnu
)
24584 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24586 if (section_is_gnu
)
24588 unsigned int version
, flags
;
24590 version
= read_2_bytes (abfd
, mac_ptr
);
24591 if (version
!= 4 && version
!= 5)
24593 complaint (&symfile_complaints
,
24594 _("unrecognized version `%d' in .debug_macro section"),
24600 flags
= read_1_byte (abfd
, mac_ptr
);
24602 *offset_size
= (flags
& 1) ? 8 : 4;
24604 if ((flags
& 2) != 0)
24605 /* We don't need the line table offset. */
24606 mac_ptr
+= *offset_size
;
24608 /* Vendor opcode descriptions. */
24609 if ((flags
& 4) != 0)
24611 unsigned int i
, count
;
24613 count
= read_1_byte (abfd
, mac_ptr
);
24615 for (i
= 0; i
< count
; ++i
)
24617 unsigned int opcode
, bytes_read
;
24620 opcode
= read_1_byte (abfd
, mac_ptr
);
24622 opcode_definitions
[opcode
] = mac_ptr
;
24623 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24624 mac_ptr
+= bytes_read
;
24633 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24634 including DW_MACRO_import. */
24637 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24639 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24640 struct macro_source_file
*current_file
,
24641 struct line_header
*lh
,
24642 struct dwarf2_section_info
*section
,
24643 int section_is_gnu
, int section_is_dwz
,
24644 unsigned int offset_size
,
24645 htab_t include_hash
)
24647 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24648 enum dwarf_macro_record_type macinfo_type
;
24649 int at_commandline
;
24650 const gdb_byte
*opcode_definitions
[256];
24652 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24653 &offset_size
, section_is_gnu
);
24654 if (mac_ptr
== NULL
)
24656 /* We already issued a complaint. */
24660 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24661 GDB is still reading the definitions from command line. First
24662 DW_MACINFO_start_file will need to be ignored as it was already executed
24663 to create CURRENT_FILE for the main source holding also the command line
24664 definitions. On first met DW_MACINFO_start_file this flag is reset to
24665 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24667 at_commandline
= 1;
24671 /* Do we at least have room for a macinfo type byte? */
24672 if (mac_ptr
>= mac_end
)
24674 dwarf2_section_buffer_overflow_complaint (section
);
24678 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24681 /* Note that we rely on the fact that the corresponding GNU and
24682 DWARF constants are the same. */
24684 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24685 switch (macinfo_type
)
24687 /* A zero macinfo type indicates the end of the macro
24692 case DW_MACRO_define
:
24693 case DW_MACRO_undef
:
24694 case DW_MACRO_define_strp
:
24695 case DW_MACRO_undef_strp
:
24696 case DW_MACRO_define_sup
:
24697 case DW_MACRO_undef_sup
:
24699 unsigned int bytes_read
;
24704 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24705 mac_ptr
+= bytes_read
;
24707 if (macinfo_type
== DW_MACRO_define
24708 || macinfo_type
== DW_MACRO_undef
)
24710 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24711 mac_ptr
+= bytes_read
;
24715 LONGEST str_offset
;
24717 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24718 mac_ptr
+= offset_size
;
24720 if (macinfo_type
== DW_MACRO_define_sup
24721 || macinfo_type
== DW_MACRO_undef_sup
24724 struct dwz_file
*dwz
24725 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24727 body
= read_indirect_string_from_dwz (objfile
,
24731 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24735 is_define
= (macinfo_type
== DW_MACRO_define
24736 || macinfo_type
== DW_MACRO_define_strp
24737 || macinfo_type
== DW_MACRO_define_sup
);
24738 if (! current_file
)
24740 /* DWARF violation as no main source is present. */
24741 complaint (&symfile_complaints
,
24742 _("debug info with no main source gives macro %s "
24744 is_define
? _("definition") : _("undefinition"),
24748 if ((line
== 0 && !at_commandline
)
24749 || (line
!= 0 && at_commandline
))
24750 complaint (&symfile_complaints
,
24751 _("debug info gives %s macro %s with %s line %d: %s"),
24752 at_commandline
? _("command-line") : _("in-file"),
24753 is_define
? _("definition") : _("undefinition"),
24754 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24757 parse_macro_definition (current_file
, line
, body
);
24760 gdb_assert (macinfo_type
== DW_MACRO_undef
24761 || macinfo_type
== DW_MACRO_undef_strp
24762 || macinfo_type
== DW_MACRO_undef_sup
);
24763 macro_undef (current_file
, line
, body
);
24768 case DW_MACRO_start_file
:
24770 unsigned int bytes_read
;
24773 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24774 mac_ptr
+= bytes_read
;
24775 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24776 mac_ptr
+= bytes_read
;
24778 if ((line
== 0 && !at_commandline
)
24779 || (line
!= 0 && at_commandline
))
24780 complaint (&symfile_complaints
,
24781 _("debug info gives source %d included "
24782 "from %s at %s line %d"),
24783 file
, at_commandline
? _("command-line") : _("file"),
24784 line
== 0 ? _("zero") : _("non-zero"), line
);
24786 if (at_commandline
)
24788 /* This DW_MACRO_start_file was executed in the
24790 at_commandline
= 0;
24793 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24797 case DW_MACRO_end_file
:
24798 if (! current_file
)
24799 complaint (&symfile_complaints
,
24800 _("macro debug info has an unmatched "
24801 "`close_file' directive"));
24804 current_file
= current_file
->included_by
;
24805 if (! current_file
)
24807 enum dwarf_macro_record_type next_type
;
24809 /* GCC circa March 2002 doesn't produce the zero
24810 type byte marking the end of the compilation
24811 unit. Complain if it's not there, but exit no
24814 /* Do we at least have room for a macinfo type byte? */
24815 if (mac_ptr
>= mac_end
)
24817 dwarf2_section_buffer_overflow_complaint (section
);
24821 /* We don't increment mac_ptr here, so this is just
24824 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24826 if (next_type
!= 0)
24827 complaint (&symfile_complaints
,
24828 _("no terminating 0-type entry for "
24829 "macros in `.debug_macinfo' section"));
24836 case DW_MACRO_import
:
24837 case DW_MACRO_import_sup
:
24841 bfd
*include_bfd
= abfd
;
24842 struct dwarf2_section_info
*include_section
= section
;
24843 const gdb_byte
*include_mac_end
= mac_end
;
24844 int is_dwz
= section_is_dwz
;
24845 const gdb_byte
*new_mac_ptr
;
24847 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24848 mac_ptr
+= offset_size
;
24850 if (macinfo_type
== DW_MACRO_import_sup
)
24852 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24854 dwarf2_read_section (objfile
, &dwz
->macro
);
24856 include_section
= &dwz
->macro
;
24857 include_bfd
= get_section_bfd_owner (include_section
);
24858 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24862 new_mac_ptr
= include_section
->buffer
+ offset
;
24863 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24867 /* This has actually happened; see
24868 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24869 complaint (&symfile_complaints
,
24870 _("recursive DW_MACRO_import in "
24871 ".debug_macro section"));
24875 *slot
= (void *) new_mac_ptr
;
24877 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24878 include_bfd
, new_mac_ptr
,
24879 include_mac_end
, current_file
, lh
,
24880 section
, section_is_gnu
, is_dwz
,
24881 offset_size
, include_hash
);
24883 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24888 case DW_MACINFO_vendor_ext
:
24889 if (!section_is_gnu
)
24891 unsigned int bytes_read
;
24893 /* This reads the constant, but since we don't recognize
24894 any vendor extensions, we ignore it. */
24895 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24896 mac_ptr
+= bytes_read
;
24897 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24898 mac_ptr
+= bytes_read
;
24900 /* We don't recognize any vendor extensions. */
24906 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24907 mac_ptr
, mac_end
, abfd
, offset_size
,
24909 if (mac_ptr
== NULL
)
24914 } while (macinfo_type
!= 0);
24918 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24919 int section_is_gnu
)
24921 struct dwarf2_per_objfile
*dwarf2_per_objfile
24922 = cu
->per_cu
->dwarf2_per_objfile
;
24923 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24924 struct line_header
*lh
= cu
->line_header
;
24926 const gdb_byte
*mac_ptr
, *mac_end
;
24927 struct macro_source_file
*current_file
= 0;
24928 enum dwarf_macro_record_type macinfo_type
;
24929 unsigned int offset_size
= cu
->header
.offset_size
;
24930 const gdb_byte
*opcode_definitions
[256];
24932 struct dwarf2_section_info
*section
;
24933 const char *section_name
;
24935 if (cu
->dwo_unit
!= NULL
)
24937 if (section_is_gnu
)
24939 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24940 section_name
= ".debug_macro.dwo";
24944 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24945 section_name
= ".debug_macinfo.dwo";
24950 if (section_is_gnu
)
24952 section
= &dwarf2_per_objfile
->macro
;
24953 section_name
= ".debug_macro";
24957 section
= &dwarf2_per_objfile
->macinfo
;
24958 section_name
= ".debug_macinfo";
24962 dwarf2_read_section (objfile
, section
);
24963 if (section
->buffer
== NULL
)
24965 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24968 abfd
= get_section_bfd_owner (section
);
24970 /* First pass: Find the name of the base filename.
24971 This filename is needed in order to process all macros whose definition
24972 (or undefinition) comes from the command line. These macros are defined
24973 before the first DW_MACINFO_start_file entry, and yet still need to be
24974 associated to the base file.
24976 To determine the base file name, we scan the macro definitions until we
24977 reach the first DW_MACINFO_start_file entry. We then initialize
24978 CURRENT_FILE accordingly so that any macro definition found before the
24979 first DW_MACINFO_start_file can still be associated to the base file. */
24981 mac_ptr
= section
->buffer
+ offset
;
24982 mac_end
= section
->buffer
+ section
->size
;
24984 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24985 &offset_size
, section_is_gnu
);
24986 if (mac_ptr
== NULL
)
24988 /* We already issued a complaint. */
24994 /* Do we at least have room for a macinfo type byte? */
24995 if (mac_ptr
>= mac_end
)
24997 /* Complaint is printed during the second pass as GDB will probably
24998 stop the first pass earlier upon finding
24999 DW_MACINFO_start_file. */
25003 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25006 /* Note that we rely on the fact that the corresponding GNU and
25007 DWARF constants are the same. */
25009 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25010 switch (macinfo_type
)
25012 /* A zero macinfo type indicates the end of the macro
25017 case DW_MACRO_define
:
25018 case DW_MACRO_undef
:
25019 /* Only skip the data by MAC_PTR. */
25021 unsigned int bytes_read
;
25023 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25024 mac_ptr
+= bytes_read
;
25025 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25026 mac_ptr
+= bytes_read
;
25030 case DW_MACRO_start_file
:
25032 unsigned int bytes_read
;
25035 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25036 mac_ptr
+= bytes_read
;
25037 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25038 mac_ptr
+= bytes_read
;
25040 current_file
= macro_start_file (file
, line
, current_file
, lh
);
25044 case DW_MACRO_end_file
:
25045 /* No data to skip by MAC_PTR. */
25048 case DW_MACRO_define_strp
:
25049 case DW_MACRO_undef_strp
:
25050 case DW_MACRO_define_sup
:
25051 case DW_MACRO_undef_sup
:
25053 unsigned int bytes_read
;
25055 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25056 mac_ptr
+= bytes_read
;
25057 mac_ptr
+= offset_size
;
25061 case DW_MACRO_import
:
25062 case DW_MACRO_import_sup
:
25063 /* Note that, according to the spec, a transparent include
25064 chain cannot call DW_MACRO_start_file. So, we can just
25065 skip this opcode. */
25066 mac_ptr
+= offset_size
;
25069 case DW_MACINFO_vendor_ext
:
25070 /* Only skip the data by MAC_PTR. */
25071 if (!section_is_gnu
)
25073 unsigned int bytes_read
;
25075 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25076 mac_ptr
+= bytes_read
;
25077 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25078 mac_ptr
+= bytes_read
;
25083 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25084 mac_ptr
, mac_end
, abfd
, offset_size
,
25086 if (mac_ptr
== NULL
)
25091 } while (macinfo_type
!= 0 && current_file
== NULL
);
25093 /* Second pass: Process all entries.
25095 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25096 command-line macro definitions/undefinitions. This flag is unset when we
25097 reach the first DW_MACINFO_start_file entry. */
25099 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25101 NULL
, xcalloc
, xfree
));
25102 mac_ptr
= section
->buffer
+ offset
;
25103 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25104 *slot
= (void *) mac_ptr
;
25105 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
25106 abfd
, mac_ptr
, mac_end
,
25107 current_file
, lh
, section
,
25108 section_is_gnu
, 0, offset_size
,
25109 include_hash
.get ());
25112 /* Check if the attribute's form is a DW_FORM_block*
25113 if so return true else false. */
25116 attr_form_is_block (const struct attribute
*attr
)
25118 return (attr
== NULL
? 0 :
25119 attr
->form
== DW_FORM_block1
25120 || attr
->form
== DW_FORM_block2
25121 || attr
->form
== DW_FORM_block4
25122 || attr
->form
== DW_FORM_block
25123 || attr
->form
== DW_FORM_exprloc
);
25126 /* Return non-zero if ATTR's value is a section offset --- classes
25127 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25128 You may use DW_UNSND (attr) to retrieve such offsets.
25130 Section 7.5.4, "Attribute Encodings", explains that no attribute
25131 may have a value that belongs to more than one of these classes; it
25132 would be ambiguous if we did, because we use the same forms for all
25136 attr_form_is_section_offset (const struct attribute
*attr
)
25138 return (attr
->form
== DW_FORM_data4
25139 || attr
->form
== DW_FORM_data8
25140 || attr
->form
== DW_FORM_sec_offset
);
25143 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25144 zero otherwise. When this function returns true, you can apply
25145 dwarf2_get_attr_constant_value to it.
25147 However, note that for some attributes you must check
25148 attr_form_is_section_offset before using this test. DW_FORM_data4
25149 and DW_FORM_data8 are members of both the constant class, and of
25150 the classes that contain offsets into other debug sections
25151 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25152 that, if an attribute's can be either a constant or one of the
25153 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25154 taken as section offsets, not constants.
25156 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25157 cannot handle that. */
25160 attr_form_is_constant (const struct attribute
*attr
)
25162 switch (attr
->form
)
25164 case DW_FORM_sdata
:
25165 case DW_FORM_udata
:
25166 case DW_FORM_data1
:
25167 case DW_FORM_data2
:
25168 case DW_FORM_data4
:
25169 case DW_FORM_data8
:
25170 case DW_FORM_implicit_const
:
25178 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25179 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25182 attr_form_is_ref (const struct attribute
*attr
)
25184 switch (attr
->form
)
25186 case DW_FORM_ref_addr
:
25191 case DW_FORM_ref_udata
:
25192 case DW_FORM_GNU_ref_alt
:
25199 /* Return the .debug_loc section to use for CU.
25200 For DWO files use .debug_loc.dwo. */
25202 static struct dwarf2_section_info
*
25203 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25205 struct dwarf2_per_objfile
*dwarf2_per_objfile
25206 = cu
->per_cu
->dwarf2_per_objfile
;
25210 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25212 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25214 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25215 : &dwarf2_per_objfile
->loc
);
25218 /* A helper function that fills in a dwarf2_loclist_baton. */
25221 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25222 struct dwarf2_loclist_baton
*baton
,
25223 const struct attribute
*attr
)
25225 struct dwarf2_per_objfile
*dwarf2_per_objfile
25226 = cu
->per_cu
->dwarf2_per_objfile
;
25227 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25229 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25231 baton
->per_cu
= cu
->per_cu
;
25232 gdb_assert (baton
->per_cu
);
25233 /* We don't know how long the location list is, but make sure we
25234 don't run off the edge of the section. */
25235 baton
->size
= section
->size
- DW_UNSND (attr
);
25236 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25237 baton
->base_address
= cu
->base_address
;
25238 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25242 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25243 struct dwarf2_cu
*cu
, int is_block
)
25245 struct dwarf2_per_objfile
*dwarf2_per_objfile
25246 = cu
->per_cu
->dwarf2_per_objfile
;
25247 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25248 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25250 if (attr_form_is_section_offset (attr
)
25251 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25252 the section. If so, fall through to the complaint in the
25254 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25256 struct dwarf2_loclist_baton
*baton
;
25258 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25260 fill_in_loclist_baton (cu
, baton
, attr
);
25262 if (cu
->base_known
== 0)
25263 complaint (&symfile_complaints
,
25264 _("Location list used without "
25265 "specifying the CU base address."));
25267 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25268 ? dwarf2_loclist_block_index
25269 : dwarf2_loclist_index
);
25270 SYMBOL_LOCATION_BATON (sym
) = baton
;
25274 struct dwarf2_locexpr_baton
*baton
;
25276 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25277 baton
->per_cu
= cu
->per_cu
;
25278 gdb_assert (baton
->per_cu
);
25280 if (attr_form_is_block (attr
))
25282 /* Note that we're just copying the block's data pointer
25283 here, not the actual data. We're still pointing into the
25284 info_buffer for SYM's objfile; right now we never release
25285 that buffer, but when we do clean up properly this may
25287 baton
->size
= DW_BLOCK (attr
)->size
;
25288 baton
->data
= DW_BLOCK (attr
)->data
;
25292 dwarf2_invalid_attrib_class_complaint ("location description",
25293 SYMBOL_NATURAL_NAME (sym
));
25297 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25298 ? dwarf2_locexpr_block_index
25299 : dwarf2_locexpr_index
);
25300 SYMBOL_LOCATION_BATON (sym
) = baton
;
25304 /* Return the OBJFILE associated with the compilation unit CU. If CU
25305 came from a separate debuginfo file, then the master objfile is
25309 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25311 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25313 /* Return the master objfile, so that we can report and look up the
25314 correct file containing this variable. */
25315 if (objfile
->separate_debug_objfile_backlink
)
25316 objfile
= objfile
->separate_debug_objfile_backlink
;
25321 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25322 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25323 CU_HEADERP first. */
25325 static const struct comp_unit_head
*
25326 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25327 struct dwarf2_per_cu_data
*per_cu
)
25329 const gdb_byte
*info_ptr
;
25332 return &per_cu
->cu
->header
;
25334 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25336 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25337 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25338 rcuh_kind::COMPILE
);
25343 /* Return the address size given in the compilation unit header for CU. */
25346 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25348 struct comp_unit_head cu_header_local
;
25349 const struct comp_unit_head
*cu_headerp
;
25351 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25353 return cu_headerp
->addr_size
;
25356 /* Return the offset size given in the compilation unit header for CU. */
25359 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25361 struct comp_unit_head cu_header_local
;
25362 const struct comp_unit_head
*cu_headerp
;
25364 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25366 return cu_headerp
->offset_size
;
25369 /* See its dwarf2loc.h declaration. */
25372 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25374 struct comp_unit_head cu_header_local
;
25375 const struct comp_unit_head
*cu_headerp
;
25377 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25379 if (cu_headerp
->version
== 2)
25380 return cu_headerp
->addr_size
;
25382 return cu_headerp
->offset_size
;
25385 /* Return the text offset of the CU. The returned offset comes from
25386 this CU's objfile. If this objfile came from a separate debuginfo
25387 file, then the offset may be different from the corresponding
25388 offset in the parent objfile. */
25391 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25393 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25395 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25398 /* Return DWARF version number of PER_CU. */
25401 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25403 return per_cu
->dwarf_version
;
25406 /* Locate the .debug_info compilation unit from CU's objfile which contains
25407 the DIE at OFFSET. Raises an error on failure. */
25409 static struct dwarf2_per_cu_data
*
25410 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25411 unsigned int offset_in_dwz
,
25412 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25414 struct dwarf2_per_cu_data
*this_cu
;
25416 const sect_offset
*cu_off
;
25419 high
= dwarf2_per_objfile
->n_comp_units
- 1;
25422 struct dwarf2_per_cu_data
*mid_cu
;
25423 int mid
= low
+ (high
- low
) / 2;
25425 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25426 cu_off
= &mid_cu
->sect_off
;
25427 if (mid_cu
->is_dwz
> offset_in_dwz
25428 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25433 gdb_assert (low
== high
);
25434 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25435 cu_off
= &this_cu
->sect_off
;
25436 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25438 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25439 error (_("Dwarf Error: could not find partial DIE containing "
25440 "offset %s [in module %s]"),
25441 sect_offset_str (sect_off
),
25442 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25444 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25446 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25450 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25451 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
25452 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25453 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25454 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25459 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25461 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25462 : per_cu (per_cu_
),
25465 checked_producer (0),
25466 producer_is_gxx_lt_4_6 (0),
25467 producer_is_gcc_lt_4_3 (0),
25468 producer_is_icc_lt_14 (0),
25469 processing_has_namespace_info (0)
25474 /* Destroy a dwarf2_cu. */
25476 dwarf2_cu::~dwarf2_cu ()
25481 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25484 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25485 enum language pretend_language
)
25487 struct attribute
*attr
;
25489 /* Set the language we're debugging. */
25490 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25492 set_cu_language (DW_UNSND (attr
), cu
);
25495 cu
->language
= pretend_language
;
25496 cu
->language_defn
= language_def (cu
->language
);
25499 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25502 /* Free all cached compilation units. */
25505 free_cached_comp_units (void *data
)
25507 struct dwarf2_per_objfile
*dwarf2_per_objfile
25508 = (struct dwarf2_per_objfile
*) data
;
25510 dwarf2_per_objfile
->free_cached_comp_units ();
25513 /* Increase the age counter on each cached compilation unit, and free
25514 any that are too old. */
25517 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25519 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25521 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25522 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25523 while (per_cu
!= NULL
)
25525 per_cu
->cu
->last_used
++;
25526 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25527 dwarf2_mark (per_cu
->cu
);
25528 per_cu
= per_cu
->cu
->read_in_chain
;
25531 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25532 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25533 while (per_cu
!= NULL
)
25535 struct dwarf2_per_cu_data
*next_cu
;
25537 next_cu
= per_cu
->cu
->read_in_chain
;
25539 if (!per_cu
->cu
->mark
)
25542 *last_chain
= next_cu
;
25545 last_chain
= &per_cu
->cu
->read_in_chain
;
25551 /* Remove a single compilation unit from the cache. */
25554 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25556 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25557 struct dwarf2_per_objfile
*dwarf2_per_objfile
25558 = target_per_cu
->dwarf2_per_objfile
;
25560 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25561 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25562 while (per_cu
!= NULL
)
25564 struct dwarf2_per_cu_data
*next_cu
;
25566 next_cu
= per_cu
->cu
->read_in_chain
;
25568 if (per_cu
== target_per_cu
)
25572 *last_chain
= next_cu
;
25576 last_chain
= &per_cu
->cu
->read_in_chain
;
25582 /* Release all extra memory associated with OBJFILE. */
25585 dwarf2_free_objfile (struct objfile
*objfile
)
25587 struct dwarf2_per_objfile
*dwarf2_per_objfile
25588 = get_dwarf2_per_objfile (objfile
);
25590 delete dwarf2_per_objfile
;
25593 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25594 We store these in a hash table separate from the DIEs, and preserve them
25595 when the DIEs are flushed out of cache.
25597 The CU "per_cu" pointer is needed because offset alone is not enough to
25598 uniquely identify the type. A file may have multiple .debug_types sections,
25599 or the type may come from a DWO file. Furthermore, while it's more logical
25600 to use per_cu->section+offset, with Fission the section with the data is in
25601 the DWO file but we don't know that section at the point we need it.
25602 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25603 because we can enter the lookup routine, get_die_type_at_offset, from
25604 outside this file, and thus won't necessarily have PER_CU->cu.
25605 Fortunately, PER_CU is stable for the life of the objfile. */
25607 struct dwarf2_per_cu_offset_and_type
25609 const struct dwarf2_per_cu_data
*per_cu
;
25610 sect_offset sect_off
;
25614 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25617 per_cu_offset_and_type_hash (const void *item
)
25619 const struct dwarf2_per_cu_offset_and_type
*ofs
25620 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25622 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25625 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25628 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25630 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25631 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25632 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25633 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25635 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25636 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25639 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25640 table if necessary. For convenience, return TYPE.
25642 The DIEs reading must have careful ordering to:
25643 * Not cause infite loops trying to read in DIEs as a prerequisite for
25644 reading current DIE.
25645 * Not trying to dereference contents of still incompletely read in types
25646 while reading in other DIEs.
25647 * Enable referencing still incompletely read in types just by a pointer to
25648 the type without accessing its fields.
25650 Therefore caller should follow these rules:
25651 * Try to fetch any prerequisite types we may need to build this DIE type
25652 before building the type and calling set_die_type.
25653 * After building type call set_die_type for current DIE as soon as
25654 possible before fetching more types to complete the current type.
25655 * Make the type as complete as possible before fetching more types. */
25657 static struct type
*
25658 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25660 struct dwarf2_per_objfile
*dwarf2_per_objfile
25661 = cu
->per_cu
->dwarf2_per_objfile
;
25662 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25663 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25664 struct attribute
*attr
;
25665 struct dynamic_prop prop
;
25667 /* For Ada types, make sure that the gnat-specific data is always
25668 initialized (if not already set). There are a few types where
25669 we should not be doing so, because the type-specific area is
25670 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25671 where the type-specific area is used to store the floatformat).
25672 But this is not a problem, because the gnat-specific information
25673 is actually not needed for these types. */
25674 if (need_gnat_info (cu
)
25675 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25676 && TYPE_CODE (type
) != TYPE_CODE_FLT
25677 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25678 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25679 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25680 && !HAVE_GNAT_AUX_INFO (type
))
25681 INIT_GNAT_SPECIFIC (type
);
25683 /* Read DW_AT_allocated and set in type. */
25684 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25685 if (attr_form_is_block (attr
))
25687 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25688 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25690 else if (attr
!= NULL
)
25692 complaint (&symfile_complaints
,
25693 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25694 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25695 sect_offset_str (die
->sect_off
));
25698 /* Read DW_AT_associated and set in type. */
25699 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25700 if (attr_form_is_block (attr
))
25702 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25703 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25705 else if (attr
!= NULL
)
25707 complaint (&symfile_complaints
,
25708 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25709 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25710 sect_offset_str (die
->sect_off
));
25713 /* Read DW_AT_data_location and set in type. */
25714 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25715 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25716 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25718 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25720 dwarf2_per_objfile
->die_type_hash
=
25721 htab_create_alloc_ex (127,
25722 per_cu_offset_and_type_hash
,
25723 per_cu_offset_and_type_eq
,
25725 &objfile
->objfile_obstack
,
25726 hashtab_obstack_allocate
,
25727 dummy_obstack_deallocate
);
25730 ofs
.per_cu
= cu
->per_cu
;
25731 ofs
.sect_off
= die
->sect_off
;
25733 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25734 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25736 complaint (&symfile_complaints
,
25737 _("A problem internal to GDB: DIE %s has type already set"),
25738 sect_offset_str (die
->sect_off
));
25739 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25740 struct dwarf2_per_cu_offset_and_type
);
25745 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25746 or return NULL if the die does not have a saved type. */
25748 static struct type
*
25749 get_die_type_at_offset (sect_offset sect_off
,
25750 struct dwarf2_per_cu_data
*per_cu
)
25752 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25753 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25755 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25758 ofs
.per_cu
= per_cu
;
25759 ofs
.sect_off
= sect_off
;
25760 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25761 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25768 /* Look up the type for DIE in CU in die_type_hash,
25769 or return NULL if DIE does not have a saved type. */
25771 static struct type
*
25772 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25774 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25777 /* Add a dependence relationship from CU to REF_PER_CU. */
25780 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25781 struct dwarf2_per_cu_data
*ref_per_cu
)
25785 if (cu
->dependencies
== NULL
)
25787 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25788 NULL
, &cu
->comp_unit_obstack
,
25789 hashtab_obstack_allocate
,
25790 dummy_obstack_deallocate
);
25792 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25794 *slot
= ref_per_cu
;
25797 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25798 Set the mark field in every compilation unit in the
25799 cache that we must keep because we are keeping CU. */
25802 dwarf2_mark_helper (void **slot
, void *data
)
25804 struct dwarf2_per_cu_data
*per_cu
;
25806 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25808 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25809 reading of the chain. As such dependencies remain valid it is not much
25810 useful to track and undo them during QUIT cleanups. */
25811 if (per_cu
->cu
== NULL
)
25814 if (per_cu
->cu
->mark
)
25816 per_cu
->cu
->mark
= 1;
25818 if (per_cu
->cu
->dependencies
!= NULL
)
25819 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25824 /* Set the mark field in CU and in every other compilation unit in the
25825 cache that we must keep because we are keeping CU. */
25828 dwarf2_mark (struct dwarf2_cu
*cu
)
25833 if (cu
->dependencies
!= NULL
)
25834 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25838 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25842 per_cu
->cu
->mark
= 0;
25843 per_cu
= per_cu
->cu
->read_in_chain
;
25847 /* Trivial hash function for partial_die_info: the hash value of a DIE
25848 is its offset in .debug_info for this objfile. */
25851 partial_die_hash (const void *item
)
25853 const struct partial_die_info
*part_die
25854 = (const struct partial_die_info
*) item
;
25856 return to_underlying (part_die
->sect_off
);
25859 /* Trivial comparison function for partial_die_info structures: two DIEs
25860 are equal if they have the same offset. */
25863 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25865 const struct partial_die_info
*part_die_lhs
25866 = (const struct partial_die_info
*) item_lhs
;
25867 const struct partial_die_info
*part_die_rhs
25868 = (const struct partial_die_info
*) item_rhs
;
25870 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25873 static struct cmd_list_element
*set_dwarf_cmdlist
;
25874 static struct cmd_list_element
*show_dwarf_cmdlist
;
25877 set_dwarf_cmd (const char *args
, int from_tty
)
25879 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25884 show_dwarf_cmd (const char *args
, int from_tty
)
25886 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25889 /* The "save gdb-index" command. */
25891 /* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
25895 file_write (FILE *file
, const void *data
, size_t size
)
25897 if (fwrite (data
, 1, size
, file
) != size
)
25898 error (_("couldn't data write to file"));
25901 /* Write the contents of VEC to FILE, with error checking. */
25903 template<typename Elem
, typename Alloc
>
25905 file_write (FILE *file
, const std::vector
<Elem
, Alloc
> &vec
)
25907 file_write (file
, vec
.data (), vec
.size () * sizeof (vec
[0]));
25910 /* In-memory buffer to prepare data to be written later to a file. */
25914 /* Copy DATA to the end of the buffer. */
25915 template<typename T
>
25916 void append_data (const T
&data
)
25918 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
25919 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
25920 grow (sizeof (data
)));
25923 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
25924 terminating zero is appended too. */
25925 void append_cstr0 (const char *cstr
)
25927 const size_t size
= strlen (cstr
) + 1;
25928 std::copy (cstr
, cstr
+ size
, grow (size
));
25931 /* Store INPUT as ULEB128 to the end of buffer. */
25932 void append_unsigned_leb128 (ULONGEST input
)
25936 gdb_byte output
= input
& 0x7f;
25940 append_data (output
);
25946 /* Accept a host-format integer in VAL and append it to the buffer
25947 as a target-format integer which is LEN bytes long. */
25948 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
25950 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
25953 /* Return the size of the buffer. */
25954 size_t size () const
25956 return m_vec
.size ();
25959 /* Return true iff the buffer is empty. */
25960 bool empty () const
25962 return m_vec
.empty ();
25965 /* Write the buffer to FILE. */
25966 void file_write (FILE *file
) const
25968 ::file_write (file
, m_vec
);
25972 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
25973 the start of the new block. */
25974 gdb_byte
*grow (size_t size
)
25976 m_vec
.resize (m_vec
.size () + size
);
25977 return &*m_vec
.end () - size
;
25980 gdb::byte_vector m_vec
;
25983 /* An entry in the symbol table. */
25984 struct symtab_index_entry
25986 /* The name of the symbol. */
25988 /* The offset of the name in the constant pool. */
25989 offset_type index_offset
;
25990 /* A sorted vector of the indices of all the CUs that hold an object
25992 std::vector
<offset_type
> cu_indices
;
25995 /* The symbol table. This is a power-of-2-sized hash table. */
25996 struct mapped_symtab
26000 data
.resize (1024);
26003 offset_type n_elements
= 0;
26004 std::vector
<symtab_index_entry
> data
;
26007 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
26010 Function is used only during write_hash_table so no index format backward
26011 compatibility is needed. */
26013 static symtab_index_entry
&
26014 find_slot (struct mapped_symtab
*symtab
, const char *name
)
26016 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
26018 index
= hash
& (symtab
->data
.size () - 1);
26019 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
26023 if (symtab
->data
[index
].name
== NULL
26024 || strcmp (name
, symtab
->data
[index
].name
) == 0)
26025 return symtab
->data
[index
];
26026 index
= (index
+ step
) & (symtab
->data
.size () - 1);
26030 /* Expand SYMTAB's hash table. */
26033 hash_expand (struct mapped_symtab
*symtab
)
26035 auto old_entries
= std::move (symtab
->data
);
26037 symtab
->data
.clear ();
26038 symtab
->data
.resize (old_entries
.size () * 2);
26040 for (auto &it
: old_entries
)
26041 if (it
.name
!= NULL
)
26043 auto &ref
= find_slot (symtab
, it
.name
);
26044 ref
= std::move (it
);
26048 /* Add an entry to SYMTAB. NAME is the name of the symbol.
26049 CU_INDEX is the index of the CU in which the symbol appears.
26050 IS_STATIC is one if the symbol is static, otherwise zero (global). */
26053 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
26054 int is_static
, gdb_index_symbol_kind kind
,
26055 offset_type cu_index
)
26057 offset_type cu_index_and_attrs
;
26059 ++symtab
->n_elements
;
26060 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
26061 hash_expand (symtab
);
26063 symtab_index_entry
&slot
= find_slot (symtab
, name
);
26064 if (slot
.name
== NULL
)
26067 /* index_offset is set later. */
26070 cu_index_and_attrs
= 0;
26071 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
26072 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
26073 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
26075 /* We don't want to record an index value twice as we want to avoid the
26077 We process all global symbols and then all static symbols
26078 (which would allow us to avoid the duplication by only having to check
26079 the last entry pushed), but a symbol could have multiple kinds in one CU.
26080 To keep things simple we don't worry about the duplication here and
26081 sort and uniqufy the list after we've processed all symbols. */
26082 slot
.cu_indices
.push_back (cu_index_and_attrs
);
26085 /* Sort and remove duplicates of all symbols' cu_indices lists. */
26088 uniquify_cu_indices (struct mapped_symtab
*symtab
)
26090 for (auto &entry
: symtab
->data
)
26092 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
26094 auto &cu_indices
= entry
.cu_indices
;
26095 std::sort (cu_indices
.begin (), cu_indices
.end ());
26096 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
26097 cu_indices
.erase (from
, cu_indices
.end ());
26102 /* A form of 'const char *' suitable for container keys. Only the
26103 pointer is stored. The strings themselves are compared, not the
26108 c_str_view (const char *cstr
)
26112 bool operator== (const c_str_view
&other
) const
26114 return strcmp (m_cstr
, other
.m_cstr
) == 0;
26117 /* Return the underlying C string. Note, the returned string is
26118 only a reference with lifetime of this object. */
26119 const char *c_str () const
26125 friend class c_str_view_hasher
;
26126 const char *const m_cstr
;
26129 /* A std::unordered_map::hasher for c_str_view that uses the right
26130 hash function for strings in a mapped index. */
26131 class c_str_view_hasher
26134 size_t operator () (const c_str_view
&x
) const
26136 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
26140 /* A std::unordered_map::hasher for std::vector<>. */
26141 template<typename T
>
26142 class vector_hasher
26145 size_t operator () (const std::vector
<T
> &key
) const
26147 return iterative_hash (key
.data (),
26148 sizeof (key
.front ()) * key
.size (), 0);
26152 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
26153 constant pool entries going into the data buffer CPOOL. */
26156 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
26159 /* Elements are sorted vectors of the indices of all the CUs that
26160 hold an object of this name. */
26161 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
26162 vector_hasher
<offset_type
>>
26165 /* We add all the index vectors to the constant pool first, to
26166 ensure alignment is ok. */
26167 for (symtab_index_entry
&entry
: symtab
->data
)
26169 if (entry
.name
== NULL
)
26171 gdb_assert (entry
.index_offset
== 0);
26173 /* Finding before inserting is faster than always trying to
26174 insert, because inserting always allocates a node, does the
26175 lookup, and then destroys the new node if another node
26176 already had the same key. C++17 try_emplace will avoid
26179 = symbol_hash_table
.find (entry
.cu_indices
);
26180 if (found
!= symbol_hash_table
.end ())
26182 entry
.index_offset
= found
->second
;
26186 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
26187 entry
.index_offset
= cpool
.size ();
26188 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
26189 for (const auto index
: entry
.cu_indices
)
26190 cpool
.append_data (MAYBE_SWAP (index
));
26194 /* Now write out the hash table. */
26195 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
26196 for (const auto &entry
: symtab
->data
)
26198 offset_type str_off
, vec_off
;
26200 if (entry
.name
!= NULL
)
26202 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
26203 if (insertpair
.second
)
26204 cpool
.append_cstr0 (entry
.name
);
26205 str_off
= insertpair
.first
->second
;
26206 vec_off
= entry
.index_offset
;
26210 /* While 0 is a valid constant pool index, it is not valid
26211 to have 0 for both offsets. */
26216 output
.append_data (MAYBE_SWAP (str_off
));
26217 output
.append_data (MAYBE_SWAP (vec_off
));
26221 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
26223 /* Helper struct for building the address table. */
26224 struct addrmap_index_data
26226 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
26227 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
26230 struct objfile
*objfile
;
26231 data_buf
&addr_vec
;
26232 psym_index_map
&cu_index_htab
;
26234 /* Non-zero if the previous_* fields are valid.
26235 We can't write an entry until we see the next entry (since it is only then
26236 that we know the end of the entry). */
26237 int previous_valid
;
26238 /* Index of the CU in the table of all CUs in the index file. */
26239 unsigned int previous_cu_index
;
26240 /* Start address of the CU. */
26241 CORE_ADDR previous_cu_start
;
26244 /* Write an address entry to ADDR_VEC. */
26247 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
26248 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
26250 CORE_ADDR baseaddr
;
26252 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
26254 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
26255 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
26256 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
26259 /* Worker function for traversing an addrmap to build the address table. */
26262 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
26264 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
26265 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
26267 if (data
->previous_valid
)
26268 add_address_entry (data
->objfile
, data
->addr_vec
,
26269 data
->previous_cu_start
, start_addr
,
26270 data
->previous_cu_index
);
26272 data
->previous_cu_start
= start_addr
;
26275 const auto it
= data
->cu_index_htab
.find (pst
);
26276 gdb_assert (it
!= data
->cu_index_htab
.cend ());
26277 data
->previous_cu_index
= it
->second
;
26278 data
->previous_valid
= 1;
26281 data
->previous_valid
= 0;
26286 /* Write OBJFILE's address map to ADDR_VEC.
26287 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
26288 in the index file. */
26291 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
26292 psym_index_map
&cu_index_htab
)
26294 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
26296 /* When writing the address table, we have to cope with the fact that
26297 the addrmap iterator only provides the start of a region; we have to
26298 wait until the next invocation to get the start of the next region. */
26300 addrmap_index_data
.objfile
= objfile
;
26301 addrmap_index_data
.previous_valid
= 0;
26303 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
26304 &addrmap_index_data
);
26306 /* It's highly unlikely the last entry (end address = 0xff...ff)
26307 is valid, but we should still handle it.
26308 The end address is recorded as the start of the next region, but that
26309 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
26311 if (addrmap_index_data
.previous_valid
)
26312 add_address_entry (objfile
, addr_vec
,
26313 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
26314 addrmap_index_data
.previous_cu_index
);
26317 /* Return the symbol kind of PSYM. */
26319 static gdb_index_symbol_kind
26320 symbol_kind (struct partial_symbol
*psym
)
26322 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26323 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26331 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
26333 return GDB_INDEX_SYMBOL_KIND_TYPE
;
26335 case LOC_CONST_BYTES
:
26336 case LOC_OPTIMIZED_OUT
:
26338 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
26340 /* Note: It's currently impossible to recognize psyms as enum values
26341 short of reading the type info. For now punt. */
26342 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
26344 /* There are other LOC_FOO values that one might want to classify
26345 as variables, but dwarf2read.c doesn't currently use them. */
26346 return GDB_INDEX_SYMBOL_KIND_OTHER
;
26348 case STRUCT_DOMAIN
:
26349 return GDB_INDEX_SYMBOL_KIND_TYPE
;
26351 return GDB_INDEX_SYMBOL_KIND_OTHER
;
26355 /* Add a list of partial symbols to SYMTAB. */
26358 write_psymbols (struct mapped_symtab
*symtab
,
26359 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26360 struct partial_symbol
**psymp
,
26362 offset_type cu_index
,
26365 for (; count
-- > 0; ++psymp
)
26367 struct partial_symbol
*psym
= *psymp
;
26369 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
26370 error (_("Ada is not currently supported by the index"));
26372 /* Only add a given psymbol once. */
26373 if (psyms_seen
.insert (psym
).second
)
26375 gdb_index_symbol_kind kind
= symbol_kind (psym
);
26377 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
26378 is_static
, kind
, cu_index
);
26383 /* A helper struct used when iterating over debug_types. */
26384 struct signatured_type_index_data
26386 signatured_type_index_data (data_buf
&types_list_
,
26387 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
26388 : types_list (types_list_
), psyms_seen (psyms_seen_
)
26391 struct objfile
*objfile
;
26392 struct mapped_symtab
*symtab
;
26393 data_buf
&types_list
;
26394 std::unordered_set
<partial_symbol
*> &psyms_seen
;
26398 /* A helper function that writes a single signatured_type to an
26402 write_one_signatured_type (void **slot
, void *d
)
26404 struct signatured_type_index_data
*info
26405 = (struct signatured_type_index_data
*) d
;
26406 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26407 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
26409 write_psymbols (info
->symtab
,
26411 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
26412 psymtab
->n_global_syms
, info
->cu_index
,
26414 write_psymbols (info
->symtab
,
26416 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
26417 psymtab
->n_static_syms
, info
->cu_index
,
26420 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26421 to_underlying (entry
->per_cu
.sect_off
));
26422 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26423 to_underlying (entry
->type_offset_in_tu
));
26424 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
26431 /* Recurse into all "included" dependencies and count their symbols as
26432 if they appeared in this psymtab. */
26435 recursively_count_psymbols (struct partial_symtab
*psymtab
,
26436 size_t &psyms_seen
)
26438 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26439 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26440 recursively_count_psymbols (psymtab
->dependencies
[i
],
26443 psyms_seen
+= psymtab
->n_global_syms
;
26444 psyms_seen
+= psymtab
->n_static_syms
;
26447 /* Recurse into all "included" dependencies and write their symbols as
26448 if they appeared in this psymtab. */
26451 recursively_write_psymbols (struct objfile
*objfile
,
26452 struct partial_symtab
*psymtab
,
26453 struct mapped_symtab
*symtab
,
26454 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26455 offset_type cu_index
)
26459 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26460 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26461 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26462 symtab
, psyms_seen
, cu_index
);
26464 write_psymbols (symtab
,
26466 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26467 psymtab
->n_global_syms
, cu_index
,
26469 write_psymbols (symtab
,
26471 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26472 psymtab
->n_static_syms
, cu_index
,
26476 /* DWARF-5 .debug_names builder. */
26480 debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bool is_dwarf64
,
26481 bfd_endian dwarf5_byte_order
)
26482 : m_dwarf5_byte_order (dwarf5_byte_order
),
26483 m_dwarf32 (dwarf5_byte_order
),
26484 m_dwarf64 (dwarf5_byte_order
),
26485 m_dwarf (is_dwarf64
26486 ? static_cast<dwarf
&> (m_dwarf64
)
26487 : static_cast<dwarf
&> (m_dwarf32
)),
26488 m_name_table_string_offs (m_dwarf
.name_table_string_offs
),
26489 m_name_table_entry_offs (m_dwarf
.name_table_entry_offs
),
26490 m_debugstrlookup (dwarf2_per_objfile
)
26493 int dwarf5_offset_size () const
26495 const bool dwarf5_is_dwarf64
= &m_dwarf
== &m_dwarf64
;
26496 return dwarf5_is_dwarf64
? 8 : 4;
26499 /* Is this symbol from DW_TAG_compile_unit or DW_TAG_type_unit? */
26500 enum class unit_kind
{ cu
, tu
};
26502 /* Insert one symbol. */
26503 void insert (const partial_symbol
*psym
, int cu_index
, bool is_static
,
26506 const int dwarf_tag
= psymbol_tag (psym
);
26507 if (dwarf_tag
== 0)
26509 const char *const name
= SYMBOL_SEARCH_NAME (psym
);
26510 const auto insertpair
26511 = m_name_to_value_set
.emplace (c_str_view (name
),
26512 std::set
<symbol_value
> ());
26513 std::set
<symbol_value
> &value_set
= insertpair
.first
->second
;
26514 value_set
.emplace (symbol_value (dwarf_tag
, cu_index
, is_static
, kind
));
26517 /* Build all the tables. All symbols must be already inserted.
26518 This function does not call file_write, caller has to do it
26522 /* Verify the build method has not be called twice. */
26523 gdb_assert (m_abbrev_table
.empty ());
26524 const size_t name_count
= m_name_to_value_set
.size ();
26525 m_bucket_table
.resize
26526 (std::pow (2, std::ceil (std::log2 (name_count
* 4 / 3))));
26527 m_hash_table
.reserve (name_count
);
26528 m_name_table_string_offs
.reserve (name_count
);
26529 m_name_table_entry_offs
.reserve (name_count
);
26531 /* Map each hash of symbol to its name and value. */
26532 struct hash_it_pair
26535 decltype (m_name_to_value_set
)::const_iterator it
;
26537 std::vector
<std::forward_list
<hash_it_pair
>> bucket_hash
;
26538 bucket_hash
.resize (m_bucket_table
.size ());
26539 for (decltype (m_name_to_value_set
)::const_iterator it
26540 = m_name_to_value_set
.cbegin ();
26541 it
!= m_name_to_value_set
.cend ();
26544 const char *const name
= it
->first
.c_str ();
26545 const uint32_t hash
= dwarf5_djb_hash (name
);
26546 hash_it_pair hashitpair
;
26547 hashitpair
.hash
= hash
;
26548 hashitpair
.it
= it
;
26549 auto &slot
= bucket_hash
[hash
% bucket_hash
.size()];
26550 slot
.push_front (std::move (hashitpair
));
26552 for (size_t bucket_ix
= 0; bucket_ix
< bucket_hash
.size (); ++bucket_ix
)
26554 const std::forward_list
<hash_it_pair
> &hashitlist
26555 = bucket_hash
[bucket_ix
];
26556 if (hashitlist
.empty ())
26558 uint32_t &bucket_slot
= m_bucket_table
[bucket_ix
];
26559 /* The hashes array is indexed starting at 1. */
26560 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&bucket_slot
),
26561 sizeof (bucket_slot
), m_dwarf5_byte_order
,
26562 m_hash_table
.size () + 1);
26563 for (const hash_it_pair
&hashitpair
: hashitlist
)
26565 m_hash_table
.push_back (0);
26566 store_unsigned_integer (reinterpret_cast<gdb_byte
*>
26567 (&m_hash_table
.back ()),
26568 sizeof (m_hash_table
.back ()),
26569 m_dwarf5_byte_order
, hashitpair
.hash
);
26570 const c_str_view
&name
= hashitpair
.it
->first
;
26571 const std::set
<symbol_value
> &value_set
= hashitpair
.it
->second
;
26572 m_name_table_string_offs
.push_back_reorder
26573 (m_debugstrlookup
.lookup (name
.c_str ()));
26574 m_name_table_entry_offs
.push_back_reorder (m_entry_pool
.size ());
26575 gdb_assert (!value_set
.empty ());
26576 for (const symbol_value
&value
: value_set
)
26578 int &idx
= m_indexkey_to_idx
[index_key (value
.dwarf_tag
,
26583 idx
= m_idx_next
++;
26584 m_abbrev_table
.append_unsigned_leb128 (idx
);
26585 m_abbrev_table
.append_unsigned_leb128 (value
.dwarf_tag
);
26586 m_abbrev_table
.append_unsigned_leb128
26587 (value
.kind
== unit_kind::cu
? DW_IDX_compile_unit
26588 : DW_IDX_type_unit
);
26589 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_udata
);
26590 m_abbrev_table
.append_unsigned_leb128 (value
.is_static
26591 ? DW_IDX_GNU_internal
26592 : DW_IDX_GNU_external
);
26593 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_flag_present
);
26595 /* Terminate attributes list. */
26596 m_abbrev_table
.append_unsigned_leb128 (0);
26597 m_abbrev_table
.append_unsigned_leb128 (0);
26600 m_entry_pool
.append_unsigned_leb128 (idx
);
26601 m_entry_pool
.append_unsigned_leb128 (value
.cu_index
);
26604 /* Terminate the list of CUs. */
26605 m_entry_pool
.append_unsigned_leb128 (0);
26608 gdb_assert (m_hash_table
.size () == name_count
);
26610 /* Terminate tags list. */
26611 m_abbrev_table
.append_unsigned_leb128 (0);
26614 /* Return .debug_names bucket count. This must be called only after
26615 calling the build method. */
26616 uint32_t bucket_count () const
26618 /* Verify the build method has been already called. */
26619 gdb_assert (!m_abbrev_table
.empty ());
26620 const uint32_t retval
= m_bucket_table
.size ();
26622 /* Check for overflow. */
26623 gdb_assert (retval
== m_bucket_table
.size ());
26627 /* Return .debug_names names count. This must be called only after
26628 calling the build method. */
26629 uint32_t name_count () const
26631 /* Verify the build method has been already called. */
26632 gdb_assert (!m_abbrev_table
.empty ());
26633 const uint32_t retval
= m_hash_table
.size ();
26635 /* Check for overflow. */
26636 gdb_assert (retval
== m_hash_table
.size ());
26640 /* Return number of bytes of .debug_names abbreviation table. This
26641 must be called only after calling the build method. */
26642 uint32_t abbrev_table_bytes () const
26644 gdb_assert (!m_abbrev_table
.empty ());
26645 return m_abbrev_table
.size ();
26648 /* Recurse into all "included" dependencies and store their symbols
26649 as if they appeared in this psymtab. */
26650 void recursively_write_psymbols
26651 (struct objfile
*objfile
,
26652 struct partial_symtab
*psymtab
,
26653 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26656 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26657 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26658 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26659 psyms_seen
, cu_index
);
26661 write_psymbols (psyms_seen
,
26662 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26663 psymtab
->n_global_syms
, cu_index
, false, unit_kind::cu
);
26664 write_psymbols (psyms_seen
,
26665 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26666 psymtab
->n_static_syms
, cu_index
, true, unit_kind::cu
);
26669 /* Return number of bytes the .debug_names section will have. This
26670 must be called only after calling the build method. */
26671 size_t bytes () const
26673 /* Verify the build method has been already called. */
26674 gdb_assert (!m_abbrev_table
.empty ());
26675 size_t expected_bytes
= 0;
26676 expected_bytes
+= m_bucket_table
.size () * sizeof (m_bucket_table
[0]);
26677 expected_bytes
+= m_hash_table
.size () * sizeof (m_hash_table
[0]);
26678 expected_bytes
+= m_name_table_string_offs
.bytes ();
26679 expected_bytes
+= m_name_table_entry_offs
.bytes ();
26680 expected_bytes
+= m_abbrev_table
.size ();
26681 expected_bytes
+= m_entry_pool
.size ();
26682 return expected_bytes
;
26685 /* Write .debug_names to FILE_NAMES and .debug_str addition to
26686 FILE_STR. This must be called only after calling the build
26688 void file_write (FILE *file_names
, FILE *file_str
) const
26690 /* Verify the build method has been already called. */
26691 gdb_assert (!m_abbrev_table
.empty ());
26692 ::file_write (file_names
, m_bucket_table
);
26693 ::file_write (file_names
, m_hash_table
);
26694 m_name_table_string_offs
.file_write (file_names
);
26695 m_name_table_entry_offs
.file_write (file_names
);
26696 m_abbrev_table
.file_write (file_names
);
26697 m_entry_pool
.file_write (file_names
);
26698 m_debugstrlookup
.file_write (file_str
);
26701 /* A helper user data for write_one_signatured_type. */
26702 class write_one_signatured_type_data
26705 write_one_signatured_type_data (debug_names
&nametable_
,
26706 signatured_type_index_data
&&info_
)
26707 : nametable (nametable_
), info (std::move (info_
))
26709 debug_names
&nametable
;
26710 struct signatured_type_index_data info
;
26713 /* A helper function to pass write_one_signatured_type to
26714 htab_traverse_noresize. */
26716 write_one_signatured_type (void **slot
, void *d
)
26718 write_one_signatured_type_data
*data
= (write_one_signatured_type_data
*) d
;
26719 struct signatured_type_index_data
*info
= &data
->info
;
26720 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26722 data
->nametable
.write_one_signatured_type (entry
, info
);
26729 /* Storage for symbol names mapping them to their .debug_str section
26731 class debug_str_lookup
26735 /* Object costructor to be called for current DWARF2_PER_OBJFILE.
26736 All .debug_str section strings are automatically stored. */
26737 debug_str_lookup (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26738 : m_abfd (dwarf2_per_objfile
->objfile
->obfd
),
26739 m_dwarf2_per_objfile (dwarf2_per_objfile
)
26741 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
26742 &dwarf2_per_objfile
->str
);
26743 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
26745 for (const gdb_byte
*data
= dwarf2_per_objfile
->str
.buffer
;
26746 data
< (dwarf2_per_objfile
->str
.buffer
26747 + dwarf2_per_objfile
->str
.size
);)
26749 const char *const s
= reinterpret_cast<const char *> (data
);
26750 const auto insertpair
26751 = m_str_table
.emplace (c_str_view (s
),
26752 data
- dwarf2_per_objfile
->str
.buffer
);
26753 if (!insertpair
.second
)
26754 complaint (&symfile_complaints
,
26755 _("Duplicate string \"%s\" in "
26756 ".debug_str section [in module %s]"),
26757 s
, bfd_get_filename (m_abfd
));
26758 data
+= strlen (s
) + 1;
26762 /* Return offset of symbol name S in the .debug_str section. Add
26763 such symbol to the section's end if it does not exist there
26765 size_t lookup (const char *s
)
26767 const auto it
= m_str_table
.find (c_str_view (s
));
26768 if (it
!= m_str_table
.end ())
26770 const size_t offset
= (m_dwarf2_per_objfile
->str
.size
26771 + m_str_add_buf
.size ());
26772 m_str_table
.emplace (c_str_view (s
), offset
);
26773 m_str_add_buf
.append_cstr0 (s
);
26777 /* Append the end of the .debug_str section to FILE. */
26778 void file_write (FILE *file
) const
26780 m_str_add_buf
.file_write (file
);
26784 std::unordered_map
<c_str_view
, size_t, c_str_view_hasher
> m_str_table
;
26786 struct dwarf2_per_objfile
*m_dwarf2_per_objfile
;
26788 /* Data to add at the end of .debug_str for new needed symbol names. */
26789 data_buf m_str_add_buf
;
26792 /* Container to map used DWARF tags to their .debug_names abbreviation
26797 index_key (int dwarf_tag_
, bool is_static_
, unit_kind kind_
)
26798 : dwarf_tag (dwarf_tag_
), is_static (is_static_
), kind (kind_
)
26803 operator== (const index_key
&other
) const
26805 return (dwarf_tag
== other
.dwarf_tag
&& is_static
== other
.is_static
26806 && kind
== other
.kind
);
26809 const int dwarf_tag
;
26810 const bool is_static
;
26811 const unit_kind kind
;
26814 /* Provide std::unordered_map::hasher for index_key. */
26815 class index_key_hasher
26819 operator () (const index_key
&key
) const
26821 return (std::hash
<int>() (key
.dwarf_tag
) << 1) | key
.is_static
;
26825 /* Parameters of one symbol entry. */
26829 const int dwarf_tag
, cu_index
;
26830 const bool is_static
;
26831 const unit_kind kind
;
26833 symbol_value (int dwarf_tag_
, int cu_index_
, bool is_static_
,
26835 : dwarf_tag (dwarf_tag_
), cu_index (cu_index_
), is_static (is_static_
),
26840 operator< (const symbol_value
&other
) const
26860 /* Abstract base class to unify DWARF-32 and DWARF-64 name table
26865 const bfd_endian dwarf5_byte_order
;
26867 explicit offset_vec (bfd_endian dwarf5_byte_order_
)
26868 : dwarf5_byte_order (dwarf5_byte_order_
)
26871 /* Call std::vector::reserve for NELEM elements. */
26872 virtual void reserve (size_t nelem
) = 0;
26874 /* Call std::vector::push_back with store_unsigned_integer byte
26875 reordering for ELEM. */
26876 virtual void push_back_reorder (size_t elem
) = 0;
26878 /* Return expected output size in bytes. */
26879 virtual size_t bytes () const = 0;
26881 /* Write name table to FILE. */
26882 virtual void file_write (FILE *file
) const = 0;
26885 /* Template to unify DWARF-32 and DWARF-64 output. */
26886 template<typename OffsetSize
>
26887 class offset_vec_tmpl
: public offset_vec
26890 explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_
)
26891 : offset_vec (dwarf5_byte_order_
)
26894 /* Implement offset_vec::reserve. */
26895 void reserve (size_t nelem
) override
26897 m_vec
.reserve (nelem
);
26900 /* Implement offset_vec::push_back_reorder. */
26901 void push_back_reorder (size_t elem
) override
26903 m_vec
.push_back (elem
);
26904 /* Check for overflow. */
26905 gdb_assert (m_vec
.back () == elem
);
26906 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&m_vec
.back ()),
26907 sizeof (m_vec
.back ()), dwarf5_byte_order
, elem
);
26910 /* Implement offset_vec::bytes. */
26911 size_t bytes () const override
26913 return m_vec
.size () * sizeof (m_vec
[0]);
26916 /* Implement offset_vec::file_write. */
26917 void file_write (FILE *file
) const override
26919 ::file_write (file
, m_vec
);
26923 std::vector
<OffsetSize
> m_vec
;
26926 /* Base class to unify DWARF-32 and DWARF-64 .debug_names output
26927 respecting name table width. */
26931 offset_vec
&name_table_string_offs
, &name_table_entry_offs
;
26933 dwarf (offset_vec
&name_table_string_offs_
,
26934 offset_vec
&name_table_entry_offs_
)
26935 : name_table_string_offs (name_table_string_offs_
),
26936 name_table_entry_offs (name_table_entry_offs_
)
26941 /* Template to unify DWARF-32 and DWARF-64 .debug_names output
26942 respecting name table width. */
26943 template<typename OffsetSize
>
26944 class dwarf_tmpl
: public dwarf
26947 explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_
)
26948 : dwarf (m_name_table_string_offs
, m_name_table_entry_offs
),
26949 m_name_table_string_offs (dwarf5_byte_order_
),
26950 m_name_table_entry_offs (dwarf5_byte_order_
)
26954 offset_vec_tmpl
<OffsetSize
> m_name_table_string_offs
;
26955 offset_vec_tmpl
<OffsetSize
> m_name_table_entry_offs
;
26958 /* Try to reconstruct original DWARF tag for given partial_symbol.
26959 This function is not DWARF-5 compliant but it is sufficient for
26960 GDB as a DWARF-5 index consumer. */
26961 static int psymbol_tag (const struct partial_symbol
*psym
)
26963 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26964 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26972 return DW_TAG_subprogram
;
26974 return DW_TAG_typedef
;
26976 case LOC_CONST_BYTES
:
26977 case LOC_OPTIMIZED_OUT
:
26979 return DW_TAG_variable
;
26981 /* Note: It's currently impossible to recognize psyms as enum values
26982 short of reading the type info. For now punt. */
26983 return DW_TAG_variable
;
26985 /* There are other LOC_FOO values that one might want to classify
26986 as variables, but dwarf2read.c doesn't currently use them. */
26987 return DW_TAG_variable
;
26989 case STRUCT_DOMAIN
:
26990 return DW_TAG_structure_type
;
26996 /* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
26997 void write_psymbols (std::unordered_set
<partial_symbol
*> &psyms_seen
,
26998 struct partial_symbol
**psymp
, int count
, int cu_index
,
26999 bool is_static
, unit_kind kind
)
27001 for (; count
-- > 0; ++psymp
)
27003 struct partial_symbol
*psym
= *psymp
;
27005 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
27006 error (_("Ada is not currently supported by the index"));
27008 /* Only add a given psymbol once. */
27009 if (psyms_seen
.insert (psym
).second
)
27010 insert (psym
, cu_index
, is_static
, kind
);
27014 /* A helper function that writes a single signatured_type
27015 to a debug_names. */
27017 write_one_signatured_type (struct signatured_type
*entry
,
27018 struct signatured_type_index_data
*info
)
27020 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
27022 write_psymbols (info
->psyms_seen
,
27023 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
27024 psymtab
->n_global_syms
, info
->cu_index
, false,
27026 write_psymbols (info
->psyms_seen
,
27027 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
27028 psymtab
->n_static_syms
, info
->cu_index
, true,
27031 info
->types_list
.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order
,
27032 to_underlying (entry
->per_cu
.sect_off
));
27037 /* Store value of each symbol. */
27038 std::unordered_map
<c_str_view
, std::set
<symbol_value
>, c_str_view_hasher
>
27039 m_name_to_value_set
;
27041 /* Tables of DWARF-5 .debug_names. They are in object file byte
27043 std::vector
<uint32_t> m_bucket_table
;
27044 std::vector
<uint32_t> m_hash_table
;
27046 const bfd_endian m_dwarf5_byte_order
;
27047 dwarf_tmpl
<uint32_t> m_dwarf32
;
27048 dwarf_tmpl
<uint64_t> m_dwarf64
;
27050 offset_vec
&m_name_table_string_offs
, &m_name_table_entry_offs
;
27051 debug_str_lookup m_debugstrlookup
;
27053 /* Map each used .debug_names abbreviation tag parameter to its
27055 std::unordered_map
<index_key
, int, index_key_hasher
> m_indexkey_to_idx
;
27057 /* Next unused .debug_names abbreviation tag for
27058 m_indexkey_to_idx. */
27059 int m_idx_next
= 1;
27061 /* .debug_names abbreviation table. */
27062 data_buf m_abbrev_table
;
27064 /* .debug_names entry pool. */
27065 data_buf m_entry_pool
;
27068 /* Return iff any of the needed offsets does not fit into 32-bit
27069 .debug_names section. */
27072 check_dwarf64_offsets (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
27074 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27076 const dwarf2_per_cu_data
&per_cu
= *dwarf2_per_objfile
->all_comp_units
[i
];
27078 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
27081 for (int i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
27083 const signatured_type
&sigtype
= *dwarf2_per_objfile
->all_type_units
[i
];
27084 const dwarf2_per_cu_data
&per_cu
= sigtype
.per_cu
;
27086 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
27092 /* The psyms_seen set is potentially going to be largish (~40k
27093 elements when indexing a -g3 build of GDB itself). Estimate the
27094 number of elements in order to avoid too many rehashes, which
27095 require rebuilding buckets and thus many trips to
27099 psyms_seen_size (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
27101 size_t psyms_count
= 0;
27102 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27104 struct dwarf2_per_cu_data
*per_cu
27105 = dwarf2_per_objfile
->all_comp_units
[i
];
27106 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27108 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
27109 recursively_count_psymbols (psymtab
, psyms_count
);
27111 /* Generating an index for gdb itself shows a ratio of
27112 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
27113 return psyms_count
/ 4;
27116 /* Write new .gdb_index section for OBJFILE into OUT_FILE.
27117 Return how many bytes were expected to be written into OUT_FILE. */
27120 write_gdbindex (struct dwarf2_per_objfile
*dwarf2_per_objfile
, FILE *out_file
)
27122 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27123 mapped_symtab symtab
;
27126 /* While we're scanning CU's create a table that maps a psymtab pointer
27127 (which is what addrmap records) to its index (which is what is recorded
27128 in the index file). This will later be needed to write the address
27130 psym_index_map cu_index_htab
;
27131 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
27133 /* The CU list is already sorted, so we don't need to do additional
27134 work here. Also, the debug_types entries do not appear in
27135 all_comp_units, but only in their own hash table. */
27137 std::unordered_set
<partial_symbol
*> psyms_seen
27138 (psyms_seen_size (dwarf2_per_objfile
));
27139 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27141 struct dwarf2_per_cu_data
*per_cu
27142 = dwarf2_per_objfile
->all_comp_units
[i
];
27143 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27145 /* CU of a shared file from 'dwz -m' may be unused by this main file.
27146 It may be referenced from a local scope but in such case it does not
27147 need to be present in .gdb_index. */
27148 if (psymtab
== NULL
)
27151 if (psymtab
->user
== NULL
)
27152 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
27155 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
27156 gdb_assert (insertpair
.second
);
27158 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
27159 to_underlying (per_cu
->sect_off
));
27160 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
27163 /* Dump the address map. */
27165 write_address_map (objfile
, addr_vec
, cu_index_htab
);
27167 /* Write out the .debug_type entries, if any. */
27168 data_buf types_cu_list
;
27169 if (dwarf2_per_objfile
->signatured_types
)
27171 signatured_type_index_data
sig_data (types_cu_list
,
27174 sig_data
.objfile
= objfile
;
27175 sig_data
.symtab
= &symtab
;
27176 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
27177 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
27178 write_one_signatured_type
, &sig_data
);
27181 /* Now that we've processed all symbols we can shrink their cu_indices
27183 uniquify_cu_indices (&symtab
);
27185 data_buf symtab_vec
, constant_pool
;
27186 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
27189 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
27190 offset_type total_len
= size_of_contents
;
27192 /* The version number. */
27193 contents
.append_data (MAYBE_SWAP (8));
27195 /* The offset of the CU list from the start of the file. */
27196 contents
.append_data (MAYBE_SWAP (total_len
));
27197 total_len
+= cu_list
.size ();
27199 /* The offset of the types CU list from the start of the file. */
27200 contents
.append_data (MAYBE_SWAP (total_len
));
27201 total_len
+= types_cu_list
.size ();
27203 /* The offset of the address table from the start of the file. */
27204 contents
.append_data (MAYBE_SWAP (total_len
));
27205 total_len
+= addr_vec
.size ();
27207 /* The offset of the symbol table from the start of the file. */
27208 contents
.append_data (MAYBE_SWAP (total_len
));
27209 total_len
+= symtab_vec
.size ();
27211 /* The offset of the constant pool from the start of the file. */
27212 contents
.append_data (MAYBE_SWAP (total_len
));
27213 total_len
+= constant_pool
.size ();
27215 gdb_assert (contents
.size () == size_of_contents
);
27217 contents
.file_write (out_file
);
27218 cu_list
.file_write (out_file
);
27219 types_cu_list
.file_write (out_file
);
27220 addr_vec
.file_write (out_file
);
27221 symtab_vec
.file_write (out_file
);
27222 constant_pool
.file_write (out_file
);
27227 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
27228 static const gdb_byte dwarf5_gdb_augmentation
[] = { 'G', 'D', 'B', 0 };
27230 /* Write a new .debug_names section for OBJFILE into OUT_FILE, write
27231 needed addition to .debug_str section to OUT_FILE_STR. Return how
27232 many bytes were expected to be written into OUT_FILE. */
27235 write_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
27236 FILE *out_file
, FILE *out_file_str
)
27238 const bool dwarf5_is_dwarf64
= check_dwarf64_offsets (dwarf2_per_objfile
);
27239 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27240 const enum bfd_endian dwarf5_byte_order
27241 = gdbarch_byte_order (get_objfile_arch (objfile
));
27243 /* The CU list is already sorted, so we don't need to do additional
27244 work here. Also, the debug_types entries do not appear in
27245 all_comp_units, but only in their own hash table. */
27247 debug_names
nametable (dwarf2_per_objfile
, dwarf5_is_dwarf64
,
27248 dwarf5_byte_order
);
27249 std::unordered_set
<partial_symbol
*>
27250 psyms_seen (psyms_seen_size (dwarf2_per_objfile
));
27251 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27253 const dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
27254 partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27256 /* CU of a shared file from 'dwz -m' may be unused by this main
27257 file. It may be referenced from a local scope but in such
27258 case it does not need to be present in .debug_names. */
27259 if (psymtab
== NULL
)
27262 if (psymtab
->user
== NULL
)
27263 nametable
.recursively_write_psymbols (objfile
, psymtab
, psyms_seen
, i
);
27265 cu_list
.append_uint (nametable
.dwarf5_offset_size (), dwarf5_byte_order
,
27266 to_underlying (per_cu
->sect_off
));
27269 /* Write out the .debug_type entries, if any. */
27270 data_buf types_cu_list
;
27271 if (dwarf2_per_objfile
->signatured_types
)
27273 debug_names::write_one_signatured_type_data
sig_data (nametable
,
27274 signatured_type_index_data (types_cu_list
, psyms_seen
));
27276 sig_data
.info
.objfile
= objfile
;
27277 /* It is used only for gdb_index. */
27278 sig_data
.info
.symtab
= nullptr;
27279 sig_data
.info
.cu_index
= 0;
27280 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
27281 debug_names::write_one_signatured_type
,
27285 nametable
.build ();
27287 /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
27289 const offset_type bytes_of_header
27290 = ((dwarf5_is_dwarf64
? 12 : 4)
27292 + sizeof (dwarf5_gdb_augmentation
));
27293 size_t expected_bytes
= 0;
27294 expected_bytes
+= bytes_of_header
;
27295 expected_bytes
+= cu_list
.size ();
27296 expected_bytes
+= types_cu_list
.size ();
27297 expected_bytes
+= nametable
.bytes ();
27300 if (!dwarf5_is_dwarf64
)
27302 const uint64_t size64
= expected_bytes
- 4;
27303 gdb_assert (size64
< 0xfffffff0);
27304 header
.append_uint (4, dwarf5_byte_order
, size64
);
27308 header
.append_uint (4, dwarf5_byte_order
, 0xffffffff);
27309 header
.append_uint (8, dwarf5_byte_order
, expected_bytes
- 12);
27312 /* The version number. */
27313 header
.append_uint (2, dwarf5_byte_order
, 5);
27316 header
.append_uint (2, dwarf5_byte_order
, 0);
27318 /* comp_unit_count - The number of CUs in the CU list. */
27319 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_comp_units
);
27321 /* local_type_unit_count - The number of TUs in the local TU
27323 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_type_units
);
27325 /* foreign_type_unit_count - The number of TUs in the foreign TU
27327 header
.append_uint (4, dwarf5_byte_order
, 0);
27329 /* bucket_count - The number of hash buckets in the hash lookup
27331 header
.append_uint (4, dwarf5_byte_order
, nametable
.bucket_count ());
27333 /* name_count - The number of unique names in the index. */
27334 header
.append_uint (4, dwarf5_byte_order
, nametable
.name_count ());
27336 /* abbrev_table_size - The size in bytes of the abbreviations
27338 header
.append_uint (4, dwarf5_byte_order
, nametable
.abbrev_table_bytes ());
27340 /* augmentation_string_size - The size in bytes of the augmentation
27341 string. This value is rounded up to a multiple of 4. */
27342 static_assert (sizeof (dwarf5_gdb_augmentation
) % 4 == 0, "");
27343 header
.append_uint (4, dwarf5_byte_order
, sizeof (dwarf5_gdb_augmentation
));
27344 header
.append_data (dwarf5_gdb_augmentation
);
27346 gdb_assert (header
.size () == bytes_of_header
);
27348 header
.file_write (out_file
);
27349 cu_list
.file_write (out_file
);
27350 types_cu_list
.file_write (out_file
);
27351 nametable
.file_write (out_file
, out_file_str
);
27353 return expected_bytes
;
27356 /* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
27357 position is at the end of the file. */
27360 assert_file_size (FILE *file
, const char *filename
, size_t expected_size
)
27362 const auto file_size
= ftell (file
);
27363 if (file_size
== -1)
27364 error (_("Can't get `%s' size"), filename
);
27365 gdb_assert (file_size
== expected_size
);
27368 /* Create an index file for OBJFILE in the directory DIR. */
27371 write_psymtabs_to_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
27373 dw_index_kind index_kind
)
27375 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27377 if (dwarf2_per_objfile
->using_index
)
27378 error (_("Cannot use an index to create the index"));
27380 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
27381 error (_("Cannot make an index when the file has multiple .debug_types sections"));
27383 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
27387 if (stat (objfile_name (objfile
), &st
) < 0)
27388 perror_with_name (objfile_name (objfile
));
27390 std::string
filename (std::string (dir
) + SLASH_STRING
27391 + lbasename (objfile_name (objfile
))
27392 + (index_kind
== dw_index_kind::DEBUG_NAMES
27393 ? INDEX5_SUFFIX
: INDEX4_SUFFIX
));
27395 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
27397 error (_("Can't open `%s' for writing"), filename
.c_str ());
27399 /* Order matters here; we want FILE to be closed before FILENAME is
27400 unlinked, because on MS-Windows one cannot delete a file that is
27401 still open. (Don't call anything here that might throw until
27402 file_closer is created.) */
27403 gdb::unlinker
unlink_file (filename
.c_str ());
27404 gdb_file_up
close_out_file (out_file
);
27406 if (index_kind
== dw_index_kind::DEBUG_NAMES
)
27408 std::string
filename_str (std::string (dir
) + SLASH_STRING
27409 + lbasename (objfile_name (objfile
))
27410 + DEBUG_STR_SUFFIX
);
27412 = gdb_fopen_cloexec (filename_str
.c_str (), "wb").release ();
27414 error (_("Can't open `%s' for writing"), filename_str
.c_str ());
27415 gdb::unlinker
unlink_file_str (filename_str
.c_str ());
27416 gdb_file_up
close_out_file_str (out_file_str
);
27418 const size_t total_len
27419 = write_debug_names (dwarf2_per_objfile
, out_file
, out_file_str
);
27420 assert_file_size (out_file
, filename
.c_str (), total_len
);
27422 /* We want to keep the file .debug_str file too. */
27423 unlink_file_str
.keep ();
27427 const size_t total_len
27428 = write_gdbindex (dwarf2_per_objfile
, out_file
);
27429 assert_file_size (out_file
, filename
.c_str (), total_len
);
27432 /* We want to keep the file. */
27433 unlink_file
.keep ();
27436 /* Implementation of the `save gdb-index' command.
27438 Note that the .gdb_index file format used by this command is
27439 documented in the GDB manual. Any changes here must be documented
27443 save_gdb_index_command (const char *arg
, int from_tty
)
27445 struct objfile
*objfile
;
27446 const char dwarf5space
[] = "-dwarf-5 ";
27447 dw_index_kind index_kind
= dw_index_kind::GDB_INDEX
;
27452 arg
= skip_spaces (arg
);
27453 if (strncmp (arg
, dwarf5space
, strlen (dwarf5space
)) == 0)
27455 index_kind
= dw_index_kind::DEBUG_NAMES
;
27456 arg
+= strlen (dwarf5space
);
27457 arg
= skip_spaces (arg
);
27461 error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
27463 ALL_OBJFILES (objfile
)
27467 /* If the objfile does not correspond to an actual file, skip it. */
27468 if (stat (objfile_name (objfile
), &st
) < 0)
27471 struct dwarf2_per_objfile
*dwarf2_per_objfile
27472 = get_dwarf2_per_objfile (objfile
);
27474 if (dwarf2_per_objfile
!= NULL
)
27478 write_psymtabs_to_index (dwarf2_per_objfile
, arg
, index_kind
);
27480 CATCH (except
, RETURN_MASK_ERROR
)
27482 exception_fprintf (gdb_stderr
, except
,
27483 _("Error while writing index for `%s': "),
27484 objfile_name (objfile
));
27494 int dwarf_always_disassemble
;
27497 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
27498 struct cmd_list_element
*c
, const char *value
)
27500 fprintf_filtered (file
,
27501 _("Whether to always disassemble "
27502 "DWARF expressions is %s.\n"),
27507 show_check_physname (struct ui_file
*file
, int from_tty
,
27508 struct cmd_list_element
*c
, const char *value
)
27510 fprintf_filtered (file
,
27511 _("Whether to check \"physname\" is %s.\n"),
27516 _initialize_dwarf2_read (void)
27518 struct cmd_list_element
*c
;
27520 dwarf2_objfile_data_key
= register_objfile_data ();
27522 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
27523 Set DWARF specific variables.\n\
27524 Configure DWARF variables such as the cache size"),
27525 &set_dwarf_cmdlist
, "maintenance set dwarf ",
27526 0/*allow-unknown*/, &maintenance_set_cmdlist
);
27528 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
27529 Show DWARF specific variables\n\
27530 Show DWARF variables such as the cache size"),
27531 &show_dwarf_cmdlist
, "maintenance show dwarf ",
27532 0/*allow-unknown*/, &maintenance_show_cmdlist
);
27534 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
27535 &dwarf_max_cache_age
, _("\
27536 Set the upper bound on the age of cached DWARF compilation units."), _("\
27537 Show the upper bound on the age of cached DWARF compilation units."), _("\
27538 A higher limit means that cached compilation units will be stored\n\
27539 in memory longer, and more total memory will be used. Zero disables\n\
27540 caching, which can slow down startup."),
27542 show_dwarf_max_cache_age
,
27543 &set_dwarf_cmdlist
,
27544 &show_dwarf_cmdlist
);
27546 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
27547 &dwarf_always_disassemble
, _("\
27548 Set whether `info address' always disassembles DWARF expressions."), _("\
27549 Show whether `info address' always disassembles DWARF expressions."), _("\
27550 When enabled, DWARF expressions are always printed in an assembly-like\n\
27551 syntax. When disabled, expressions will be printed in a more\n\
27552 conversational style, when possible."),
27554 show_dwarf_always_disassemble
,
27555 &set_dwarf_cmdlist
,
27556 &show_dwarf_cmdlist
);
27558 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
27559 Set debugging of the DWARF reader."), _("\
27560 Show debugging of the DWARF reader."), _("\
27561 When enabled (non-zero), debugging messages are printed during DWARF\n\
27562 reading and symtab expansion. A value of 1 (one) provides basic\n\
27563 information. A value greater than 1 provides more verbose information."),
27566 &setdebuglist
, &showdebuglist
);
27568 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
27569 Set debugging of the DWARF DIE reader."), _("\
27570 Show debugging of the DWARF DIE reader."), _("\
27571 When enabled (non-zero), DIEs are dumped after they are read in.\n\
27572 The value is the maximum depth to print."),
27575 &setdebuglist
, &showdebuglist
);
27577 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
27578 Set debugging of the dwarf line reader."), _("\
27579 Show debugging of the dwarf line reader."), _("\
27580 When enabled (non-zero), line number entries are dumped as they are read in.\n\
27581 A value of 1 (one) provides basic information.\n\
27582 A value greater than 1 provides more verbose information."),
27585 &setdebuglist
, &showdebuglist
);
27587 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
27588 Set cross-checking of \"physname\" code against demangler."), _("\
27589 Show cross-checking of \"physname\" code against demangler."), _("\
27590 When enabled, GDB's internal \"physname\" code is checked against\n\
27592 NULL
, show_check_physname
,
27593 &setdebuglist
, &showdebuglist
);
27595 add_setshow_boolean_cmd ("use-deprecated-index-sections",
27596 no_class
, &use_deprecated_index_sections
, _("\
27597 Set whether to use deprecated gdb_index sections."), _("\
27598 Show whether to use deprecated gdb_index sections."), _("\
27599 When enabled, deprecated .gdb_index sections are used anyway.\n\
27600 Normally they are ignored either because of a missing feature or\n\
27601 performance issue.\n\
27602 Warning: This option must be enabled before gdb reads the file."),
27605 &setlist
, &showlist
);
27607 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
27609 Save a gdb-index file.\n\
27610 Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
27612 No options create one file with .gdb-index extension for pre-DWARF-5\n\
27613 compatible .gdb_index section. With -dwarf-5 creates two files with\n\
27614 extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
27616 set_cmd_completer (c
, filename_completer
);
27618 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27619 &dwarf2_locexpr_funcs
);
27620 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27621 &dwarf2_loclist_funcs
);
27623 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27624 &dwarf2_block_frame_base_locexpr_funcs
);
27625 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27626 &dwarf2_block_frame_base_loclist_funcs
);
27629 selftests::register_test ("dw2_expand_symtabs_matching",
27630 selftests::dw2_expand_symtabs_matching::run_test
);