1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 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. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 /* This is used to store the data that is always per objfile. */
109 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
111 /* These are used to store the dwarf2_per_bfd objects.
113 objfiles having the same BFD, which doesn't require relocations, are going to
114 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
116 Other objfiles are not going to share a dwarf2_per_bfd with any other
117 objfiles, so they'll have their own version kept in the _objfile_data_key
119 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
120 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
122 /* The "aclass" indices for various kinds of computed DWARF symbols. */
124 static int dwarf2_locexpr_index
;
125 static int dwarf2_loclist_index
;
126 static int dwarf2_locexpr_block_index
;
127 static int dwarf2_loclist_block_index
;
129 /* Size of .debug_loclists section header for 32-bit DWARF format. */
130 #define LOCLIST_HEADER_SIZE32 12
132 /* Size of .debug_loclists section header for 64-bit DWARF format. */
133 #define LOCLIST_HEADER_SIZE64 20
135 /* An index into a (C++) symbol name component in a symbol name as
136 recorded in the mapped_index's symbol table. For each C++ symbol
137 in the symbol table, we record one entry for the start of each
138 component in the symbol in a table of name components, and then
139 sort the table, in order to be able to binary search symbol names,
140 ignoring leading namespaces, both completion and regular look up.
141 For example, for symbol "A::B::C", we'll have an entry that points
142 to "A::B::C", another that points to "B::C", and another for "C".
143 Note that function symbols in GDB index have no parameter
144 information, just the function/method names. You can convert a
145 name_component to a "const char *" using the
146 'mapped_index::symbol_name_at(offset_type)' method. */
148 struct name_component
150 /* Offset in the symbol name where the component starts. Stored as
151 a (32-bit) offset instead of a pointer to save memory and improve
152 locality on 64-bit architectures. */
153 offset_type name_offset
;
155 /* The symbol's index in the symbol and constant pool tables of a
160 /* Base class containing bits shared by both .gdb_index and
161 .debug_name indexes. */
163 struct mapped_index_base
165 mapped_index_base () = default;
166 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
168 /* The name_component table (a sorted vector). See name_component's
169 description above. */
170 std::vector
<name_component
> name_components
;
172 /* How NAME_COMPONENTS is sorted. */
173 enum case_sensitivity name_components_casing
;
175 /* Return the number of names in the symbol table. */
176 virtual size_t symbol_name_count () const = 0;
178 /* Get the name of the symbol at IDX in the symbol table. */
179 virtual const char *symbol_name_at
180 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
182 /* Return whether the name at IDX in the symbol table should be
184 virtual bool symbol_name_slot_invalid (offset_type idx
) const
189 /* Build the symbol name component sorted vector, if we haven't
191 void build_name_components (dwarf2_per_objfile
*per_objfile
);
193 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
194 possible matches for LN_NO_PARAMS in the name component
196 std::pair
<std::vector
<name_component
>::const_iterator
,
197 std::vector
<name_component
>::const_iterator
>
198 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
200 dwarf2_per_objfile
*per_objfile
) const;
202 /* Prevent deleting/destroying via a base class pointer. */
204 ~mapped_index_base() = default;
207 /* A description of the mapped index. The file format is described in
208 a comment by the code that writes the index. */
209 struct mapped_index final
: public mapped_index_base
211 /* A slot/bucket in the symbol table hash. */
212 struct symbol_table_slot
214 const offset_type name
;
215 const offset_type vec
;
218 /* Index data format version. */
221 /* The address table data. */
222 gdb::array_view
<const gdb_byte
> address_table
;
224 /* The symbol table, implemented as a hash table. */
225 gdb::array_view
<symbol_table_slot
> symbol_table
;
227 /* A pointer to the constant pool. */
228 const char *constant_pool
= nullptr;
230 bool symbol_name_slot_invalid (offset_type idx
) const override
232 const auto &bucket
= this->symbol_table
[idx
];
233 return bucket
.name
== 0 && bucket
.vec
== 0;
236 /* Convenience method to get at the name of the symbol at IDX in the
238 const char *symbol_name_at
239 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
240 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
242 size_t symbol_name_count () const override
243 { return this->symbol_table
.size (); }
246 /* A description of the mapped .debug_names.
247 Uninitialized map has CU_COUNT 0. */
248 struct mapped_debug_names final
: public mapped_index_base
250 bfd_endian dwarf5_byte_order
;
251 bool dwarf5_is_dwarf64
;
252 bool augmentation_is_gdb
;
254 uint32_t cu_count
= 0;
255 uint32_t tu_count
, bucket_count
, name_count
;
256 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
257 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
258 const gdb_byte
*name_table_string_offs_reordered
;
259 const gdb_byte
*name_table_entry_offs_reordered
;
260 const gdb_byte
*entry_pool
;
267 /* Attribute name DW_IDX_*. */
270 /* Attribute form DW_FORM_*. */
273 /* Value if FORM is DW_FORM_implicit_const. */
274 LONGEST implicit_const
;
276 std::vector
<attr
> attr_vec
;
279 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
281 const char *namei_to_name
282 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
284 /* Implementation of the mapped_index_base virtual interface, for
285 the name_components cache. */
287 const char *symbol_name_at
288 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
289 { return namei_to_name (idx
, per_objfile
); }
291 size_t symbol_name_count () const override
292 { return this->name_count
; }
295 /* See dwarf2read.h. */
298 get_dwarf2_per_objfile (struct objfile
*objfile
)
300 return dwarf2_objfile_data_key
.get (objfile
);
303 /* Default names of the debugging sections. */
305 /* Note that if the debugging section has been compressed, it might
306 have a name like .zdebug_info. */
308 static const struct dwarf2_debug_sections dwarf2_elf_names
=
310 { ".debug_info", ".zdebug_info" },
311 { ".debug_abbrev", ".zdebug_abbrev" },
312 { ".debug_line", ".zdebug_line" },
313 { ".debug_loc", ".zdebug_loc" },
314 { ".debug_loclists", ".zdebug_loclists" },
315 { ".debug_macinfo", ".zdebug_macinfo" },
316 { ".debug_macro", ".zdebug_macro" },
317 { ".debug_str", ".zdebug_str" },
318 { ".debug_str_offsets", ".zdebug_str_offsets" },
319 { ".debug_line_str", ".zdebug_line_str" },
320 { ".debug_ranges", ".zdebug_ranges" },
321 { ".debug_rnglists", ".zdebug_rnglists" },
322 { ".debug_types", ".zdebug_types" },
323 { ".debug_addr", ".zdebug_addr" },
324 { ".debug_frame", ".zdebug_frame" },
325 { ".eh_frame", NULL
},
326 { ".gdb_index", ".zgdb_index" },
327 { ".debug_names", ".zdebug_names" },
328 { ".debug_aranges", ".zdebug_aranges" },
332 /* List of DWO/DWP sections. */
334 static const struct dwop_section_names
336 struct dwarf2_section_names abbrev_dwo
;
337 struct dwarf2_section_names info_dwo
;
338 struct dwarf2_section_names line_dwo
;
339 struct dwarf2_section_names loc_dwo
;
340 struct dwarf2_section_names loclists_dwo
;
341 struct dwarf2_section_names macinfo_dwo
;
342 struct dwarf2_section_names macro_dwo
;
343 struct dwarf2_section_names str_dwo
;
344 struct dwarf2_section_names str_offsets_dwo
;
345 struct dwarf2_section_names types_dwo
;
346 struct dwarf2_section_names cu_index
;
347 struct dwarf2_section_names tu_index
;
351 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
352 { ".debug_info.dwo", ".zdebug_info.dwo" },
353 { ".debug_line.dwo", ".zdebug_line.dwo" },
354 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
355 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
356 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
357 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
358 { ".debug_str.dwo", ".zdebug_str.dwo" },
359 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
360 { ".debug_types.dwo", ".zdebug_types.dwo" },
361 { ".debug_cu_index", ".zdebug_cu_index" },
362 { ".debug_tu_index", ".zdebug_tu_index" },
365 /* local data types */
367 /* The location list section (.debug_loclists) begins with a header,
368 which contains the following information. */
369 struct loclist_header
371 /* A 4-byte or 12-byte length containing the length of the
372 set of entries for this compilation unit, not including the
373 length field itself. */
376 /* A 2-byte version identifier. */
379 /* A 1-byte unsigned integer containing the size in bytes of an address on
380 the target system. */
381 unsigned char addr_size
;
383 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
384 on the target system. */
385 unsigned char segment_collector_size
;
387 /* A 4-byte count of the number of offsets that follow the header. */
388 unsigned int offset_entry_count
;
391 /* Type used for delaying computation of method physnames.
392 See comments for compute_delayed_physnames. */
393 struct delayed_method_info
395 /* The type to which the method is attached, i.e., its parent class. */
398 /* The index of the method in the type's function fieldlists. */
401 /* The index of the method in the fieldlist. */
404 /* The name of the DIE. */
407 /* The DIE associated with this method. */
408 struct die_info
*die
;
411 /* Internal state when decoding a particular compilation unit. */
414 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
415 dwarf2_per_objfile
*per_objfile
);
417 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
419 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
420 Create the set of symtabs used by this TU, or if this TU is sharing
421 symtabs with another TU and the symtabs have already been created
422 then restore those symtabs in the line header.
423 We don't need the pc/line-number mapping for type units. */
424 void setup_type_unit_groups (struct die_info
*die
);
426 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
427 buildsym_compunit constructor. */
428 struct compunit_symtab
*start_symtab (const char *name
,
429 const char *comp_dir
,
432 /* Reset the builder. */
433 void reset_builder () { m_builder
.reset (); }
435 /* Return a type that is a generic pointer type, the size of which
436 matches the address size given in the compilation unit header for
438 struct type
*addr_type () const;
440 /* Find an integer type the same size as the address size given in
441 the compilation unit header for this CU. UNSIGNED_P controls if
442 the integer is unsigned or not. */
443 struct type
*addr_sized_int_type (bool unsigned_p
) const;
445 /* The header of the compilation unit. */
446 struct comp_unit_head header
{};
448 /* Base address of this compilation unit. */
449 gdb::optional
<CORE_ADDR
> base_address
;
451 /* The language we are debugging. */
452 enum language language
= language_unknown
;
453 const struct language_defn
*language_defn
= nullptr;
455 const char *producer
= nullptr;
458 /* The symtab builder for this CU. This is only non-NULL when full
459 symbols are being read. */
460 std::unique_ptr
<buildsym_compunit
> m_builder
;
463 /* The generic symbol table building routines have separate lists for
464 file scope symbols and all all other scopes (local scopes). So
465 we need to select the right one to pass to add_symbol_to_list().
466 We do it by keeping a pointer to the correct list in list_in_scope.
468 FIXME: The original dwarf code just treated the file scope as the
469 first local scope, and all other local scopes as nested local
470 scopes, and worked fine. Check to see if we really need to
471 distinguish these in buildsym.c. */
472 struct pending
**list_in_scope
= nullptr;
474 /* Hash table holding all the loaded partial DIEs
475 with partial_die->offset.SECT_OFF as hash. */
476 htab_t partial_dies
= nullptr;
478 /* Storage for things with the same lifetime as this read-in compilation
479 unit, including partial DIEs. */
480 auto_obstack comp_unit_obstack
;
482 /* Backlink to our per_cu entry. */
483 struct dwarf2_per_cu_data
*per_cu
;
485 /* The dwarf2_per_objfile that owns this. */
486 dwarf2_per_objfile
*per_objfile
;
488 /* How many compilation units ago was this CU last referenced? */
491 /* A hash table of DIE cu_offset for following references with
492 die_info->offset.sect_off as hash. */
493 htab_t die_hash
= nullptr;
495 /* Full DIEs if read in. */
496 struct die_info
*dies
= nullptr;
498 /* A set of pointers to dwarf2_per_cu_data objects for compilation
499 units referenced by this one. Only set during full symbol processing;
500 partial symbol tables do not have dependencies. */
501 htab_t dependencies
= nullptr;
503 /* Header data from the line table, during full symbol processing. */
504 struct line_header
*line_header
= nullptr;
505 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
506 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
507 this is the DW_TAG_compile_unit die for this CU. We'll hold on
508 to the line header as long as this DIE is being processed. See
509 process_die_scope. */
510 die_info
*line_header_die_owner
= nullptr;
512 /* A list of methods which need to have physnames computed
513 after all type information has been read. */
514 std::vector
<delayed_method_info
> method_list
;
516 /* To be copied to symtab->call_site_htab. */
517 htab_t call_site_htab
= nullptr;
519 /* Non-NULL if this CU came from a DWO file.
520 There is an invariant here that is important to remember:
521 Except for attributes copied from the top level DIE in the "main"
522 (or "stub") file in preparation for reading the DWO file
523 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
524 Either there isn't a DWO file (in which case this is NULL and the point
525 is moot), or there is and either we're not going to read it (in which
526 case this is NULL) or there is and we are reading it (in which case this
528 struct dwo_unit
*dwo_unit
= nullptr;
530 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
531 Note this value comes from the Fission stub CU/TU's DIE. */
532 gdb::optional
<ULONGEST
> addr_base
;
534 /* The DW_AT_rnglists_base attribute if present.
535 Note this value comes from the Fission stub CU/TU's DIE.
536 Also note that the value is zero in the non-DWO case so this value can
537 be used without needing to know whether DWO files are in use or not.
538 N.B. This does not apply to DW_AT_ranges appearing in
539 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
540 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
541 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
542 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
543 ULONGEST ranges_base
= 0;
545 /* The DW_AT_loclists_base attribute if present. */
546 ULONGEST loclist_base
= 0;
548 /* When reading debug info generated by older versions of rustc, we
549 have to rewrite some union types to be struct types with a
550 variant part. This rewriting must be done after the CU is fully
551 read in, because otherwise at the point of rewriting some struct
552 type might not have been fully processed. So, we keep a list of
553 all such types here and process them after expansion. */
554 std::vector
<struct type
*> rust_unions
;
556 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
557 files, the value is implicitly zero. For DWARF 5 version DWO files, the
558 value is often implicit and is the size of the header of
559 .debug_str_offsets section (8 or 4, depending on the address size). */
560 gdb::optional
<ULONGEST
> str_offsets_base
;
562 /* Mark used when releasing cached dies. */
565 /* This CU references .debug_loc. See the symtab->locations_valid field.
566 This test is imperfect as there may exist optimized debug code not using
567 any location list and still facing inlining issues if handled as
568 unoptimized code. For a future better test see GCC PR other/32998. */
569 bool has_loclist
: 1;
571 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
572 if all the producer_is_* fields are valid. This information is cached
573 because profiling CU expansion showed excessive time spent in
574 producer_is_gxx_lt_4_6. */
575 bool checked_producer
: 1;
576 bool producer_is_gxx_lt_4_6
: 1;
577 bool producer_is_gcc_lt_4_3
: 1;
578 bool producer_is_icc
: 1;
579 bool producer_is_icc_lt_14
: 1;
580 bool producer_is_codewarrior
: 1;
582 /* When true, the file that we're processing is known to have
583 debugging info for C++ namespaces. GCC 3.3.x did not produce
584 this information, but later versions do. */
586 bool processing_has_namespace_info
: 1;
588 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
590 /* If this CU was inherited by another CU (via specification,
591 abstract_origin, etc), this is the ancestor CU. */
594 /* Get the buildsym_compunit for this CU. */
595 buildsym_compunit
*get_builder ()
597 /* If this CU has a builder associated with it, use that. */
598 if (m_builder
!= nullptr)
599 return m_builder
.get ();
601 /* Otherwise, search ancestors for a valid builder. */
602 if (ancestor
!= nullptr)
603 return ancestor
->get_builder ();
609 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
610 This includes type_unit_group and quick_file_names. */
612 struct stmt_list_hash
614 /* The DWO unit this table is from or NULL if there is none. */
615 struct dwo_unit
*dwo_unit
;
617 /* Offset in .debug_line or .debug_line.dwo. */
618 sect_offset line_sect_off
;
621 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
622 an object of this type. This contains elements of type unit groups
623 that can be shared across objfiles. The non-shareable parts are in
624 type_unit_group_unshareable. */
626 struct type_unit_group
628 /* dwarf2read.c's main "handle" on a TU symtab.
629 To simplify things we create an artificial CU that "includes" all the
630 type units using this stmt_list so that the rest of the code still has
631 a "per_cu" handle on the symtab. */
632 struct dwarf2_per_cu_data per_cu
;
634 /* The TUs that share this DW_AT_stmt_list entry.
635 This is added to while parsing type units to build partial symtabs,
636 and is deleted afterwards and not used again. */
637 std::vector
<signatured_type
*> *tus
;
639 /* The data used to construct the hash key. */
640 struct stmt_list_hash hash
;
643 /* These sections are what may appear in a (real or virtual) DWO file. */
647 struct dwarf2_section_info abbrev
;
648 struct dwarf2_section_info line
;
649 struct dwarf2_section_info loc
;
650 struct dwarf2_section_info loclists
;
651 struct dwarf2_section_info macinfo
;
652 struct dwarf2_section_info macro
;
653 struct dwarf2_section_info str
;
654 struct dwarf2_section_info str_offsets
;
655 /* In the case of a virtual DWO file, these two are unused. */
656 struct dwarf2_section_info info
;
657 std::vector
<dwarf2_section_info
> types
;
660 /* CUs/TUs in DWP/DWO files. */
664 /* Backlink to the containing struct dwo_file. */
665 struct dwo_file
*dwo_file
;
667 /* The "id" that distinguishes this CU/TU.
668 .debug_info calls this "dwo_id", .debug_types calls this "signature".
669 Since signatures came first, we stick with it for consistency. */
672 /* The section this CU/TU lives in, in the DWO file. */
673 struct dwarf2_section_info
*section
;
675 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
676 sect_offset sect_off
;
679 /* For types, offset in the type's DIE of the type defined by this TU. */
680 cu_offset type_offset_in_tu
;
683 /* include/dwarf2.h defines the DWP section codes.
684 It defines a max value but it doesn't define a min value, which we
685 use for error checking, so provide one. */
687 enum dwp_v2_section_ids
692 /* Data for one DWO file.
694 This includes virtual DWO files (a virtual DWO file is a DWO file as it
695 appears in a DWP file). DWP files don't really have DWO files per se -
696 comdat folding of types "loses" the DWO file they came from, and from
697 a high level view DWP files appear to contain a mass of random types.
698 However, to maintain consistency with the non-DWP case we pretend DWP
699 files contain virtual DWO files, and we assign each TU with one virtual
700 DWO file (generally based on the line and abbrev section offsets -
701 a heuristic that seems to work in practice). */
705 dwo_file () = default;
706 DISABLE_COPY_AND_ASSIGN (dwo_file
);
708 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
709 For virtual DWO files the name is constructed from the section offsets
710 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
711 from related CU+TUs. */
712 const char *dwo_name
= nullptr;
714 /* The DW_AT_comp_dir attribute. */
715 const char *comp_dir
= nullptr;
717 /* The bfd, when the file is open. Otherwise this is NULL.
718 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
719 gdb_bfd_ref_ptr dbfd
;
721 /* The sections that make up this DWO file.
722 Remember that for virtual DWO files in DWP V2, these are virtual
723 sections (for lack of a better name). */
724 struct dwo_sections sections
{};
726 /* The CUs in the file.
727 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
728 an extension to handle LLVM's Link Time Optimization output (where
729 multiple source files may be compiled into a single object/dwo pair). */
732 /* Table of TUs in the file.
733 Each element is a struct dwo_unit. */
737 /* These sections are what may appear in a DWP file. */
741 /* These are used by both DWP version 1 and 2. */
742 struct dwarf2_section_info str
;
743 struct dwarf2_section_info cu_index
;
744 struct dwarf2_section_info tu_index
;
746 /* These are only used by DWP version 2 files.
747 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
748 sections are referenced by section number, and are not recorded here.
749 In DWP version 2 there is at most one copy of all these sections, each
750 section being (effectively) comprised of the concatenation of all of the
751 individual sections that exist in the version 1 format.
752 To keep the code simple we treat each of these concatenated pieces as a
753 section itself (a virtual section?). */
754 struct dwarf2_section_info abbrev
;
755 struct dwarf2_section_info info
;
756 struct dwarf2_section_info line
;
757 struct dwarf2_section_info loc
;
758 struct dwarf2_section_info macinfo
;
759 struct dwarf2_section_info macro
;
760 struct dwarf2_section_info str_offsets
;
761 struct dwarf2_section_info types
;
764 /* These sections are what may appear in a virtual DWO file in DWP version 1.
765 A virtual DWO file is a DWO file as it appears in a DWP file. */
767 struct virtual_v1_dwo_sections
769 struct dwarf2_section_info abbrev
;
770 struct dwarf2_section_info line
;
771 struct dwarf2_section_info loc
;
772 struct dwarf2_section_info macinfo
;
773 struct dwarf2_section_info macro
;
774 struct dwarf2_section_info str_offsets
;
775 /* Each DWP hash table entry records one CU or one TU.
776 That is recorded here, and copied to dwo_unit.section. */
777 struct dwarf2_section_info info_or_types
;
780 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
781 In version 2, the sections of the DWO files are concatenated together
782 and stored in one section of that name. Thus each ELF section contains
783 several "virtual" sections. */
785 struct virtual_v2_dwo_sections
787 bfd_size_type abbrev_offset
;
788 bfd_size_type abbrev_size
;
790 bfd_size_type line_offset
;
791 bfd_size_type line_size
;
793 bfd_size_type loc_offset
;
794 bfd_size_type loc_size
;
796 bfd_size_type macinfo_offset
;
797 bfd_size_type macinfo_size
;
799 bfd_size_type macro_offset
;
800 bfd_size_type macro_size
;
802 bfd_size_type str_offsets_offset
;
803 bfd_size_type str_offsets_size
;
805 /* Each DWP hash table entry records one CU or one TU.
806 That is recorded here, and copied to dwo_unit.section. */
807 bfd_size_type info_or_types_offset
;
808 bfd_size_type info_or_types_size
;
811 /* Contents of DWP hash tables. */
813 struct dwp_hash_table
815 uint32_t version
, nr_columns
;
816 uint32_t nr_units
, nr_slots
;
817 const gdb_byte
*hash_table
, *unit_table
;
822 const gdb_byte
*indices
;
826 /* This is indexed by column number and gives the id of the section
828 #define MAX_NR_V2_DWO_SECTIONS \
829 (1 /* .debug_info or .debug_types */ \
830 + 1 /* .debug_abbrev */ \
831 + 1 /* .debug_line */ \
832 + 1 /* .debug_loc */ \
833 + 1 /* .debug_str_offsets */ \
834 + 1 /* .debug_macro or .debug_macinfo */)
835 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
836 const gdb_byte
*offsets
;
837 const gdb_byte
*sizes
;
842 /* Data for one DWP file. */
846 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
848 dbfd (std::move (abfd
))
852 /* Name of the file. */
855 /* File format version. */
859 gdb_bfd_ref_ptr dbfd
;
861 /* Section info for this file. */
862 struct dwp_sections sections
{};
864 /* Table of CUs in the file. */
865 const struct dwp_hash_table
*cus
= nullptr;
867 /* Table of TUs in the file. */
868 const struct dwp_hash_table
*tus
= nullptr;
870 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
874 /* Table to map ELF section numbers to their sections.
875 This is only needed for the DWP V1 file format. */
876 unsigned int num_sections
= 0;
877 asection
**elf_sections
= nullptr;
880 /* Struct used to pass misc. parameters to read_die_and_children, et
881 al. which are used for both .debug_info and .debug_types dies.
882 All parameters here are unchanging for the life of the call. This
883 struct exists to abstract away the constant parameters of die reading. */
885 struct die_reader_specs
887 /* The bfd of die_section. */
890 /* The CU of the DIE we are parsing. */
891 struct dwarf2_cu
*cu
;
893 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
894 struct dwo_file
*dwo_file
;
896 /* The section the die comes from.
897 This is either .debug_info or .debug_types, or the .dwo variants. */
898 struct dwarf2_section_info
*die_section
;
900 /* die_section->buffer. */
901 const gdb_byte
*buffer
;
903 /* The end of the buffer. */
904 const gdb_byte
*buffer_end
;
906 /* The abbreviation table to use when reading the DIEs. */
907 struct abbrev_table
*abbrev_table
;
910 /* A subclass of die_reader_specs that holds storage and has complex
911 constructor and destructor behavior. */
913 class cutu_reader
: public die_reader_specs
917 cutu_reader (dwarf2_per_cu_data
*this_cu
,
918 dwarf2_per_objfile
*per_objfile
,
919 struct abbrev_table
*abbrev_table
,
920 dwarf2_cu
*existing_cu
,
923 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
924 dwarf2_per_objfile
*per_objfile
,
925 struct dwarf2_cu
*parent_cu
= nullptr,
926 struct dwo_file
*dwo_file
= nullptr);
928 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
930 const gdb_byte
*info_ptr
= nullptr;
931 struct die_info
*comp_unit_die
= nullptr;
932 bool dummy_p
= false;
934 /* Release the new CU, putting it on the chain. This cannot be done
939 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
940 dwarf2_per_objfile
*per_objfile
,
941 dwarf2_cu
*existing_cu
);
943 struct dwarf2_per_cu_data
*m_this_cu
;
944 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
946 /* The ordinary abbreviation table. */
947 abbrev_table_up m_abbrev_table_holder
;
949 /* The DWO abbreviation table. */
950 abbrev_table_up m_dwo_abbrev_table
;
953 /* When we construct a partial symbol table entry we only
954 need this much information. */
955 struct partial_die_info
: public allocate_on_obstack
957 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
959 /* Disable assign but still keep copy ctor, which is needed
960 load_partial_dies. */
961 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
963 /* Adjust the partial die before generating a symbol for it. This
964 function may set the is_external flag or change the DIE's
966 void fixup (struct dwarf2_cu
*cu
);
968 /* Read a minimal amount of information into the minimal die
970 const gdb_byte
*read (const struct die_reader_specs
*reader
,
971 const struct abbrev_info
&abbrev
,
972 const gdb_byte
*info_ptr
);
974 /* Compute the name of this partial DIE. This memoizes the
975 result, so it is safe to call multiple times. */
976 const char *name (dwarf2_cu
*cu
);
978 /* Offset of this DIE. */
979 const sect_offset sect_off
;
981 /* DWARF-2 tag for this DIE. */
982 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
984 /* Assorted flags describing the data found in this DIE. */
985 const unsigned int has_children
: 1;
987 unsigned int is_external
: 1;
988 unsigned int is_declaration
: 1;
989 unsigned int has_type
: 1;
990 unsigned int has_specification
: 1;
991 unsigned int has_pc_info
: 1;
992 unsigned int may_be_inlined
: 1;
994 /* This DIE has been marked DW_AT_main_subprogram. */
995 unsigned int main_subprogram
: 1;
997 /* Flag set if the SCOPE field of this structure has been
999 unsigned int scope_set
: 1;
1001 /* Flag set if the DIE has a byte_size attribute. */
1002 unsigned int has_byte_size
: 1;
1004 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1005 unsigned int has_const_value
: 1;
1007 /* Flag set if any of the DIE's children are template arguments. */
1008 unsigned int has_template_arguments
: 1;
1010 /* Flag set if fixup has been called on this die. */
1011 unsigned int fixup_called
: 1;
1013 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1014 unsigned int is_dwz
: 1;
1016 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1017 unsigned int spec_is_dwz
: 1;
1019 unsigned int canonical_name
: 1;
1021 /* The name of this DIE. Normally the value of DW_AT_name, but
1022 sometimes a default name for unnamed DIEs. */
1023 const char *raw_name
= nullptr;
1025 /* The linkage name, if present. */
1026 const char *linkage_name
= nullptr;
1028 /* The scope to prepend to our children. This is generally
1029 allocated on the comp_unit_obstack, so will disappear
1030 when this compilation unit leaves the cache. */
1031 const char *scope
= nullptr;
1033 /* Some data associated with the partial DIE. The tag determines
1034 which field is live. */
1037 /* The location description associated with this DIE, if any. */
1038 struct dwarf_block
*locdesc
;
1039 /* The offset of an import, for DW_TAG_imported_unit. */
1040 sect_offset sect_off
;
1043 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1044 CORE_ADDR lowpc
= 0;
1045 CORE_ADDR highpc
= 0;
1047 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1048 DW_AT_sibling, if any. */
1049 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1050 could return DW_AT_sibling values to its caller load_partial_dies. */
1051 const gdb_byte
*sibling
= nullptr;
1053 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1054 DW_AT_specification (or DW_AT_abstract_origin or
1055 DW_AT_extension). */
1056 sect_offset spec_offset
{};
1058 /* Pointers to this DIE's parent, first child, and next sibling,
1060 struct partial_die_info
*die_parent
= nullptr;
1061 struct partial_die_info
*die_child
= nullptr;
1062 struct partial_die_info
*die_sibling
= nullptr;
1064 friend struct partial_die_info
*
1065 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1068 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1069 partial_die_info (sect_offset sect_off
)
1070 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1074 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1076 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1081 has_specification
= 0;
1084 main_subprogram
= 0;
1087 has_const_value
= 0;
1088 has_template_arguments
= 0;
1096 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1097 but this would require a corresponding change in unpack_field_as_long
1099 static int bits_per_byte
= 8;
1101 struct variant_part_builder
;
1103 /* When reading a variant, we track a bit more information about the
1104 field, and store it in an object of this type. */
1106 struct variant_field
1108 int first_field
= -1;
1109 int last_field
= -1;
1111 /* A variant can contain other variant parts. */
1112 std::vector
<variant_part_builder
> variant_parts
;
1114 /* If we see a DW_TAG_variant, then this will be set if this is the
1116 bool default_branch
= false;
1117 /* If we see a DW_AT_discr_value, then this will be the discriminant
1119 ULONGEST discriminant_value
= 0;
1120 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1122 struct dwarf_block
*discr_list_data
= nullptr;
1125 /* This represents a DW_TAG_variant_part. */
1127 struct variant_part_builder
1129 /* The offset of the discriminant field. */
1130 sect_offset discriminant_offset
{};
1132 /* Variants that are direct children of this variant part. */
1133 std::vector
<variant_field
> variants
;
1135 /* True if we're currently reading a variant. */
1136 bool processing_variant
= false;
1141 int accessibility
= 0;
1143 /* Variant parts need to find the discriminant, which is a DIE
1144 reference. We track the section offset of each field to make
1147 struct field field
{};
1152 const char *name
= nullptr;
1153 std::vector
<struct fn_field
> fnfields
;
1156 /* The routines that read and process dies for a C struct or C++ class
1157 pass lists of data member fields and lists of member function fields
1158 in an instance of a field_info structure, as defined below. */
1161 /* List of data member and baseclasses fields. */
1162 std::vector
<struct nextfield
> fields
;
1163 std::vector
<struct nextfield
> baseclasses
;
1165 /* Set if the accessibility of one of the fields is not public. */
1166 int non_public_fields
= 0;
1168 /* Member function fieldlist array, contains name of possibly overloaded
1169 member function, number of overloaded member functions and a pointer
1170 to the head of the member function field chain. */
1171 std::vector
<struct fnfieldlist
> fnfieldlists
;
1173 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1174 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1175 std::vector
<struct decl_field
> typedef_field_list
;
1177 /* Nested types defined by this class and the number of elements in this
1179 std::vector
<struct decl_field
> nested_types_list
;
1181 /* If non-null, this is the variant part we are currently
1183 variant_part_builder
*current_variant_part
= nullptr;
1184 /* This holds all the top-level variant parts attached to the type
1186 std::vector
<variant_part_builder
> variant_parts
;
1188 /* Return the total number of fields (including baseclasses). */
1189 int nfields () const
1191 return fields
.size () + baseclasses
.size ();
1195 /* Loaded secondary compilation units are kept in memory until they
1196 have not been referenced for the processing of this many
1197 compilation units. Set this to zero to disable caching. Cache
1198 sizes of up to at least twenty will improve startup time for
1199 typical inter-CU-reference binaries, at an obvious memory cost. */
1200 static int dwarf_max_cache_age
= 5;
1202 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1203 struct cmd_list_element
*c
, const char *value
)
1205 fprintf_filtered (file
, _("The upper bound on the age of cached "
1206 "DWARF compilation units is %s.\n"),
1210 /* local function prototypes */
1212 static void dwarf2_find_base_address (struct die_info
*die
,
1213 struct dwarf2_cu
*cu
);
1215 static dwarf2_psymtab
*create_partial_symtab
1216 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1219 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1220 const gdb_byte
*info_ptr
,
1221 struct die_info
*type_unit_die
);
1223 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1225 static void scan_partial_symbols (struct partial_die_info
*,
1226 CORE_ADDR
*, CORE_ADDR
*,
1227 int, struct dwarf2_cu
*);
1229 static void add_partial_symbol (struct partial_die_info
*,
1230 struct dwarf2_cu
*);
1232 static void add_partial_namespace (struct partial_die_info
*pdi
,
1233 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1234 int set_addrmap
, struct dwarf2_cu
*cu
);
1236 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1237 CORE_ADDR
*highpc
, int set_addrmap
,
1238 struct dwarf2_cu
*cu
);
1240 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1241 struct dwarf2_cu
*cu
);
1243 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1244 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1245 int need_pc
, struct dwarf2_cu
*cu
);
1247 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1249 static struct partial_die_info
*load_partial_dies
1250 (const struct die_reader_specs
*, const gdb_byte
*, int);
1252 /* A pair of partial_die_info and compilation unit. */
1253 struct cu_partial_die_info
1255 /* The compilation unit of the partial_die_info. */
1256 struct dwarf2_cu
*cu
;
1257 /* A partial_die_info. */
1258 struct partial_die_info
*pdi
;
1260 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1266 cu_partial_die_info () = delete;
1269 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1270 struct dwarf2_cu
*);
1272 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1273 struct attribute
*, struct attr_abbrev
*,
1274 const gdb_byte
*, bool *need_reprocess
);
1276 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1277 struct attribute
*attr
);
1279 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1281 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1282 dwarf2_section_info
*, sect_offset
);
1284 static const char *read_indirect_string
1285 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1286 const struct comp_unit_head
*, unsigned int *);
1288 static const char *read_indirect_string_at_offset
1289 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1291 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1295 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1296 ULONGEST str_index
);
1298 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1299 ULONGEST str_index
);
1301 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1303 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1304 struct dwarf2_cu
*);
1306 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1307 struct dwarf2_cu
*cu
);
1309 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1311 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1312 struct dwarf2_cu
*cu
);
1314 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1316 static struct die_info
*die_specification (struct die_info
*die
,
1317 struct dwarf2_cu
**);
1319 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1320 struct dwarf2_cu
*cu
);
1322 static void dwarf_decode_lines (struct line_header
*, const char *,
1323 struct dwarf2_cu
*, dwarf2_psymtab
*,
1324 CORE_ADDR
, int decode_mapping
);
1326 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1329 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1330 struct dwarf2_cu
*, struct symbol
* = NULL
);
1332 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1333 struct dwarf2_cu
*);
1335 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1338 struct obstack
*obstack
,
1339 struct dwarf2_cu
*cu
, LONGEST
*value
,
1340 const gdb_byte
**bytes
,
1341 struct dwarf2_locexpr_baton
**baton
);
1343 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1345 static int need_gnat_info (struct dwarf2_cu
*);
1347 static struct type
*die_descriptive_type (struct die_info
*,
1348 struct dwarf2_cu
*);
1350 static void set_descriptive_type (struct type
*, struct die_info
*,
1351 struct dwarf2_cu
*);
1353 static struct type
*die_containing_type (struct die_info
*,
1354 struct dwarf2_cu
*);
1356 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1357 struct dwarf2_cu
*);
1359 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1361 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1363 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1365 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1366 const char *suffix
, int physname
,
1367 struct dwarf2_cu
*cu
);
1369 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1371 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1373 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1375 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1377 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1379 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1381 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1382 struct dwarf2_cu
*, dwarf2_psymtab
*);
1384 /* Return the .debug_loclists section to use for cu. */
1385 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1387 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1388 values. Keep the items ordered with increasing constraints compliance. */
1391 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1392 PC_BOUNDS_NOT_PRESENT
,
1394 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1395 were present but they do not form a valid range of PC addresses. */
1398 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1401 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1405 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1406 CORE_ADDR
*, CORE_ADDR
*,
1410 static void get_scope_pc_bounds (struct die_info
*,
1411 CORE_ADDR
*, CORE_ADDR
*,
1412 struct dwarf2_cu
*);
1414 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1415 CORE_ADDR
, struct dwarf2_cu
*);
1417 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1418 struct dwarf2_cu
*);
1420 static void dwarf2_attach_fields_to_type (struct field_info
*,
1421 struct type
*, struct dwarf2_cu
*);
1423 static void dwarf2_add_member_fn (struct field_info
*,
1424 struct die_info
*, struct type
*,
1425 struct dwarf2_cu
*);
1427 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1429 struct dwarf2_cu
*);
1431 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1433 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1435 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1437 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1439 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1441 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1443 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1445 static struct type
*read_module_type (struct die_info
*die
,
1446 struct dwarf2_cu
*cu
);
1448 static const char *namespace_name (struct die_info
*die
,
1449 int *is_anonymous
, struct dwarf2_cu
*);
1451 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1456 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1457 struct dwarf2_cu
*);
1459 static struct die_info
*read_die_and_siblings_1
1460 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1463 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1464 const gdb_byte
*info_ptr
,
1465 const gdb_byte
**new_info_ptr
,
1466 struct die_info
*parent
);
1468 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1469 struct die_info
**, const gdb_byte
*,
1472 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1473 struct die_info
**, const gdb_byte
*);
1475 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1477 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1480 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1482 static const char *dwarf2_full_name (const char *name
,
1483 struct die_info
*die
,
1484 struct dwarf2_cu
*cu
);
1486 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1487 struct dwarf2_cu
*cu
);
1489 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1490 struct dwarf2_cu
**);
1492 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1494 static void dump_die_for_error (struct die_info
*);
1496 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1499 /*static*/ void dump_die (struct die_info
*, int max_level
);
1501 static void store_in_ref_table (struct die_info
*,
1502 struct dwarf2_cu
*);
1504 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1505 const struct attribute
*,
1506 struct dwarf2_cu
**);
1508 static struct die_info
*follow_die_ref (struct die_info
*,
1509 const struct attribute
*,
1510 struct dwarf2_cu
**);
1512 static struct die_info
*follow_die_sig (struct die_info
*,
1513 const struct attribute
*,
1514 struct dwarf2_cu
**);
1516 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1517 struct dwarf2_cu
*);
1519 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1520 const struct attribute
*,
1521 struct dwarf2_cu
*);
1523 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1524 dwarf2_per_objfile
*per_objfile
);
1526 static void read_signatured_type (signatured_type
*sig_type
,
1527 dwarf2_per_objfile
*per_objfile
);
1529 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1530 struct die_info
*die
, struct dwarf2_cu
*cu
,
1531 struct dynamic_prop
*prop
, struct type
*type
);
1533 /* memory allocation interface */
1535 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1537 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1539 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1541 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1542 struct dwarf2_loclist_baton
*baton
,
1543 const struct attribute
*attr
);
1545 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1547 struct dwarf2_cu
*cu
,
1550 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1551 const gdb_byte
*info_ptr
,
1552 struct abbrev_info
*abbrev
);
1554 static hashval_t
partial_die_hash (const void *item
);
1556 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1558 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1559 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1560 dwarf2_per_objfile
*per_objfile
);
1562 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1563 struct die_info
*comp_unit_die
,
1564 enum language pretend_language
);
1566 static struct type
*set_die_type (struct die_info
*, struct type
*,
1567 struct dwarf2_cu
*);
1569 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1571 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1573 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1574 dwarf2_per_objfile
*per_objfile
,
1576 enum language pretend_language
);
1578 static void process_full_comp_unit (dwarf2_cu
*cu
,
1579 enum language pretend_language
);
1581 static void process_full_type_unit (dwarf2_cu
*cu
,
1582 enum language pretend_language
);
1584 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1585 struct dwarf2_per_cu_data
*);
1587 static void dwarf2_mark (struct dwarf2_cu
*);
1589 static struct type
*get_die_type_at_offset (sect_offset
,
1590 dwarf2_per_cu_data
*per_cu
,
1591 dwarf2_per_objfile
*per_objfile
);
1593 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1595 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1596 dwarf2_per_objfile
*per_objfile
,
1597 enum language pretend_language
);
1599 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1601 /* Class, the destructor of which frees all allocated queue entries. This
1602 will only have work to do if an error was thrown while processing the
1603 dwarf. If no error was thrown then the queue entries should have all
1604 been processed, and freed, as we went along. */
1606 class dwarf2_queue_guard
1609 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1610 : m_per_objfile (per_objfile
)
1614 /* Free any entries remaining on the queue. There should only be
1615 entries left if we hit an error while processing the dwarf. */
1616 ~dwarf2_queue_guard ()
1618 /* Ensure that no memory is allocated by the queue. */
1619 std::queue
<dwarf2_queue_item
> empty
;
1620 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1623 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1626 dwarf2_per_objfile
*m_per_objfile
;
1629 dwarf2_queue_item::~dwarf2_queue_item ()
1631 /* Anything still marked queued is likely to be in an
1632 inconsistent state, so discard it. */
1635 per_objfile
->remove_cu (per_cu
);
1640 /* The return type of find_file_and_directory. Note, the enclosed
1641 string pointers are only valid while this object is valid. */
1643 struct file_and_directory
1645 /* The filename. This is never NULL. */
1648 /* The compilation directory. NULL if not known. If we needed to
1649 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1650 points directly to the DW_AT_comp_dir string attribute owned by
1651 the obstack that owns the DIE. */
1652 const char *comp_dir
;
1654 /* If we needed to build a new string for comp_dir, this is what
1655 owns the storage. */
1656 std::string comp_dir_storage
;
1659 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1660 struct dwarf2_cu
*cu
);
1662 static htab_up
allocate_signatured_type_table ();
1664 static htab_up
allocate_dwo_unit_table ();
1666 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1667 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1668 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1670 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1672 static struct dwo_unit
*lookup_dwo_comp_unit
1673 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1674 ULONGEST signature
);
1676 static struct dwo_unit
*lookup_dwo_type_unit
1677 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1679 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1681 /* A unique pointer to a dwo_file. */
1683 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1685 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1687 static void check_producer (struct dwarf2_cu
*cu
);
1689 static void free_line_header_voidp (void *arg
);
1691 /* Various complaints about symbol reading that don't abort the process. */
1694 dwarf2_debug_line_missing_file_complaint (void)
1696 complaint (_(".debug_line section has line data without a file"));
1700 dwarf2_debug_line_missing_end_sequence_complaint (void)
1702 complaint (_(".debug_line section has line "
1703 "program sequence without an end"));
1707 dwarf2_complex_location_expr_complaint (void)
1709 complaint (_("location expression too complex"));
1713 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1716 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1721 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1723 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1727 /* Hash function for line_header_hash. */
1730 line_header_hash (const struct line_header
*ofs
)
1732 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1735 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1738 line_header_hash_voidp (const void *item
)
1740 const struct line_header
*ofs
= (const struct line_header
*) item
;
1742 return line_header_hash (ofs
);
1745 /* Equality function for line_header_hash. */
1748 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1750 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1751 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1753 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1754 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1759 /* See declaration. */
1761 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1764 can_copy (can_copy_
)
1767 names
= &dwarf2_elf_names
;
1769 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1770 locate_sections (obfd
, sec
, *names
);
1773 dwarf2_per_bfd::~dwarf2_per_bfd ()
1775 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1776 per_cu
->imported_symtabs_free ();
1778 for (signatured_type
*sig_type
: all_type_units
)
1779 sig_type
->per_cu
.imported_symtabs_free ();
1781 /* Everything else should be on this->obstack. */
1787 dwarf2_per_objfile::remove_all_cus ()
1789 for (auto pair
: m_dwarf2_cus
)
1792 m_dwarf2_cus
.clear ();
1795 /* A helper class that calls free_cached_comp_units on
1798 class free_cached_comp_units
1802 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1803 : m_per_objfile (per_objfile
)
1807 ~free_cached_comp_units ()
1809 m_per_objfile
->remove_all_cus ();
1812 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1816 dwarf2_per_objfile
*m_per_objfile
;
1822 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1824 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1826 return this->m_symtabs
[per_cu
->index
] != nullptr;
1832 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1834 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1836 return this->m_symtabs
[per_cu
->index
];
1842 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1843 compunit_symtab
*symtab
)
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1846 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1848 this->m_symtabs
[per_cu
->index
] = symtab
;
1851 /* Try to locate the sections we need for DWARF 2 debugging
1852 information and return true if we have enough to do something.
1853 NAMES points to the dwarf2 section names, or is NULL if the standard
1854 ELF names are used. CAN_COPY is true for formats where symbol
1855 interposition is possible and so symbol values must follow copy
1856 relocation rules. */
1859 dwarf2_has_info (struct objfile
*objfile
,
1860 const struct dwarf2_debug_sections
*names
,
1863 if (objfile
->flags
& OBJF_READNEVER
)
1866 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1868 if (per_objfile
== NULL
)
1870 dwarf2_per_bfd
*per_bfd
;
1872 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1873 doesn't require relocations and if there aren't partial symbols
1874 from some other reader. */
1875 if (!objfile_has_partial_symbols (objfile
)
1876 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1878 /* See if one has been created for this BFD yet. */
1879 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1881 if (per_bfd
== nullptr)
1883 /* No, create it now. */
1884 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1885 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1890 /* No sharing possible, create one specifically for this objfile. */
1891 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1892 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1895 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1898 return (!per_objfile
->per_bfd
->info
.is_virtual
1899 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1900 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1901 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1904 /* When loading sections, we look either for uncompressed section or for
1905 compressed section names. */
1908 section_is_p (const char *section_name
,
1909 const struct dwarf2_section_names
*names
)
1911 if (names
->normal
!= NULL
1912 && strcmp (section_name
, names
->normal
) == 0)
1914 if (names
->compressed
!= NULL
1915 && strcmp (section_name
, names
->compressed
) == 0)
1920 /* See declaration. */
1923 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1924 const dwarf2_debug_sections
&names
)
1926 flagword aflag
= bfd_section_flags (sectp
);
1928 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1931 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1932 > bfd_get_file_size (abfd
))
1934 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1935 warning (_("Discarding section %s which has a section size (%s"
1936 ") larger than the file size [in module %s]"),
1937 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1938 bfd_get_filename (abfd
));
1940 else if (section_is_p (sectp
->name
, &names
.info
))
1942 this->info
.s
.section
= sectp
;
1943 this->info
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1947 this->abbrev
.s
.section
= sectp
;
1948 this->abbrev
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.line
))
1952 this->line
.s
.section
= sectp
;
1953 this->line
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.loc
))
1957 this->loc
.s
.section
= sectp
;
1958 this->loc
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.loclists
))
1962 this->loclists
.s
.section
= sectp
;
1963 this->loclists
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1967 this->macinfo
.s
.section
= sectp
;
1968 this->macinfo
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.macro
))
1972 this->macro
.s
.section
= sectp
;
1973 this->macro
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.str
))
1977 this->str
.s
.section
= sectp
;
1978 this->str
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1982 this->str_offsets
.s
.section
= sectp
;
1983 this->str_offsets
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.line_str
))
1987 this->line_str
.s
.section
= sectp
;
1988 this->line_str
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.addr
))
1992 this->addr
.s
.section
= sectp
;
1993 this->addr
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.frame
))
1997 this->frame
.s
.section
= sectp
;
1998 this->frame
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2002 this->eh_frame
.s
.section
= sectp
;
2003 this->eh_frame
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.ranges
))
2007 this->ranges
.s
.section
= sectp
;
2008 this->ranges
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2012 this->rnglists
.s
.section
= sectp
;
2013 this->rnglists
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.types
))
2017 struct dwarf2_section_info type_section
;
2019 memset (&type_section
, 0, sizeof (type_section
));
2020 type_section
.s
.section
= sectp
;
2021 type_section
.size
= bfd_section_size (sectp
);
2023 this->types
.push_back (type_section
);
2025 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2027 this->gdb_index
.s
.section
= sectp
;
2028 this->gdb_index
.size
= bfd_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2032 this->debug_names
.s
.section
= sectp
;
2033 this->debug_names
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2037 this->debug_aranges
.s
.section
= sectp
;
2038 this->debug_aranges
.size
= bfd_section_size (sectp
);
2041 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2042 && bfd_section_vma (sectp
) == 0)
2043 this->has_section_at_zero
= true;
2046 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2050 dwarf2_get_section_info (struct objfile
*objfile
,
2051 enum dwarf2_section_enum sect
,
2052 asection
**sectp
, const gdb_byte
**bufp
,
2053 bfd_size_type
*sizep
)
2055 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2056 struct dwarf2_section_info
*info
;
2058 /* We may see an objfile without any DWARF, in which case we just
2060 if (per_objfile
== NULL
)
2069 case DWARF2_DEBUG_FRAME
:
2070 info
= &per_objfile
->per_bfd
->frame
;
2072 case DWARF2_EH_FRAME
:
2073 info
= &per_objfile
->per_bfd
->eh_frame
;
2076 gdb_assert_not_reached ("unexpected section");
2079 info
->read (objfile
);
2081 *sectp
= info
->get_bfd_section ();
2082 *bufp
= info
->buffer
;
2083 *sizep
= info
->size
;
2086 /* A helper function to find the sections for a .dwz file. */
2089 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2091 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2093 /* Note that we only support the standard ELF names, because .dwz
2094 is ELF-only (at the time of writing). */
2095 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2097 dwz_file
->abbrev
.s
.section
= sectp
;
2098 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2100 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2102 dwz_file
->info
.s
.section
= sectp
;
2103 dwz_file
->info
.size
= bfd_section_size (sectp
);
2105 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2107 dwz_file
->str
.s
.section
= sectp
;
2108 dwz_file
->str
.size
= bfd_section_size (sectp
);
2110 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2112 dwz_file
->line
.s
.section
= sectp
;
2113 dwz_file
->line
.size
= bfd_section_size (sectp
);
2115 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2117 dwz_file
->macro
.s
.section
= sectp
;
2118 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2120 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2122 dwz_file
->gdb_index
.s
.section
= sectp
;
2123 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2125 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2127 dwz_file
->debug_names
.s
.section
= sectp
;
2128 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2132 /* See dwarf2read.h. */
2135 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2137 const char *filename
;
2138 bfd_size_type buildid_len_arg
;
2142 if (per_bfd
->dwz_file
!= NULL
)
2143 return per_bfd
->dwz_file
.get ();
2145 bfd_set_error (bfd_error_no_error
);
2146 gdb::unique_xmalloc_ptr
<char> data
2147 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2148 &buildid_len_arg
, &buildid
));
2151 if (bfd_get_error () == bfd_error_no_error
)
2153 error (_("could not read '.gnu_debugaltlink' section: %s"),
2154 bfd_errmsg (bfd_get_error ()));
2157 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2159 buildid_len
= (size_t) buildid_len_arg
;
2161 filename
= data
.get ();
2163 std::string abs_storage
;
2164 if (!IS_ABSOLUTE_PATH (filename
))
2166 gdb::unique_xmalloc_ptr
<char> abs
2167 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2169 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2170 filename
= abs_storage
.c_str ();
2173 /* First try the file name given in the section. If that doesn't
2174 work, try to use the build-id instead. */
2175 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2176 if (dwz_bfd
!= NULL
)
2178 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2179 dwz_bfd
.reset (nullptr);
2182 if (dwz_bfd
== NULL
)
2183 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2185 if (dwz_bfd
== nullptr)
2187 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2188 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2190 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2197 /* File successfully retrieved from server. */
2198 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2200 if (dwz_bfd
== nullptr)
2201 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2202 alt_filename
.get ());
2203 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2204 dwz_bfd
.reset (nullptr);
2208 if (dwz_bfd
== NULL
)
2209 error (_("could not find '.gnu_debugaltlink' file for %s"),
2210 bfd_get_filename (per_bfd
->obfd
));
2212 std::unique_ptr
<struct dwz_file
> result
2213 (new struct dwz_file (std::move (dwz_bfd
)));
2215 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2218 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2219 per_bfd
->dwz_file
= std::move (result
);
2220 return per_bfd
->dwz_file
.get ();
2223 /* DWARF quick_symbols_functions support. */
2225 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2226 unique line tables, so we maintain a separate table of all .debug_line
2227 derived entries to support the sharing.
2228 All the quick functions need is the list of file names. We discard the
2229 line_header when we're done and don't need to record it here. */
2230 struct quick_file_names
2232 /* The data used to construct the hash key. */
2233 struct stmt_list_hash hash
;
2235 /* The number of entries in file_names, real_names. */
2236 unsigned int num_file_names
;
2238 /* The file names from the line table, after being run through
2240 const char **file_names
;
2242 /* The file names from the line table after being run through
2243 gdb_realpath. These are computed lazily. */
2244 const char **real_names
;
2247 /* When using the index (and thus not using psymtabs), each CU has an
2248 object of this type. This is used to hold information needed by
2249 the various "quick" methods. */
2250 struct dwarf2_per_cu_quick_data
2252 /* The file table. This can be NULL if there was no file table
2253 or it's currently not read in.
2254 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2255 struct quick_file_names
*file_names
;
2257 /* A temporary mark bit used when iterating over all CUs in
2258 expand_symtabs_matching. */
2259 unsigned int mark
: 1;
2261 /* True if we've tried to read the file table and found there isn't one.
2262 There will be no point in trying to read it again next time. */
2263 unsigned int no_file_data
: 1;
2266 /* Utility hash function for a stmt_list_hash. */
2269 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2273 if (stmt_list_hash
->dwo_unit
!= NULL
)
2274 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2275 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2279 /* Utility equality function for a stmt_list_hash. */
2282 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2283 const struct stmt_list_hash
*rhs
)
2285 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2287 if (lhs
->dwo_unit
!= NULL
2288 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2291 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2294 /* Hash function for a quick_file_names. */
2297 hash_file_name_entry (const void *e
)
2299 const struct quick_file_names
*file_data
2300 = (const struct quick_file_names
*) e
;
2302 return hash_stmt_list_entry (&file_data
->hash
);
2305 /* Equality function for a quick_file_names. */
2308 eq_file_name_entry (const void *a
, const void *b
)
2310 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2311 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2313 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2316 /* Delete function for a quick_file_names. */
2319 delete_file_name_entry (void *e
)
2321 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2324 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2326 xfree ((void*) file_data
->file_names
[i
]);
2327 if (file_data
->real_names
)
2328 xfree ((void*) file_data
->real_names
[i
]);
2331 /* The space for the struct itself lives on the obstack, so we don't
2335 /* Create a quick_file_names hash table. */
2338 create_quick_file_names_table (unsigned int nr_initial_entries
)
2340 return htab_up (htab_create_alloc (nr_initial_entries
,
2341 hash_file_name_entry
, eq_file_name_entry
,
2342 delete_file_name_entry
, xcalloc
, xfree
));
2345 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2346 function is unrelated to symtabs, symtab would have to be created afterwards.
2347 You should call age_cached_comp_units after processing the CU. */
2350 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2353 if (per_cu
->is_debug_types
)
2354 load_full_type_unit (per_cu
, per_objfile
);
2356 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2358 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2360 return nullptr; /* Dummy CU. */
2362 dwarf2_find_base_address (cu
->dies
, cu
);
2367 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2370 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2371 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2373 /* Skip type_unit_groups, reading the type units they contain
2374 is handled elsewhere. */
2375 if (per_cu
->type_unit_group_p ())
2378 /* The destructor of dwarf2_queue_guard frees any entries left on
2379 the queue. After this point we're guaranteed to leave this function
2380 with the dwarf queue empty. */
2381 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2383 if (!per_objfile
->symtab_set_p (per_cu
))
2385 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2386 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2388 /* If we just loaded a CU from a DWO, and we're working with an index
2389 that may badly handle TUs, load all the TUs in that DWO as well.
2390 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2391 if (!per_cu
->is_debug_types
2393 && cu
->dwo_unit
!= NULL
2394 && per_objfile
->per_bfd
->index_table
!= NULL
2395 && per_objfile
->per_bfd
->index_table
->version
<= 7
2396 /* DWP files aren't supported yet. */
2397 && get_dwp_file (per_objfile
) == NULL
)
2398 queue_and_load_all_dwo_tus (cu
);
2401 process_queue (per_objfile
);
2403 /* Age the cache, releasing compilation units that have not
2404 been used recently. */
2405 per_objfile
->age_comp_units ();
2408 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2409 the per-objfile for which this symtab is instantiated.
2411 Returns the resulting symbol table. */
2413 static struct compunit_symtab
*
2414 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2415 dwarf2_per_objfile
*per_objfile
,
2418 gdb_assert (per_objfile
->per_bfd
->using_index
);
2420 if (!per_objfile
->symtab_set_p (per_cu
))
2422 free_cached_comp_units
freer (per_objfile
);
2423 scoped_restore decrementer
= increment_reading_symtab ();
2424 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2425 process_cu_includes (per_objfile
);
2428 return per_objfile
->get_symtab (per_cu
);
2431 /* See declaration. */
2433 dwarf2_per_cu_data
*
2434 dwarf2_per_bfd::get_cutu (int index
)
2436 if (index
>= this->all_comp_units
.size ())
2438 index
-= this->all_comp_units
.size ();
2439 gdb_assert (index
< this->all_type_units
.size ());
2440 return &this->all_type_units
[index
]->per_cu
;
2443 return this->all_comp_units
[index
];
2446 /* See declaration. */
2448 dwarf2_per_cu_data
*
2449 dwarf2_per_bfd::get_cu (int index
)
2451 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2453 return this->all_comp_units
[index
];
2456 /* See declaration. */
2459 dwarf2_per_bfd::get_tu (int index
)
2461 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2463 return this->all_type_units
[index
];
2468 dwarf2_per_cu_data
*
2469 dwarf2_per_bfd::allocate_per_cu ()
2471 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2472 result
->per_bfd
= this;
2473 result
->index
= m_num_psymtabs
++;
2480 dwarf2_per_bfd::allocate_signatured_type ()
2482 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2483 result
->per_cu
.per_bfd
= this;
2484 result
->per_cu
.index
= m_num_psymtabs
++;
2488 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2489 obstack, and constructed with the specified field values. */
2491 static dwarf2_per_cu_data
*
2492 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2493 struct dwarf2_section_info
*section
,
2495 sect_offset sect_off
, ULONGEST length
)
2497 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2498 the_cu
->sect_off
= sect_off
;
2499 the_cu
->length
= length
;
2500 the_cu
->section
= section
;
2501 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2502 struct dwarf2_per_cu_quick_data
);
2503 the_cu
->is_dwz
= is_dwz
;
2507 /* A helper for create_cus_from_index that handles a given list of
2511 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2512 const gdb_byte
*cu_list
, offset_type n_elements
,
2513 struct dwarf2_section_info
*section
,
2516 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2518 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2520 sect_offset sect_off
2521 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2522 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2525 dwarf2_per_cu_data
*per_cu
2526 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2528 per_bfd
->all_comp_units
.push_back (per_cu
);
2532 /* Read the CU list from the mapped index, and use it to create all
2533 the CU objects for PER_BFD. */
2536 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2537 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2538 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2540 gdb_assert (per_bfd
->all_comp_units
.empty ());
2541 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2543 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2546 if (dwz_elements
== 0)
2549 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2550 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2554 /* Create the signatured type hash table from the index. */
2557 create_signatured_type_table_from_index
2558 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2559 const gdb_byte
*bytes
, offset_type elements
)
2561 gdb_assert (per_bfd
->all_type_units
.empty ());
2562 per_bfd
->all_type_units
.reserve (elements
/ 3);
2564 htab_up sig_types_hash
= allocate_signatured_type_table ();
2566 for (offset_type i
= 0; i
< elements
; i
+= 3)
2568 struct signatured_type
*sig_type
;
2571 cu_offset type_offset_in_tu
;
2573 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2574 sect_offset sect_off
2575 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2577 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2579 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2582 sig_type
= per_bfd
->allocate_signatured_type ();
2583 sig_type
->signature
= signature
;
2584 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2585 sig_type
->per_cu
.is_debug_types
= 1;
2586 sig_type
->per_cu
.section
= section
;
2587 sig_type
->per_cu
.sect_off
= sect_off
;
2588 sig_type
->per_cu
.v
.quick
2589 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2590 struct dwarf2_per_cu_quick_data
);
2592 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2595 per_bfd
->all_type_units
.push_back (sig_type
);
2598 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2601 /* Create the signatured type hash table from .debug_names. */
2604 create_signatured_type_table_from_debug_names
2605 (dwarf2_per_objfile
*per_objfile
,
2606 const mapped_debug_names
&map
,
2607 struct dwarf2_section_info
*section
,
2608 struct dwarf2_section_info
*abbrev_section
)
2610 struct objfile
*objfile
= per_objfile
->objfile
;
2612 section
->read (objfile
);
2613 abbrev_section
->read (objfile
);
2615 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2616 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2618 htab_up sig_types_hash
= allocate_signatured_type_table ();
2620 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2622 struct signatured_type
*sig_type
;
2625 sect_offset sect_off
2626 = (sect_offset
) (extract_unsigned_integer
2627 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2629 map
.dwarf5_byte_order
));
2631 comp_unit_head cu_header
;
2632 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2634 section
->buffer
+ to_underlying (sect_off
),
2637 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2638 sig_type
->signature
= cu_header
.signature
;
2639 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2640 sig_type
->per_cu
.is_debug_types
= 1;
2641 sig_type
->per_cu
.section
= section
;
2642 sig_type
->per_cu
.sect_off
= sect_off
;
2643 sig_type
->per_cu
.v
.quick
2644 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2645 struct dwarf2_per_cu_quick_data
);
2647 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2650 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2653 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2656 /* Read the address map data from the mapped index, and use it to
2657 populate the objfile's psymtabs_addrmap. */
2660 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2661 struct mapped_index
*index
)
2663 struct objfile
*objfile
= per_objfile
->objfile
;
2664 struct gdbarch
*gdbarch
= objfile
->arch ();
2665 const gdb_byte
*iter
, *end
;
2666 struct addrmap
*mutable_map
;
2669 auto_obstack temp_obstack
;
2671 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2673 iter
= index
->address_table
.data ();
2674 end
= iter
+ index
->address_table
.size ();
2676 baseaddr
= objfile
->text_section_offset ();
2680 ULONGEST hi
, lo
, cu_index
;
2681 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2683 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2685 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2690 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2691 hex_string (lo
), hex_string (hi
));
2695 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2697 complaint (_(".gdb_index address table has invalid CU number %u"),
2698 (unsigned) cu_index
);
2702 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2703 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2704 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2705 per_objfile
->per_bfd
->get_cu (cu_index
));
2708 objfile
->partial_symtabs
->psymtabs_addrmap
2709 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2712 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2713 populate the objfile's psymtabs_addrmap. */
2716 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2717 struct dwarf2_section_info
*section
)
2719 struct objfile
*objfile
= per_objfile
->objfile
;
2720 bfd
*abfd
= objfile
->obfd
;
2721 struct gdbarch
*gdbarch
= objfile
->arch ();
2722 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2724 auto_obstack temp_obstack
;
2725 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2727 std::unordered_map
<sect_offset
,
2728 dwarf2_per_cu_data
*,
2729 gdb::hash_enum
<sect_offset
>>
2730 debug_info_offset_to_per_cu
;
2731 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2733 const auto insertpair
2734 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2735 if (!insertpair
.second
)
2737 warning (_("Section .debug_aranges in %s has duplicate "
2738 "debug_info_offset %s, ignoring .debug_aranges."),
2739 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2744 section
->read (objfile
);
2746 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2748 const gdb_byte
*addr
= section
->buffer
;
2750 while (addr
< section
->buffer
+ section
->size
)
2752 const gdb_byte
*const entry_addr
= addr
;
2753 unsigned int bytes_read
;
2755 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2759 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2760 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2761 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2762 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2764 warning (_("Section .debug_aranges in %s entry at offset %s "
2765 "length %s exceeds section length %s, "
2766 "ignoring .debug_aranges."),
2767 objfile_name (objfile
),
2768 plongest (entry_addr
- section
->buffer
),
2769 plongest (bytes_read
+ entry_length
),
2770 pulongest (section
->size
));
2774 /* The version number. */
2775 const uint16_t version
= read_2_bytes (abfd
, addr
);
2779 warning (_("Section .debug_aranges in %s entry at offset %s "
2780 "has unsupported version %d, ignoring .debug_aranges."),
2781 objfile_name (objfile
),
2782 plongest (entry_addr
- section
->buffer
), version
);
2786 const uint64_t debug_info_offset
2787 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2788 addr
+= offset_size
;
2789 const auto per_cu_it
2790 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2791 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2793 warning (_("Section .debug_aranges in %s entry at offset %s "
2794 "debug_info_offset %s does not exists, "
2795 "ignoring .debug_aranges."),
2796 objfile_name (objfile
),
2797 plongest (entry_addr
- section
->buffer
),
2798 pulongest (debug_info_offset
));
2801 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2803 const uint8_t address_size
= *addr
++;
2804 if (address_size
< 1 || address_size
> 8)
2806 warning (_("Section .debug_aranges in %s entry at offset %s "
2807 "address_size %u is invalid, ignoring .debug_aranges."),
2808 objfile_name (objfile
),
2809 plongest (entry_addr
- section
->buffer
), address_size
);
2813 const uint8_t segment_selector_size
= *addr
++;
2814 if (segment_selector_size
!= 0)
2816 warning (_("Section .debug_aranges in %s entry at offset %s "
2817 "segment_selector_size %u is not supported, "
2818 "ignoring .debug_aranges."),
2819 objfile_name (objfile
),
2820 plongest (entry_addr
- section
->buffer
),
2821 segment_selector_size
);
2825 /* Must pad to an alignment boundary that is twice the address
2826 size. It is undocumented by the DWARF standard but GCC does
2828 for (size_t padding
= ((-(addr
- section
->buffer
))
2829 & (2 * address_size
- 1));
2830 padding
> 0; padding
--)
2833 warning (_("Section .debug_aranges in %s entry at offset %s "
2834 "padding is not zero, ignoring .debug_aranges."),
2835 objfile_name (objfile
),
2836 plongest (entry_addr
- section
->buffer
));
2842 if (addr
+ 2 * address_size
> entry_end
)
2844 warning (_("Section .debug_aranges in %s entry at offset %s "
2845 "address list is not properly terminated, "
2846 "ignoring .debug_aranges."),
2847 objfile_name (objfile
),
2848 plongest (entry_addr
- section
->buffer
));
2851 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2853 addr
+= address_size
;
2854 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2856 addr
+= address_size
;
2857 if (start
== 0 && length
== 0)
2859 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2861 /* Symbol was eliminated due to a COMDAT group. */
2864 ULONGEST end
= start
+ length
;
2865 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2867 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2869 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2873 objfile
->partial_symtabs
->psymtabs_addrmap
2874 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2877 /* Find a slot in the mapped index INDEX for the object named NAME.
2878 If NAME is found, set *VEC_OUT to point to the CU vector in the
2879 constant pool and return true. If NAME cannot be found, return
2883 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2884 offset_type
**vec_out
)
2887 offset_type slot
, step
;
2888 int (*cmp
) (const char *, const char *);
2890 gdb::unique_xmalloc_ptr
<char> without_params
;
2891 if (current_language
->la_language
== language_cplus
2892 || current_language
->la_language
== language_fortran
2893 || current_language
->la_language
== language_d
)
2895 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2898 if (strchr (name
, '(') != NULL
)
2900 without_params
= cp_remove_params (name
);
2902 if (without_params
!= NULL
)
2903 name
= without_params
.get ();
2907 /* Index version 4 did not support case insensitive searches. But the
2908 indices for case insensitive languages are built in lowercase, therefore
2909 simulate our NAME being searched is also lowercased. */
2910 hash
= mapped_index_string_hash ((index
->version
== 4
2911 && case_sensitivity
== case_sensitive_off
2912 ? 5 : index
->version
),
2915 slot
= hash
& (index
->symbol_table
.size () - 1);
2916 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2917 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2923 const auto &bucket
= index
->symbol_table
[slot
];
2924 if (bucket
.name
== 0 && bucket
.vec
== 0)
2927 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2928 if (!cmp (name
, str
))
2930 *vec_out
= (offset_type
*) (index
->constant_pool
2931 + MAYBE_SWAP (bucket
.vec
));
2935 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2939 /* A helper function that reads the .gdb_index from BUFFER and fills
2940 in MAP. FILENAME is the name of the file containing the data;
2941 it is used for error reporting. DEPRECATED_OK is true if it is
2942 ok to use deprecated sections.
2944 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2945 out parameters that are filled in with information about the CU and
2946 TU lists in the section.
2948 Returns true if all went well, false otherwise. */
2951 read_gdb_index_from_buffer (const char *filename
,
2953 gdb::array_view
<const gdb_byte
> buffer
,
2954 struct mapped_index
*map
,
2955 const gdb_byte
**cu_list
,
2956 offset_type
*cu_list_elements
,
2957 const gdb_byte
**types_list
,
2958 offset_type
*types_list_elements
)
2960 const gdb_byte
*addr
= &buffer
[0];
2962 /* Version check. */
2963 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2964 /* Versions earlier than 3 emitted every copy of a psymbol. This
2965 causes the index to behave very poorly for certain requests. Version 3
2966 contained incomplete addrmap. So, it seems better to just ignore such
2970 static int warning_printed
= 0;
2971 if (!warning_printed
)
2973 warning (_("Skipping obsolete .gdb_index section in %s."),
2975 warning_printed
= 1;
2979 /* Index version 4 uses a different hash function than index version
2982 Versions earlier than 6 did not emit psymbols for inlined
2983 functions. Using these files will cause GDB not to be able to
2984 set breakpoints on inlined functions by name, so we ignore these
2985 indices unless the user has done
2986 "set use-deprecated-index-sections on". */
2987 if (version
< 6 && !deprecated_ok
)
2989 static int warning_printed
= 0;
2990 if (!warning_printed
)
2993 Skipping deprecated .gdb_index section in %s.\n\
2994 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2995 to use the section anyway."),
2997 warning_printed
= 1;
3001 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3002 of the TU (for symbols coming from TUs),
3003 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3004 Plus gold-generated indices can have duplicate entries for global symbols,
3005 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3006 These are just performance bugs, and we can't distinguish gdb-generated
3007 indices from gold-generated ones, so issue no warning here. */
3009 /* Indexes with higher version than the one supported by GDB may be no
3010 longer backward compatible. */
3014 map
->version
= version
;
3016 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3019 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3020 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3024 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3025 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3026 - MAYBE_SWAP (metadata
[i
]))
3030 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3031 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3033 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3036 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3037 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3039 = gdb::array_view
<mapped_index::symbol_table_slot
>
3040 ((mapped_index::symbol_table_slot
*) symbol_table
,
3041 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3044 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3049 /* Callback types for dwarf2_read_gdb_index. */
3051 typedef gdb::function_view
3052 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3053 get_gdb_index_contents_ftype
;
3054 typedef gdb::function_view
3055 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3056 get_gdb_index_contents_dwz_ftype
;
3058 /* Read .gdb_index. If everything went ok, initialize the "quick"
3059 elements of all the CUs and return 1. Otherwise, return 0. */
3062 dwarf2_read_gdb_index
3063 (dwarf2_per_objfile
*per_objfile
,
3064 get_gdb_index_contents_ftype get_gdb_index_contents
,
3065 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3067 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3068 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3069 struct dwz_file
*dwz
;
3070 struct objfile
*objfile
= per_objfile
->objfile
;
3071 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3073 gdb::array_view
<const gdb_byte
> main_index_contents
3074 = get_gdb_index_contents (objfile
, per_bfd
);
3076 if (main_index_contents
.empty ())
3079 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3080 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3081 use_deprecated_index_sections
,
3082 main_index_contents
, map
.get (), &cu_list
,
3083 &cu_list_elements
, &types_list
,
3084 &types_list_elements
))
3087 /* Don't use the index if it's empty. */
3088 if (map
->symbol_table
.empty ())
3091 /* If there is a .dwz file, read it so we can get its CU list as
3093 dwz
= dwarf2_get_dwz_file (per_bfd
);
3096 struct mapped_index dwz_map
;
3097 const gdb_byte
*dwz_types_ignore
;
3098 offset_type dwz_types_elements_ignore
;
3100 gdb::array_view
<const gdb_byte
> dwz_index_content
3101 = get_gdb_index_contents_dwz (objfile
, dwz
);
3103 if (dwz_index_content
.empty ())
3106 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3107 1, dwz_index_content
, &dwz_map
,
3108 &dwz_list
, &dwz_list_elements
,
3110 &dwz_types_elements_ignore
))
3112 warning (_("could not read '.gdb_index' section from %s; skipping"),
3113 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3118 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3121 if (types_list_elements
)
3123 /* We can only handle a single .debug_types when we have an
3125 if (per_bfd
->types
.size () != 1)
3128 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3130 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3131 types_list_elements
);
3134 create_addrmap_from_index (per_objfile
, map
.get ());
3136 per_bfd
->index_table
= std::move (map
);
3137 per_bfd
->using_index
= 1;
3138 per_bfd
->quick_file_names_table
=
3139 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3141 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3142 objfiles using the same BFD. */
3143 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3144 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3149 /* die_reader_func for dw2_get_file_names. */
3152 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3153 const gdb_byte
*info_ptr
,
3154 struct die_info
*comp_unit_die
)
3156 struct dwarf2_cu
*cu
= reader
->cu
;
3157 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3158 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3159 struct dwarf2_per_cu_data
*lh_cu
;
3160 struct attribute
*attr
;
3162 struct quick_file_names
*qfn
;
3164 gdb_assert (! this_cu
->is_debug_types
);
3166 /* Our callers never want to match partial units -- instead they
3167 will match the enclosing full CU. */
3168 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3170 this_cu
->v
.quick
->no_file_data
= 1;
3178 sect_offset line_offset
{};
3180 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3181 if (attr
!= nullptr)
3183 struct quick_file_names find_entry
;
3185 line_offset
= (sect_offset
) DW_UNSND (attr
);
3187 /* We may have already read in this line header (TU line header sharing).
3188 If we have we're done. */
3189 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3190 find_entry
.hash
.line_sect_off
= line_offset
;
3191 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3192 &find_entry
, INSERT
);
3195 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3199 lh
= dwarf_decode_line_header (line_offset
, cu
);
3203 lh_cu
->v
.quick
->no_file_data
= 1;
3207 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3208 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3209 qfn
->hash
.line_sect_off
= line_offset
;
3210 gdb_assert (slot
!= NULL
);
3213 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3216 if (strcmp (fnd
.name
, "<unknown>") != 0)
3219 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3221 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3222 qfn
->num_file_names
);
3224 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3225 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3226 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3227 fnd
.comp_dir
).release ();
3228 qfn
->real_names
= NULL
;
3230 lh_cu
->v
.quick
->file_names
= qfn
;
3233 /* A helper for the "quick" functions which attempts to read the line
3234 table for THIS_CU. */
3236 static struct quick_file_names
*
3237 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3238 dwarf2_per_objfile
*per_objfile
)
3240 /* This should never be called for TUs. */
3241 gdb_assert (! this_cu
->is_debug_types
);
3242 /* Nor type unit groups. */
3243 gdb_assert (! this_cu
->type_unit_group_p ());
3245 if (this_cu
->v
.quick
->file_names
!= NULL
)
3246 return this_cu
->v
.quick
->file_names
;
3247 /* If we know there is no line data, no point in looking again. */
3248 if (this_cu
->v
.quick
->no_file_data
)
3251 cutu_reader
reader (this_cu
, per_objfile
);
3252 if (!reader
.dummy_p
)
3253 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3255 if (this_cu
->v
.quick
->no_file_data
)
3257 return this_cu
->v
.quick
->file_names
;
3260 /* A helper for the "quick" functions which computes and caches the
3261 real path for a given file name from the line table. */
3264 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3265 struct quick_file_names
*qfn
, int index
)
3267 if (qfn
->real_names
== NULL
)
3268 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3269 qfn
->num_file_names
, const char *);
3271 if (qfn
->real_names
[index
] == NULL
)
3272 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3274 return qfn
->real_names
[index
];
3277 static struct symtab
*
3278 dw2_find_last_source_symtab (struct objfile
*objfile
)
3280 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3281 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3282 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3287 return compunit_primary_filetab (cust
);
3290 /* Traversal function for dw2_forget_cached_source_info. */
3293 dw2_free_cached_file_names (void **slot
, void *info
)
3295 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3297 if (file_data
->real_names
)
3301 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3303 xfree ((void*) file_data
->real_names
[i
]);
3304 file_data
->real_names
[i
] = NULL
;
3312 dw2_forget_cached_source_info (struct objfile
*objfile
)
3314 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3316 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3317 dw2_free_cached_file_names
, NULL
);
3320 /* Helper function for dw2_map_symtabs_matching_filename that expands
3321 the symtabs and calls the iterator. */
3324 dw2_map_expand_apply (struct objfile
*objfile
,
3325 struct dwarf2_per_cu_data
*per_cu
,
3326 const char *name
, const char *real_path
,
3327 gdb::function_view
<bool (symtab
*)> callback
)
3329 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3331 /* Don't visit already-expanded CUs. */
3332 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3333 if (per_objfile
->symtab_set_p (per_cu
))
3336 /* This may expand more than one symtab, and we want to iterate over
3338 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3340 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3341 last_made
, callback
);
3344 /* Implementation of the map_symtabs_matching_filename method. */
3347 dw2_map_symtabs_matching_filename
3348 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3349 gdb::function_view
<bool (symtab
*)> callback
)
3351 const char *name_basename
= lbasename (name
);
3352 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3354 /* The rule is CUs specify all the files, including those used by
3355 any TU, so there's no need to scan TUs here. */
3357 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3359 /* We only need to look at symtabs not already expanded. */
3360 if (per_objfile
->symtab_set_p (per_cu
))
3363 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3364 if (file_data
== NULL
)
3367 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3369 const char *this_name
= file_data
->file_names
[j
];
3370 const char *this_real_name
;
3372 if (compare_filenames_for_search (this_name
, name
))
3374 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3380 /* Before we invoke realpath, which can get expensive when many
3381 files are involved, do a quick comparison of the basenames. */
3382 if (! basenames_may_differ
3383 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3386 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3387 if (compare_filenames_for_search (this_real_name
, name
))
3389 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3395 if (real_path
!= NULL
)
3397 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3398 gdb_assert (IS_ABSOLUTE_PATH (name
));
3399 if (this_real_name
!= NULL
3400 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3402 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3414 /* Struct used to manage iterating over all CUs looking for a symbol. */
3416 struct dw2_symtab_iterator
3418 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3419 dwarf2_per_objfile
*per_objfile
;
3420 /* If set, only look for symbols that match that block. Valid values are
3421 GLOBAL_BLOCK and STATIC_BLOCK. */
3422 gdb::optional
<block_enum
> block_index
;
3423 /* The kind of symbol we're looking for. */
3425 /* The list of CUs from the index entry of the symbol,
3426 or NULL if not found. */
3428 /* The next element in VEC to look at. */
3430 /* The number of elements in VEC, or zero if there is no match. */
3432 /* Have we seen a global version of the symbol?
3433 If so we can ignore all further global instances.
3434 This is to work around gold/15646, inefficient gold-generated
3439 /* Initialize the index symtab iterator ITER, common part. */
3442 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3443 dwarf2_per_objfile
*per_objfile
,
3444 gdb::optional
<block_enum
> block_index
,
3447 iter
->per_objfile
= per_objfile
;
3448 iter
->block_index
= block_index
;
3449 iter
->domain
= domain
;
3451 iter
->global_seen
= 0;
3456 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3459 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3460 dwarf2_per_objfile
*per_objfile
,
3461 gdb::optional
<block_enum
> block_index
,
3465 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3467 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3468 /* index is NULL if OBJF_READNOW. */
3472 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3473 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3476 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3479 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3480 dwarf2_per_objfile
*per_objfile
,
3481 gdb::optional
<block_enum
> block_index
,
3482 domain_enum domain
, offset_type namei
)
3484 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3486 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3487 /* index is NULL if OBJF_READNOW. */
3491 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3492 const auto &bucket
= index
->symbol_table
[namei
];
3494 iter
->vec
= (offset_type
*) (index
->constant_pool
3495 + MAYBE_SWAP (bucket
.vec
));
3496 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3499 /* Return the next matching CU or NULL if there are no more. */
3501 static struct dwarf2_per_cu_data
*
3502 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3504 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3506 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3508 offset_type cu_index_and_attrs
=
3509 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3510 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3511 gdb_index_symbol_kind symbol_kind
=
3512 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3513 /* Only check the symbol attributes if they're present.
3514 Indices prior to version 7 don't record them,
3515 and indices >= 7 may elide them for certain symbols
3516 (gold does this). */
3518 (per_objfile
->per_bfd
->index_table
->version
>= 7
3519 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3521 /* Don't crash on bad data. */
3522 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3523 + per_objfile
->per_bfd
->all_type_units
.size ()))
3525 complaint (_(".gdb_index entry has bad CU index"
3526 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3530 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3532 /* Skip if already read in. */
3533 if (per_objfile
->symtab_set_p (per_cu
))
3536 /* Check static vs global. */
3539 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3541 if (iter
->block_index
.has_value ())
3543 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3545 if (is_static
!= want_static
)
3549 /* Work around gold/15646. */
3551 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3553 if (iter
->global_seen
)
3556 iter
->global_seen
= 1;
3560 /* Only check the symbol's kind if it has one. */
3563 switch (iter
->domain
)
3566 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3567 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3568 /* Some types are also in VAR_DOMAIN. */
3569 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3573 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3577 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3581 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3596 static struct compunit_symtab
*
3597 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3598 const char *name
, domain_enum domain
)
3600 struct compunit_symtab
*stab_best
= NULL
;
3601 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3603 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3605 struct dw2_symtab_iterator iter
;
3606 struct dwarf2_per_cu_data
*per_cu
;
3608 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3610 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3612 struct symbol
*sym
, *with_opaque
= NULL
;
3613 struct compunit_symtab
*stab
3614 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3615 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3616 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3618 sym
= block_find_symbol (block
, name
, domain
,
3619 block_find_non_opaque_type_preferred
,
3622 /* Some caution must be observed with overloaded functions
3623 and methods, since the index will not contain any overload
3624 information (but NAME might contain it). */
3627 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3629 if (with_opaque
!= NULL
3630 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3633 /* Keep looking through other CUs. */
3640 dw2_print_stats (struct objfile
*objfile
)
3642 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3643 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3644 + per_objfile
->per_bfd
->all_type_units
.size ());
3647 for (int i
= 0; i
< total
; ++i
)
3649 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3651 if (!per_objfile
->symtab_set_p (per_cu
))
3654 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3655 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3658 /* This dumps minimal information about the index.
3659 It is called via "mt print objfiles".
3660 One use is to verify .gdb_index has been loaded by the
3661 gdb.dwarf2/gdb-index.exp testcase. */
3664 dw2_dump (struct objfile
*objfile
)
3666 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3668 gdb_assert (per_objfile
->per_bfd
->using_index
);
3669 printf_filtered (".gdb_index:");
3670 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3672 printf_filtered (" version %d\n",
3673 per_objfile
->per_bfd
->index_table
->version
);
3676 printf_filtered (" faked for \"readnow\"\n");
3677 printf_filtered ("\n");
3681 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3682 const char *func_name
)
3684 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3686 struct dw2_symtab_iterator iter
;
3687 struct dwarf2_per_cu_data
*per_cu
;
3689 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3691 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3692 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3697 dw2_expand_all_symtabs (struct objfile
*objfile
)
3699 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3700 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3701 + per_objfile
->per_bfd
->all_type_units
.size ());
3703 for (int i
= 0; i
< total_units
; ++i
)
3705 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3707 /* We don't want to directly expand a partial CU, because if we
3708 read it with the wrong language, then assertion failures can
3709 be triggered later on. See PR symtab/23010. So, tell
3710 dw2_instantiate_symtab to skip partial CUs -- any important
3711 partial CU will be read via DW_TAG_imported_unit anyway. */
3712 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3717 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3718 const char *fullname
)
3720 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3722 /* We don't need to consider type units here.
3723 This is only called for examining code, e.g. expand_line_sal.
3724 There can be an order of magnitude (or more) more type units
3725 than comp units, and we avoid them if we can. */
3727 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3729 /* We only need to look at symtabs not already expanded. */
3730 if (per_objfile
->symtab_set_p (per_cu
))
3733 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3734 if (file_data
== NULL
)
3737 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3739 const char *this_fullname
= file_data
->file_names
[j
];
3741 if (filename_cmp (this_fullname
, fullname
) == 0)
3743 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3751 dw2_expand_symtabs_matching_symbol
3752 (mapped_index_base
&index
,
3753 const lookup_name_info
&lookup_name_in
,
3754 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3755 enum search_domain kind
,
3756 gdb::function_view
<bool (offset_type
)> match_callback
,
3757 dwarf2_per_objfile
*per_objfile
);
3760 dw2_expand_symtabs_matching_one
3761 (dwarf2_per_cu_data
*per_cu
,
3762 dwarf2_per_objfile
*per_objfile
,
3763 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3764 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3767 dw2_map_matching_symbols
3768 (struct objfile
*objfile
,
3769 const lookup_name_info
&name
, domain_enum domain
,
3771 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3772 symbol_compare_ftype
*ordered_compare
)
3775 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3777 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3779 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3781 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3783 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3784 auto matcher
= [&] (const char *symname
)
3786 if (ordered_compare
== nullptr)
3788 return ordered_compare (symname
, match_name
) == 0;
3791 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3792 [&] (offset_type namei
)
3794 struct dw2_symtab_iterator iter
;
3795 struct dwarf2_per_cu_data
*per_cu
;
3797 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3799 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3800 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3807 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3808 proceed assuming all symtabs have been read in. */
3811 for (compunit_symtab
*cust
: objfile
->compunits ())
3813 const struct block
*block
;
3817 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3818 if (!iterate_over_symbols_terminated (block
, name
,
3824 /* Starting from a search name, return the string that finds the upper
3825 bound of all strings that start with SEARCH_NAME in a sorted name
3826 list. Returns the empty string to indicate that the upper bound is
3827 the end of the list. */
3830 make_sort_after_prefix_name (const char *search_name
)
3832 /* When looking to complete "func", we find the upper bound of all
3833 symbols that start with "func" by looking for where we'd insert
3834 the closest string that would follow "func" in lexicographical
3835 order. Usually, that's "func"-with-last-character-incremented,
3836 i.e. "fund". Mind non-ASCII characters, though. Usually those
3837 will be UTF-8 multi-byte sequences, but we can't be certain.
3838 Especially mind the 0xff character, which is a valid character in
3839 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3840 rule out compilers allowing it in identifiers. Note that
3841 conveniently, strcmp/strcasecmp are specified to compare
3842 characters interpreted as unsigned char. So what we do is treat
3843 the whole string as a base 256 number composed of a sequence of
3844 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3845 to 0, and carries 1 to the following more-significant position.
3846 If the very first character in SEARCH_NAME ends up incremented
3847 and carries/overflows, then the upper bound is the end of the
3848 list. The string after the empty string is also the empty
3851 Some examples of this operation:
3853 SEARCH_NAME => "+1" RESULT
3857 "\xff" "a" "\xff" => "\xff" "b"
3862 Then, with these symbols for example:
3868 completing "func" looks for symbols between "func" and
3869 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3870 which finds "func" and "func1", but not "fund".
3874 funcÿ (Latin1 'ÿ' [0xff])
3878 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3879 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3883 ÿÿ (Latin1 'ÿ' [0xff])
3886 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3887 the end of the list.
3889 std::string after
= search_name
;
3890 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3892 if (!after
.empty ())
3893 after
.back () = (unsigned char) after
.back () + 1;
3897 /* See declaration. */
3899 std::pair
<std::vector
<name_component
>::const_iterator
,
3900 std::vector
<name_component
>::const_iterator
>
3901 mapped_index_base::find_name_components_bounds
3902 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3903 dwarf2_per_objfile
*per_objfile
) const
3906 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3908 const char *lang_name
3909 = lookup_name_without_params
.language_lookup_name (lang
);
3911 /* Comparison function object for lower_bound that matches against a
3912 given symbol name. */
3913 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3916 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3917 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3918 return name_cmp (elem_name
, name
) < 0;
3921 /* Comparison function object for upper_bound that matches against a
3922 given symbol name. */
3923 auto lookup_compare_upper
= [&] (const char *name
,
3924 const name_component
&elem
)
3926 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3927 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3928 return name_cmp (name
, elem_name
) < 0;
3931 auto begin
= this->name_components
.begin ();
3932 auto end
= this->name_components
.end ();
3934 /* Find the lower bound. */
3937 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3940 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3943 /* Find the upper bound. */
3946 if (lookup_name_without_params
.completion_mode ())
3948 /* In completion mode, we want UPPER to point past all
3949 symbols names that have the same prefix. I.e., with
3950 these symbols, and completing "func":
3952 function << lower bound
3954 other_function << upper bound
3956 We find the upper bound by looking for the insertion
3957 point of "func"-with-last-character-incremented,
3959 std::string after
= make_sort_after_prefix_name (lang_name
);
3962 return std::lower_bound (lower
, end
, after
.c_str (),
3963 lookup_compare_lower
);
3966 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3969 return {lower
, upper
};
3972 /* See declaration. */
3975 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3977 if (!this->name_components
.empty ())
3980 this->name_components_casing
= case_sensitivity
;
3982 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3984 /* The code below only knows how to break apart components of C++
3985 symbol names (and other languages that use '::' as
3986 namespace/module separator) and Ada symbol names. */
3987 auto count
= this->symbol_name_count ();
3988 for (offset_type idx
= 0; idx
< count
; idx
++)
3990 if (this->symbol_name_slot_invalid (idx
))
3993 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3995 /* Add each name component to the name component table. */
3996 unsigned int previous_len
= 0;
3998 if (strstr (name
, "::") != nullptr)
4000 for (unsigned int current_len
= cp_find_first_component (name
);
4001 name
[current_len
] != '\0';
4002 current_len
+= cp_find_first_component (name
+ current_len
))
4004 gdb_assert (name
[current_len
] == ':');
4005 this->name_components
.push_back ({previous_len
, idx
});
4006 /* Skip the '::'. */
4008 previous_len
= current_len
;
4013 /* Handle the Ada encoded (aka mangled) form here. */
4014 for (const char *iter
= strstr (name
, "__");
4016 iter
= strstr (iter
, "__"))
4018 this->name_components
.push_back ({previous_len
, idx
});
4020 previous_len
= iter
- name
;
4024 this->name_components
.push_back ({previous_len
, idx
});
4027 /* Sort name_components elements by name. */
4028 auto name_comp_compare
= [&] (const name_component
&left
,
4029 const name_component
&right
)
4031 const char *left_qualified
4032 = this->symbol_name_at (left
.idx
, per_objfile
);
4033 const char *right_qualified
4034 = this->symbol_name_at (right
.idx
, per_objfile
);
4036 const char *left_name
= left_qualified
+ left
.name_offset
;
4037 const char *right_name
= right_qualified
+ right
.name_offset
;
4039 return name_cmp (left_name
, right_name
) < 0;
4042 std::sort (this->name_components
.begin (),
4043 this->name_components
.end (),
4047 /* Helper for dw2_expand_symtabs_matching that works with a
4048 mapped_index_base instead of the containing objfile. This is split
4049 to a separate function in order to be able to unit test the
4050 name_components matching using a mock mapped_index_base. For each
4051 symbol name that matches, calls MATCH_CALLBACK, passing it the
4052 symbol's index in the mapped_index_base symbol table. */
4055 dw2_expand_symtabs_matching_symbol
4056 (mapped_index_base
&index
,
4057 const lookup_name_info
&lookup_name_in
,
4058 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4059 enum search_domain kind
,
4060 gdb::function_view
<bool (offset_type
)> match_callback
,
4061 dwarf2_per_objfile
*per_objfile
)
4063 lookup_name_info lookup_name_without_params
4064 = lookup_name_in
.make_ignore_params ();
4066 /* Build the symbol name component sorted vector, if we haven't
4068 index
.build_name_components (per_objfile
);
4070 /* The same symbol may appear more than once in the range though.
4071 E.g., if we're looking for symbols that complete "w", and we have
4072 a symbol named "w1::w2", we'll find the two name components for
4073 that same symbol in the range. To be sure we only call the
4074 callback once per symbol, we first collect the symbol name
4075 indexes that matched in a temporary vector and ignore
4077 std::vector
<offset_type
> matches
;
4079 struct name_and_matcher
4081 symbol_name_matcher_ftype
*matcher
;
4084 bool operator== (const name_and_matcher
&other
) const
4086 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4090 /* A vector holding all the different symbol name matchers, for all
4092 std::vector
<name_and_matcher
> matchers
;
4094 for (int i
= 0; i
< nr_languages
; i
++)
4096 enum language lang_e
= (enum language
) i
;
4098 const language_defn
*lang
= language_def (lang_e
);
4099 symbol_name_matcher_ftype
*name_matcher
4100 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4102 name_and_matcher key
{
4104 lookup_name_without_params
.language_lookup_name (lang_e
)
4107 /* Don't insert the same comparison routine more than once.
4108 Note that we do this linear walk. This is not a problem in
4109 practice because the number of supported languages is
4111 if (std::find (matchers
.begin (), matchers
.end (), key
)
4114 matchers
.push_back (std::move (key
));
4117 = index
.find_name_components_bounds (lookup_name_without_params
,
4118 lang_e
, per_objfile
);
4120 /* Now for each symbol name in range, check to see if we have a name
4121 match, and if so, call the MATCH_CALLBACK callback. */
4123 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4125 const char *qualified
4126 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4128 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4129 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4132 matches
.push_back (bounds
.first
->idx
);
4136 std::sort (matches
.begin (), matches
.end ());
4138 /* Finally call the callback, once per match. */
4140 for (offset_type idx
: matches
)
4144 if (!match_callback (idx
))
4150 /* Above we use a type wider than idx's for 'prev', since 0 and
4151 (offset_type)-1 are both possible values. */
4152 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4157 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4159 /* A mock .gdb_index/.debug_names-like name index table, enough to
4160 exercise dw2_expand_symtabs_matching_symbol, which works with the
4161 mapped_index_base interface. Builds an index from the symbol list
4162 passed as parameter to the constructor. */
4163 class mock_mapped_index
: public mapped_index_base
4166 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4167 : m_symbol_table (symbols
)
4170 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4172 /* Return the number of names in the symbol table. */
4173 size_t symbol_name_count () const override
4175 return m_symbol_table
.size ();
4178 /* Get the name of the symbol at IDX in the symbol table. */
4179 const char *symbol_name_at
4180 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4182 return m_symbol_table
[idx
];
4186 gdb::array_view
<const char *> m_symbol_table
;
4189 /* Convenience function that converts a NULL pointer to a "<null>"
4190 string, to pass to print routines. */
4193 string_or_null (const char *str
)
4195 return str
!= NULL
? str
: "<null>";
4198 /* Check if a lookup_name_info built from
4199 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4200 index. EXPECTED_LIST is the list of expected matches, in expected
4201 matching order. If no match expected, then an empty list is
4202 specified. Returns true on success. On failure prints a warning
4203 indicating the file:line that failed, and returns false. */
4206 check_match (const char *file
, int line
,
4207 mock_mapped_index
&mock_index
,
4208 const char *name
, symbol_name_match_type match_type
,
4209 bool completion_mode
,
4210 std::initializer_list
<const char *> expected_list
,
4211 dwarf2_per_objfile
*per_objfile
)
4213 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4215 bool matched
= true;
4217 auto mismatch
= [&] (const char *expected_str
,
4220 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4221 "expected=\"%s\", got=\"%s\"\n"),
4223 (match_type
== symbol_name_match_type::FULL
4225 name
, string_or_null (expected_str
), string_or_null (got
));
4229 auto expected_it
= expected_list
.begin ();
4230 auto expected_end
= expected_list
.end ();
4232 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4234 [&] (offset_type idx
)
4236 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4237 const char *expected_str
4238 = expected_it
== expected_end
? NULL
: *expected_it
++;
4240 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4241 mismatch (expected_str
, matched_name
);
4245 const char *expected_str
4246 = expected_it
== expected_end
? NULL
: *expected_it
++;
4247 if (expected_str
!= NULL
)
4248 mismatch (expected_str
, NULL
);
4253 /* The symbols added to the mock mapped_index for testing (in
4255 static const char *test_symbols
[] = {
4264 "ns2::tmpl<int>::foo2",
4265 "(anonymous namespace)::A::B::C",
4267 /* These are used to check that the increment-last-char in the
4268 matching algorithm for completion doesn't match "t1_fund" when
4269 completing "t1_func". */
4275 /* A UTF-8 name with multi-byte sequences to make sure that
4276 cp-name-parser understands this as a single identifier ("função"
4277 is "function" in PT). */
4280 /* \377 (0xff) is Latin1 'ÿ'. */
4283 /* \377 (0xff) is Latin1 'ÿ'. */
4287 /* A name with all sorts of complications. Starts with "z" to make
4288 it easier for the completion tests below. */
4289 #define Z_SYM_NAME \
4290 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4291 "::tuple<(anonymous namespace)::ui*, " \
4292 "std::default_delete<(anonymous namespace)::ui>, void>"
4297 /* Returns true if the mapped_index_base::find_name_component_bounds
4298 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4299 in completion mode. */
4302 check_find_bounds_finds (mapped_index_base
&index
,
4303 const char *search_name
,
4304 gdb::array_view
<const char *> expected_syms
,
4305 dwarf2_per_objfile
*per_objfile
)
4307 lookup_name_info
lookup_name (search_name
,
4308 symbol_name_match_type::FULL
, true);
4310 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4314 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4315 if (distance
!= expected_syms
.size ())
4318 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4320 auto nc_elem
= bounds
.first
+ exp_elem
;
4321 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4322 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4329 /* Test the lower-level mapped_index::find_name_component_bounds
4333 test_mapped_index_find_name_component_bounds ()
4335 mock_mapped_index
mock_index (test_symbols
);
4337 mock_index
.build_name_components (NULL
/* per_objfile */);
4339 /* Test the lower-level mapped_index::find_name_component_bounds
4340 method in completion mode. */
4342 static const char *expected_syms
[] = {
4347 SELF_CHECK (check_find_bounds_finds
4348 (mock_index
, "t1_func", expected_syms
,
4349 NULL
/* per_objfile */));
4352 /* Check that the increment-last-char in the name matching algorithm
4353 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4355 static const char *expected_syms1
[] = {
4359 SELF_CHECK (check_find_bounds_finds
4360 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4362 static const char *expected_syms2
[] = {
4365 SELF_CHECK (check_find_bounds_finds
4366 (mock_index
, "\377\377", expected_syms2
,
4367 NULL
/* per_objfile */));
4371 /* Test dw2_expand_symtabs_matching_symbol. */
4374 test_dw2_expand_symtabs_matching_symbol ()
4376 mock_mapped_index
mock_index (test_symbols
);
4378 /* We let all tests run until the end even if some fails, for debug
4380 bool any_mismatch
= false;
4382 /* Create the expected symbols list (an initializer_list). Needed
4383 because lists have commas, and we need to pass them to CHECK,
4384 which is a macro. */
4385 #define EXPECT(...) { __VA_ARGS__ }
4387 /* Wrapper for check_match that passes down the current
4388 __FILE__/__LINE__. */
4389 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4390 any_mismatch |= !check_match (__FILE__, __LINE__, \
4392 NAME, MATCH_TYPE, COMPLETION_MODE, \
4393 EXPECTED_LIST, NULL)
4395 /* Identity checks. */
4396 for (const char *sym
: test_symbols
)
4398 /* Should be able to match all existing symbols. */
4399 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4402 /* Should be able to match all existing symbols with
4404 std::string with_params
= std::string (sym
) + "(int)";
4405 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4408 /* Should be able to match all existing symbols with
4409 parameters and qualifiers. */
4410 with_params
= std::string (sym
) + " ( int ) const";
4411 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4414 /* This should really find sym, but cp-name-parser.y doesn't
4415 know about lvalue/rvalue qualifiers yet. */
4416 with_params
= std::string (sym
) + " ( int ) &&";
4417 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4421 /* Check that the name matching algorithm for completion doesn't get
4422 confused with Latin1 'ÿ' / 0xff. */
4424 static const char str
[] = "\377";
4425 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4426 EXPECT ("\377", "\377\377123"));
4429 /* Check that the increment-last-char in the matching algorithm for
4430 completion doesn't match "t1_fund" when completing "t1_func". */
4432 static const char str
[] = "t1_func";
4433 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4434 EXPECT ("t1_func", "t1_func1"));
4437 /* Check that completion mode works at each prefix of the expected
4440 static const char str
[] = "function(int)";
4441 size_t len
= strlen (str
);
4444 for (size_t i
= 1; i
< len
; i
++)
4446 lookup
.assign (str
, i
);
4447 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4448 EXPECT ("function"));
4452 /* While "w" is a prefix of both components, the match function
4453 should still only be called once. */
4455 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4457 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4461 /* Same, with a "complicated" symbol. */
4463 static const char str
[] = Z_SYM_NAME
;
4464 size_t len
= strlen (str
);
4467 for (size_t i
= 1; i
< len
; i
++)
4469 lookup
.assign (str
, i
);
4470 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4471 EXPECT (Z_SYM_NAME
));
4475 /* In FULL mode, an incomplete symbol doesn't match. */
4477 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4481 /* A complete symbol with parameters matches any overload, since the
4482 index has no overload info. */
4484 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4485 EXPECT ("std::zfunction", "std::zfunction2"));
4486 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4487 EXPECT ("std::zfunction", "std::zfunction2"));
4488 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4489 EXPECT ("std::zfunction", "std::zfunction2"));
4492 /* Check that whitespace is ignored appropriately. A symbol with a
4493 template argument list. */
4495 static const char expected
[] = "ns::foo<int>";
4496 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4498 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4502 /* Check that whitespace is ignored appropriately. A symbol with a
4503 template argument list that includes a pointer. */
4505 static const char expected
[] = "ns::foo<char*>";
4506 /* Try both completion and non-completion modes. */
4507 static const bool completion_mode
[2] = {false, true};
4508 for (size_t i
= 0; i
< 2; i
++)
4510 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4511 completion_mode
[i
], EXPECT (expected
));
4512 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4513 completion_mode
[i
], EXPECT (expected
));
4515 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4516 completion_mode
[i
], EXPECT (expected
));
4517 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4518 completion_mode
[i
], EXPECT (expected
));
4523 /* Check method qualifiers are ignored. */
4524 static const char expected
[] = "ns::foo<char*>";
4525 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4526 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4527 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4528 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4529 CHECK_MATCH ("foo < char * > ( int ) const",
4530 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4531 CHECK_MATCH ("foo < char * > ( int ) &&",
4532 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4535 /* Test lookup names that don't match anything. */
4537 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4540 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4544 /* Some wild matching tests, exercising "(anonymous namespace)",
4545 which should not be confused with a parameter list. */
4547 static const char *syms
[] = {
4551 "A :: B :: C ( int )",
4556 for (const char *s
: syms
)
4558 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4559 EXPECT ("(anonymous namespace)::A::B::C"));
4564 static const char expected
[] = "ns2::tmpl<int>::foo2";
4565 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4567 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4571 SELF_CHECK (!any_mismatch
);
4580 test_mapped_index_find_name_component_bounds ();
4581 test_dw2_expand_symtabs_matching_symbol ();
4584 }} // namespace selftests::dw2_expand_symtabs_matching
4586 #endif /* GDB_SELF_TEST */
4588 /* If FILE_MATCHER is NULL or if PER_CU has
4589 dwarf2_per_cu_quick_data::MARK set (see
4590 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4591 EXPANSION_NOTIFY on it. */
4594 dw2_expand_symtabs_matching_one
4595 (dwarf2_per_cu_data
*per_cu
,
4596 dwarf2_per_objfile
*per_objfile
,
4597 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4598 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4600 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4602 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4604 compunit_symtab
*symtab
4605 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4606 gdb_assert (symtab
!= nullptr);
4608 if (expansion_notify
!= NULL
&& symtab_was_null
)
4609 expansion_notify (symtab
);
4613 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4614 matched, to expand corresponding CUs that were marked. IDX is the
4615 index of the symbol name that matched. */
4618 dw2_expand_marked_cus
4619 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4620 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4621 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4624 offset_type
*vec
, vec_len
, vec_idx
;
4625 bool global_seen
= false;
4626 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4628 vec
= (offset_type
*) (index
.constant_pool
4629 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4630 vec_len
= MAYBE_SWAP (vec
[0]);
4631 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4633 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4634 /* This value is only valid for index versions >= 7. */
4635 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4636 gdb_index_symbol_kind symbol_kind
=
4637 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4638 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4639 /* Only check the symbol attributes if they're present.
4640 Indices prior to version 7 don't record them,
4641 and indices >= 7 may elide them for certain symbols
4642 (gold does this). */
4645 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4647 /* Work around gold/15646. */
4650 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4658 /* Only check the symbol's kind if it has one. */
4663 case VARIABLES_DOMAIN
:
4664 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4667 case FUNCTIONS_DOMAIN
:
4668 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4672 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4675 case MODULES_DOMAIN
:
4676 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4684 /* Don't crash on bad data. */
4685 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4686 + per_objfile
->per_bfd
->all_type_units
.size ()))
4688 complaint (_(".gdb_index entry has bad CU index"
4689 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4693 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4694 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4699 /* If FILE_MATCHER is non-NULL, set all the
4700 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4701 that match FILE_MATCHER. */
4704 dw_expand_symtabs_matching_file_matcher
4705 (dwarf2_per_objfile
*per_objfile
,
4706 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4708 if (file_matcher
== NULL
)
4711 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4713 NULL
, xcalloc
, xfree
));
4714 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4716 NULL
, xcalloc
, xfree
));
4718 /* The rule is CUs specify all the files, including those used by
4719 any TU, so there's no need to scan TUs here. */
4721 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4725 per_cu
->v
.quick
->mark
= 0;
4727 /* We only need to look at symtabs not already expanded. */
4728 if (per_objfile
->symtab_set_p (per_cu
))
4731 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4732 if (file_data
== NULL
)
4735 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4737 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4739 per_cu
->v
.quick
->mark
= 1;
4743 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4745 const char *this_real_name
;
4747 if (file_matcher (file_data
->file_names
[j
], false))
4749 per_cu
->v
.quick
->mark
= 1;
4753 /* Before we invoke realpath, which can get expensive when many
4754 files are involved, do a quick comparison of the basenames. */
4755 if (!basenames_may_differ
4756 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4760 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4761 if (file_matcher (this_real_name
, false))
4763 per_cu
->v
.quick
->mark
= 1;
4768 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4769 ? visited_found
.get ()
4770 : visited_not_found
.get (),
4777 dw2_expand_symtabs_matching
4778 (struct objfile
*objfile
,
4779 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4780 const lookup_name_info
*lookup_name
,
4781 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4782 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4783 enum search_domain kind
)
4785 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4787 /* index_table is NULL if OBJF_READNOW. */
4788 if (!per_objfile
->per_bfd
->index_table
)
4791 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4793 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4795 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4799 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4800 file_matcher
, expansion_notify
);
4805 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4807 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4809 kind
, [&] (offset_type idx
)
4811 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4817 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4820 static struct compunit_symtab
*
4821 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4826 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4827 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4830 if (cust
->includes
== NULL
)
4833 for (i
= 0; cust
->includes
[i
]; ++i
)
4835 struct compunit_symtab
*s
= cust
->includes
[i
];
4837 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4845 static struct compunit_symtab
*
4846 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4847 struct bound_minimal_symbol msymbol
,
4849 struct obj_section
*section
,
4852 struct dwarf2_per_cu_data
*data
;
4853 struct compunit_symtab
*result
;
4855 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4858 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4859 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4860 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4864 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4865 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4866 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4867 paddress (objfile
->arch (), pc
));
4869 result
= recursively_find_pc_sect_compunit_symtab
4870 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4872 gdb_assert (result
!= NULL
);
4877 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4878 void *data
, int need_fullname
)
4880 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4882 if (!per_objfile
->per_bfd
->filenames_cache
)
4884 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4886 htab_up
visited (htab_create_alloc (10,
4887 htab_hash_pointer
, htab_eq_pointer
,
4888 NULL
, xcalloc
, xfree
));
4890 /* The rule is CUs specify all the files, including those used
4891 by any TU, so there's no need to scan TUs here. We can
4892 ignore file names coming from already-expanded CUs. */
4894 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4896 if (per_objfile
->symtab_set_p (per_cu
))
4898 void **slot
= htab_find_slot (visited
.get (),
4899 per_cu
->v
.quick
->file_names
,
4902 *slot
= per_cu
->v
.quick
->file_names
;
4906 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4908 /* We only need to look at symtabs not already expanded. */
4909 if (per_objfile
->symtab_set_p (per_cu
))
4912 quick_file_names
*file_data
4913 = dw2_get_file_names (per_cu
, per_objfile
);
4914 if (file_data
== NULL
)
4917 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4920 /* Already visited. */
4925 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4927 const char *filename
= file_data
->file_names
[j
];
4928 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4933 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4935 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4938 this_real_name
= gdb_realpath (filename
);
4939 (*fun
) (filename
, this_real_name
.get (), data
);
4944 dw2_has_symbols (struct objfile
*objfile
)
4949 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4952 dw2_find_last_source_symtab
,
4953 dw2_forget_cached_source_info
,
4954 dw2_map_symtabs_matching_filename
,
4959 dw2_expand_symtabs_for_function
,
4960 dw2_expand_all_symtabs
,
4961 dw2_expand_symtabs_with_fullname
,
4962 dw2_map_matching_symbols
,
4963 dw2_expand_symtabs_matching
,
4964 dw2_find_pc_sect_compunit_symtab
,
4966 dw2_map_symbol_filenames
4969 /* DWARF-5 debug_names reader. */
4971 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4972 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4974 /* A helper function that reads the .debug_names section in SECTION
4975 and fills in MAP. FILENAME is the name of the file containing the
4976 section; it is used for error reporting.
4978 Returns true if all went well, false otherwise. */
4981 read_debug_names_from_section (struct objfile
*objfile
,
4982 const char *filename
,
4983 struct dwarf2_section_info
*section
,
4984 mapped_debug_names
&map
)
4986 if (section
->empty ())
4989 /* Older elfutils strip versions could keep the section in the main
4990 executable while splitting it for the separate debug info file. */
4991 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4994 section
->read (objfile
);
4996 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4998 const gdb_byte
*addr
= section
->buffer
;
5000 bfd
*const abfd
= section
->get_bfd_owner ();
5002 unsigned int bytes_read
;
5003 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5006 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5007 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5008 if (bytes_read
+ length
!= section
->size
)
5010 /* There may be multiple per-CU indices. */
5011 warning (_("Section .debug_names in %s length %s does not match "
5012 "section length %s, ignoring .debug_names."),
5013 filename
, plongest (bytes_read
+ length
),
5014 pulongest (section
->size
));
5018 /* The version number. */
5019 uint16_t version
= read_2_bytes (abfd
, addr
);
5023 warning (_("Section .debug_names in %s has unsupported version %d, "
5024 "ignoring .debug_names."),
5030 uint16_t padding
= read_2_bytes (abfd
, addr
);
5034 warning (_("Section .debug_names in %s has unsupported padding %d, "
5035 "ignoring .debug_names."),
5040 /* comp_unit_count - The number of CUs in the CU list. */
5041 map
.cu_count
= read_4_bytes (abfd
, addr
);
5044 /* local_type_unit_count - The number of TUs in the local TU
5046 map
.tu_count
= read_4_bytes (abfd
, addr
);
5049 /* foreign_type_unit_count - The number of TUs in the foreign TU
5051 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5053 if (foreign_tu_count
!= 0)
5055 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5056 "ignoring .debug_names."),
5057 filename
, static_cast<unsigned long> (foreign_tu_count
));
5061 /* bucket_count - The number of hash buckets in the hash lookup
5063 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5066 /* name_count - The number of unique names in the index. */
5067 map
.name_count
= read_4_bytes (abfd
, addr
);
5070 /* abbrev_table_size - The size in bytes of the abbreviations
5072 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5075 /* augmentation_string_size - The size in bytes of the augmentation
5076 string. This value is rounded up to a multiple of 4. */
5077 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5079 map
.augmentation_is_gdb
= ((augmentation_string_size
5080 == sizeof (dwarf5_augmentation
))
5081 && memcmp (addr
, dwarf5_augmentation
,
5082 sizeof (dwarf5_augmentation
)) == 0);
5083 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5084 addr
+= augmentation_string_size
;
5087 map
.cu_table_reordered
= addr
;
5088 addr
+= map
.cu_count
* map
.offset_size
;
5090 /* List of Local TUs */
5091 map
.tu_table_reordered
= addr
;
5092 addr
+= map
.tu_count
* map
.offset_size
;
5094 /* Hash Lookup Table */
5095 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5096 addr
+= map
.bucket_count
* 4;
5097 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5098 addr
+= map
.name_count
* 4;
5101 map
.name_table_string_offs_reordered
= addr
;
5102 addr
+= map
.name_count
* map
.offset_size
;
5103 map
.name_table_entry_offs_reordered
= addr
;
5104 addr
+= map
.name_count
* map
.offset_size
;
5106 const gdb_byte
*abbrev_table_start
= addr
;
5109 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5114 const auto insertpair
5115 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5116 if (!insertpair
.second
)
5118 warning (_("Section .debug_names in %s has duplicate index %s, "
5119 "ignoring .debug_names."),
5120 filename
, pulongest (index_num
));
5123 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5124 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5129 mapped_debug_names::index_val::attr attr
;
5130 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5132 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5134 if (attr
.form
== DW_FORM_implicit_const
)
5136 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5140 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5142 indexval
.attr_vec
.push_back (std::move (attr
));
5145 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5147 warning (_("Section .debug_names in %s has abbreviation_table "
5148 "of size %s vs. written as %u, ignoring .debug_names."),
5149 filename
, plongest (addr
- abbrev_table_start
),
5153 map
.entry_pool
= addr
;
5158 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5162 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5163 const mapped_debug_names
&map
,
5164 dwarf2_section_info
§ion
,
5167 if (!map
.augmentation_is_gdb
)
5169 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5171 sect_offset sect_off
5172 = (sect_offset
) (extract_unsigned_integer
5173 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5175 map
.dwarf5_byte_order
));
5176 /* We don't know the length of the CU, because the CU list in a
5177 .debug_names index can be incomplete, so we can't use the start of
5178 the next CU as end of this CU. We create the CUs here with length 0,
5179 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5180 dwarf2_per_cu_data
*per_cu
5181 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5182 per_bfd
->all_comp_units
.push_back (per_cu
);
5186 sect_offset sect_off_prev
;
5187 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5189 sect_offset sect_off_next
;
5190 if (i
< map
.cu_count
)
5193 = (sect_offset
) (extract_unsigned_integer
5194 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5196 map
.dwarf5_byte_order
));
5199 sect_off_next
= (sect_offset
) section
.size
;
5202 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5203 dwarf2_per_cu_data
*per_cu
5204 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5205 sect_off_prev
, length
);
5206 per_bfd
->all_comp_units
.push_back (per_cu
);
5208 sect_off_prev
= sect_off_next
;
5212 /* Read the CU list from the mapped index, and use it to create all
5213 the CU objects for this dwarf2_per_objfile. */
5216 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5217 const mapped_debug_names
&map
,
5218 const mapped_debug_names
&dwz_map
)
5220 gdb_assert (per_bfd
->all_comp_units
.empty ());
5221 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5223 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5224 false /* is_dwz */);
5226 if (dwz_map
.cu_count
== 0)
5229 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5230 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5234 /* Read .debug_names. If everything went ok, initialize the "quick"
5235 elements of all the CUs and return true. Otherwise, return false. */
5238 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5240 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5241 mapped_debug_names dwz_map
;
5242 struct objfile
*objfile
= per_objfile
->objfile
;
5243 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5245 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5246 &per_objfile
->per_bfd
->debug_names
, *map
))
5249 /* Don't use the index if it's empty. */
5250 if (map
->name_count
== 0)
5253 /* If there is a .dwz file, read it so we can get its CU list as
5255 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5258 if (!read_debug_names_from_section (objfile
,
5259 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5260 &dwz
->debug_names
, dwz_map
))
5262 warning (_("could not read '.debug_names' section from %s; skipping"),
5263 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5268 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5270 if (map
->tu_count
!= 0)
5272 /* We can only handle a single .debug_types when we have an
5274 if (per_bfd
->types
.size () != 1)
5277 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5279 create_signatured_type_table_from_debug_names
5280 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5283 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5285 per_bfd
->debug_names_table
= std::move (map
);
5286 per_bfd
->using_index
= 1;
5287 per_bfd
->quick_file_names_table
=
5288 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5290 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5291 objfiles using the same BFD. */
5292 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5293 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5298 /* Type used to manage iterating over all CUs looking for a symbol for
5301 class dw2_debug_names_iterator
5304 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5305 gdb::optional
<block_enum
> block_index
,
5307 const char *name
, dwarf2_per_objfile
*per_objfile
)
5308 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5309 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5310 m_per_objfile (per_objfile
)
5313 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5314 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5317 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5318 m_per_objfile (per_objfile
)
5321 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5322 block_enum block_index
, domain_enum domain
,
5323 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5324 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5325 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5326 m_per_objfile (per_objfile
)
5329 /* Return the next matching CU or NULL if there are no more. */
5330 dwarf2_per_cu_data
*next ();
5333 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5335 dwarf2_per_objfile
*per_objfile
);
5336 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5338 dwarf2_per_objfile
*per_objfile
);
5340 /* The internalized form of .debug_names. */
5341 const mapped_debug_names
&m_map
;
5343 /* If set, only look for symbols that match that block. Valid values are
5344 GLOBAL_BLOCK and STATIC_BLOCK. */
5345 const gdb::optional
<block_enum
> m_block_index
;
5347 /* The kind of symbol we're looking for. */
5348 const domain_enum m_domain
= UNDEF_DOMAIN
;
5349 const search_domain m_search
= ALL_DOMAIN
;
5351 /* The list of CUs from the index entry of the symbol, or NULL if
5353 const gdb_byte
*m_addr
;
5355 dwarf2_per_objfile
*m_per_objfile
;
5359 mapped_debug_names::namei_to_name
5360 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5362 const ULONGEST namei_string_offs
5363 = extract_unsigned_integer ((name_table_string_offs_reordered
5364 + namei
* offset_size
),
5367 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5370 /* Find a slot in .debug_names for the object named NAME. If NAME is
5371 found, return pointer to its pool data. If NAME cannot be found,
5375 dw2_debug_names_iterator::find_vec_in_debug_names
5376 (const mapped_debug_names
&map
, const char *name
,
5377 dwarf2_per_objfile
*per_objfile
)
5379 int (*cmp
) (const char *, const char *);
5381 gdb::unique_xmalloc_ptr
<char> without_params
;
5382 if (current_language
->la_language
== language_cplus
5383 || current_language
->la_language
== language_fortran
5384 || current_language
->la_language
== language_d
)
5386 /* NAME is already canonical. Drop any qualifiers as
5387 .debug_names does not contain any. */
5389 if (strchr (name
, '(') != NULL
)
5391 without_params
= cp_remove_params (name
);
5392 if (without_params
!= NULL
)
5393 name
= without_params
.get ();
5397 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5399 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5401 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5402 (map
.bucket_table_reordered
5403 + (full_hash
% map
.bucket_count
)), 4,
5404 map
.dwarf5_byte_order
);
5408 if (namei
>= map
.name_count
)
5410 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5412 namei
, map
.name_count
,
5413 objfile_name (per_objfile
->objfile
));
5419 const uint32_t namei_full_hash
5420 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5421 (map
.hash_table_reordered
+ namei
), 4,
5422 map
.dwarf5_byte_order
);
5423 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5426 if (full_hash
== namei_full_hash
)
5428 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5430 #if 0 /* An expensive sanity check. */
5431 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5433 complaint (_("Wrong .debug_names hash for string at index %u "
5435 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5440 if (cmp (namei_string
, name
) == 0)
5442 const ULONGEST namei_entry_offs
5443 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5444 + namei
* map
.offset_size
),
5445 map
.offset_size
, map
.dwarf5_byte_order
);
5446 return map
.entry_pool
+ namei_entry_offs
;
5451 if (namei
>= map
.name_count
)
5457 dw2_debug_names_iterator::find_vec_in_debug_names
5458 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5460 if (namei
>= map
.name_count
)
5462 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5464 namei
, map
.name_count
,
5465 objfile_name (per_objfile
->objfile
));
5469 const ULONGEST namei_entry_offs
5470 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5471 + namei
* map
.offset_size
),
5472 map
.offset_size
, map
.dwarf5_byte_order
);
5473 return map
.entry_pool
+ namei_entry_offs
;
5476 /* See dw2_debug_names_iterator. */
5478 dwarf2_per_cu_data
*
5479 dw2_debug_names_iterator::next ()
5484 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5485 struct objfile
*objfile
= m_per_objfile
->objfile
;
5486 bfd
*const abfd
= objfile
->obfd
;
5490 unsigned int bytes_read
;
5491 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5492 m_addr
+= bytes_read
;
5496 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5497 if (indexval_it
== m_map
.abbrev_map
.cend ())
5499 complaint (_("Wrong .debug_names undefined abbrev code %s "
5501 pulongest (abbrev
), objfile_name (objfile
));
5504 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5505 enum class symbol_linkage
{
5509 } symbol_linkage_
= symbol_linkage::unknown
;
5510 dwarf2_per_cu_data
*per_cu
= NULL
;
5511 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5516 case DW_FORM_implicit_const
:
5517 ull
= attr
.implicit_const
;
5519 case DW_FORM_flag_present
:
5523 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5524 m_addr
+= bytes_read
;
5527 ull
= read_4_bytes (abfd
, m_addr
);
5531 ull
= read_8_bytes (abfd
, m_addr
);
5534 case DW_FORM_ref_sig8
:
5535 ull
= read_8_bytes (abfd
, m_addr
);
5539 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5540 dwarf_form_name (attr
.form
),
5541 objfile_name (objfile
));
5544 switch (attr
.dw_idx
)
5546 case DW_IDX_compile_unit
:
5547 /* Don't crash on bad data. */
5548 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5550 complaint (_(".debug_names entry has bad CU index %s"
5553 objfile_name (objfile
));
5556 per_cu
= per_bfd
->get_cutu (ull
);
5558 case DW_IDX_type_unit
:
5559 /* Don't crash on bad data. */
5560 if (ull
>= per_bfd
->all_type_units
.size ())
5562 complaint (_(".debug_names entry has bad TU index %s"
5565 objfile_name (objfile
));
5568 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5570 case DW_IDX_die_offset
:
5571 /* In a per-CU index (as opposed to a per-module index), index
5572 entries without CU attribute implicitly refer to the single CU. */
5574 per_cu
= per_bfd
->get_cu (0);
5576 case DW_IDX_GNU_internal
:
5577 if (!m_map
.augmentation_is_gdb
)
5579 symbol_linkage_
= symbol_linkage::static_
;
5581 case DW_IDX_GNU_external
:
5582 if (!m_map
.augmentation_is_gdb
)
5584 symbol_linkage_
= symbol_linkage::extern_
;
5589 /* Skip if already read in. */
5590 if (m_per_objfile
->symtab_set_p (per_cu
))
5593 /* Check static vs global. */
5594 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5596 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5597 const bool symbol_is_static
=
5598 symbol_linkage_
== symbol_linkage::static_
;
5599 if (want_static
!= symbol_is_static
)
5603 /* Match dw2_symtab_iter_next, symbol_kind
5604 and debug_names::psymbol_tag. */
5608 switch (indexval
.dwarf_tag
)
5610 case DW_TAG_variable
:
5611 case DW_TAG_subprogram
:
5612 /* Some types are also in VAR_DOMAIN. */
5613 case DW_TAG_typedef
:
5614 case DW_TAG_structure_type
:
5621 switch (indexval
.dwarf_tag
)
5623 case DW_TAG_typedef
:
5624 case DW_TAG_structure_type
:
5631 switch (indexval
.dwarf_tag
)
5634 case DW_TAG_variable
:
5641 switch (indexval
.dwarf_tag
)
5653 /* Match dw2_expand_symtabs_matching, symbol_kind and
5654 debug_names::psymbol_tag. */
5657 case VARIABLES_DOMAIN
:
5658 switch (indexval
.dwarf_tag
)
5660 case DW_TAG_variable
:
5666 case FUNCTIONS_DOMAIN
:
5667 switch (indexval
.dwarf_tag
)
5669 case DW_TAG_subprogram
:
5676 switch (indexval
.dwarf_tag
)
5678 case DW_TAG_typedef
:
5679 case DW_TAG_structure_type
:
5685 case MODULES_DOMAIN
:
5686 switch (indexval
.dwarf_tag
)
5700 static struct compunit_symtab
*
5701 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5702 const char *name
, domain_enum domain
)
5704 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5706 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5709 /* index is NULL if OBJF_READNOW. */
5712 const auto &map
= *mapp
;
5714 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5716 struct compunit_symtab
*stab_best
= NULL
;
5717 struct dwarf2_per_cu_data
*per_cu
;
5718 while ((per_cu
= iter
.next ()) != NULL
)
5720 struct symbol
*sym
, *with_opaque
= NULL
;
5721 compunit_symtab
*stab
5722 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5723 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5724 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5726 sym
= block_find_symbol (block
, name
, domain
,
5727 block_find_non_opaque_type_preferred
,
5730 /* Some caution must be observed with overloaded functions and
5731 methods, since the index will not contain any overload
5732 information (but NAME might contain it). */
5735 && strcmp_iw (sym
->search_name (), name
) == 0)
5737 if (with_opaque
!= NULL
5738 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5741 /* Keep looking through other CUs. */
5747 /* This dumps minimal information about .debug_names. It is called
5748 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5749 uses this to verify that .debug_names has been loaded. */
5752 dw2_debug_names_dump (struct objfile
*objfile
)
5754 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5756 gdb_assert (per_objfile
->per_bfd
->using_index
);
5757 printf_filtered (".debug_names:");
5758 if (per_objfile
->per_bfd
->debug_names_table
)
5759 printf_filtered (" exists\n");
5761 printf_filtered (" faked for \"readnow\"\n");
5762 printf_filtered ("\n");
5766 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5767 const char *func_name
)
5769 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5771 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5772 if (per_objfile
->per_bfd
->debug_names_table
)
5774 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5776 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5779 struct dwarf2_per_cu_data
*per_cu
;
5780 while ((per_cu
= iter
.next ()) != NULL
)
5781 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5786 dw2_debug_names_map_matching_symbols
5787 (struct objfile
*objfile
,
5788 const lookup_name_info
&name
, domain_enum domain
,
5790 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5791 symbol_compare_ftype
*ordered_compare
)
5793 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5795 /* debug_names_table is NULL if OBJF_READNOW. */
5796 if (!per_objfile
->per_bfd
->debug_names_table
)
5799 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5800 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5802 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5803 auto matcher
= [&] (const char *symname
)
5805 if (ordered_compare
== nullptr)
5807 return ordered_compare (symname
, match_name
) == 0;
5810 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5811 [&] (offset_type namei
)
5813 /* The name was matched, now expand corresponding CUs that were
5815 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5818 struct dwarf2_per_cu_data
*per_cu
;
5819 while ((per_cu
= iter
.next ()) != NULL
)
5820 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5825 /* It's a shame we couldn't do this inside the
5826 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5827 that have already been expanded. Instead, this loop matches what
5828 the psymtab code does. */
5829 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5831 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5832 if (symtab
!= nullptr)
5834 const struct block
*block
5835 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5836 if (!iterate_over_symbols_terminated (block
, name
,
5844 dw2_debug_names_expand_symtabs_matching
5845 (struct objfile
*objfile
,
5846 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5847 const lookup_name_info
*lookup_name
,
5848 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5849 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5850 enum search_domain kind
)
5852 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5854 /* debug_names_table is NULL if OBJF_READNOW. */
5855 if (!per_objfile
->per_bfd
->debug_names_table
)
5858 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5860 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5862 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5866 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5872 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5874 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5876 kind
, [&] (offset_type namei
)
5878 /* The name was matched, now expand corresponding CUs that were
5880 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5882 struct dwarf2_per_cu_data
*per_cu
;
5883 while ((per_cu
= iter
.next ()) != NULL
)
5884 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5890 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5893 dw2_find_last_source_symtab
,
5894 dw2_forget_cached_source_info
,
5895 dw2_map_symtabs_matching_filename
,
5896 dw2_debug_names_lookup_symbol
,
5899 dw2_debug_names_dump
,
5900 dw2_debug_names_expand_symtabs_for_function
,
5901 dw2_expand_all_symtabs
,
5902 dw2_expand_symtabs_with_fullname
,
5903 dw2_debug_names_map_matching_symbols
,
5904 dw2_debug_names_expand_symtabs_matching
,
5905 dw2_find_pc_sect_compunit_symtab
,
5907 dw2_map_symbol_filenames
5910 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5911 to either a dwarf2_per_bfd or dwz_file object. */
5913 template <typename T
>
5914 static gdb::array_view
<const gdb_byte
>
5915 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5917 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5919 if (section
->empty ())
5922 /* Older elfutils strip versions could keep the section in the main
5923 executable while splitting it for the separate debug info file. */
5924 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5927 section
->read (obj
);
5929 /* dwarf2_section_info::size is a bfd_size_type, while
5930 gdb::array_view works with size_t. On 32-bit hosts, with
5931 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5932 is 32-bit. So we need an explicit narrowing conversion here.
5933 This is fine, because it's impossible to allocate or mmap an
5934 array/buffer larger than what size_t can represent. */
5935 return gdb::make_array_view (section
->buffer
, section
->size
);
5938 /* Lookup the index cache for the contents of the index associated to
5941 static gdb::array_view
<const gdb_byte
>
5942 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5944 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5945 if (build_id
== nullptr)
5948 return global_index_cache
.lookup_gdb_index (build_id
,
5949 &dwarf2_per_bfd
->index_cache_res
);
5952 /* Same as the above, but for DWZ. */
5954 static gdb::array_view
<const gdb_byte
>
5955 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5957 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5958 if (build_id
== nullptr)
5961 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5964 /* See symfile.h. */
5967 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5969 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5970 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5972 /* If we're about to read full symbols, don't bother with the
5973 indices. In this case we also don't care if some other debug
5974 format is making psymtabs, because they are all about to be
5976 if ((objfile
->flags
& OBJF_READNOW
))
5978 /* When using READNOW, the using_index flag (set below) indicates that
5979 PER_BFD was already initialized, when we loaded some other objfile. */
5980 if (per_bfd
->using_index
)
5982 *index_kind
= dw_index_kind::GDB_INDEX
;
5983 per_objfile
->resize_symtabs ();
5987 per_bfd
->using_index
= 1;
5988 create_all_comp_units (per_objfile
);
5989 create_all_type_units (per_objfile
);
5990 per_bfd
->quick_file_names_table
5991 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5992 per_objfile
->resize_symtabs ();
5994 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5995 + per_bfd
->all_type_units
.size ()); ++i
)
5997 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5999 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6000 struct dwarf2_per_cu_quick_data
);
6003 /* Return 1 so that gdb sees the "quick" functions. However,
6004 these functions will be no-ops because we will have expanded
6006 *index_kind
= dw_index_kind::GDB_INDEX
;
6010 /* Was a debug names index already read when we processed an objfile sharing
6012 if (per_bfd
->debug_names_table
!= nullptr)
6014 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6015 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6016 per_objfile
->resize_symtabs ();
6020 /* Was a GDB index already read when we processed an objfile sharing
6022 if (per_bfd
->index_table
!= nullptr)
6024 *index_kind
= dw_index_kind::GDB_INDEX
;
6025 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6026 per_objfile
->resize_symtabs ();
6030 /* There might already be partial symtabs built for this BFD. This happens
6031 when loading the same binary twice with the index-cache enabled. If so,
6032 don't try to read an index. The objfile / per_objfile initialization will
6033 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6035 if (per_bfd
->partial_symtabs
!= nullptr)
6038 if (dwarf2_read_debug_names (per_objfile
))
6040 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6041 per_objfile
->resize_symtabs ();
6045 if (dwarf2_read_gdb_index (per_objfile
,
6046 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6047 get_gdb_index_contents_from_section
<dwz_file
>))
6049 *index_kind
= dw_index_kind::GDB_INDEX
;
6050 per_objfile
->resize_symtabs ();
6054 /* ... otherwise, try to find the index in the index cache. */
6055 if (dwarf2_read_gdb_index (per_objfile
,
6056 get_gdb_index_contents_from_cache
,
6057 get_gdb_index_contents_from_cache_dwz
))
6059 global_index_cache
.hit ();
6060 *index_kind
= dw_index_kind::GDB_INDEX
;
6061 per_objfile
->resize_symtabs ();
6065 global_index_cache
.miss ();
6071 /* Build a partial symbol table. */
6074 dwarf2_build_psymtabs (struct objfile
*objfile
)
6076 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6077 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6079 if (per_bfd
->partial_symtabs
!= nullptr)
6081 /* Partial symbols were already read, so now we can simply
6083 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6084 per_objfile
->resize_symtabs ();
6088 init_psymbol_list (objfile
, 1024);
6092 /* This isn't really ideal: all the data we allocate on the
6093 objfile's obstack is still uselessly kept around. However,
6094 freeing it seems unsafe. */
6095 psymtab_discarder
psymtabs (objfile
);
6096 dwarf2_build_psymtabs_hard (per_objfile
);
6099 per_objfile
->resize_symtabs ();
6101 /* (maybe) store an index in the cache. */
6102 global_index_cache
.store (per_objfile
);
6104 catch (const gdb_exception_error
&except
)
6106 exception_print (gdb_stderr
, except
);
6109 /* Finish by setting the local reference to partial symtabs, so that
6110 we don't try to read them again if reading another objfile with the same
6111 BFD. If we can't in fact share, this won't make a difference anyway as
6112 the dwarf2_per_bfd object won't be shared. */
6113 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6116 /* Find the base address of the compilation unit for range lists and
6117 location lists. It will normally be specified by DW_AT_low_pc.
6118 In DWARF-3 draft 4, the base address could be overridden by
6119 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6120 compilation units with discontinuous ranges. */
6123 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6125 struct attribute
*attr
;
6127 cu
->base_address
.reset ();
6129 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6130 if (attr
!= nullptr)
6131 cu
->base_address
= attr
->value_as_address ();
6134 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6135 if (attr
!= nullptr)
6136 cu
->base_address
= attr
->value_as_address ();
6140 /* Helper function that returns the proper abbrev section for
6143 static struct dwarf2_section_info
*
6144 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6146 struct dwarf2_section_info
*abbrev
;
6147 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6149 if (this_cu
->is_dwz
)
6150 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6152 abbrev
= &per_bfd
->abbrev
;
6157 /* Fetch the abbreviation table offset from a comp or type unit header. */
6160 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6161 struct dwarf2_section_info
*section
,
6162 sect_offset sect_off
)
6164 bfd
*abfd
= section
->get_bfd_owner ();
6165 const gdb_byte
*info_ptr
;
6166 unsigned int initial_length_size
, offset_size
;
6169 section
->read (per_objfile
->objfile
);
6170 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6171 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6172 offset_size
= initial_length_size
== 4 ? 4 : 8;
6173 info_ptr
+= initial_length_size
;
6175 version
= read_2_bytes (abfd
, info_ptr
);
6179 /* Skip unit type and address size. */
6183 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6186 /* A partial symtab that is used only for include files. */
6187 struct dwarf2_include_psymtab
: public partial_symtab
6189 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6190 : partial_symtab (filename
, objfile
)
6194 void read_symtab (struct objfile
*objfile
) override
6196 /* It's an include file, no symbols to read for it.
6197 Everything is in the includer symtab. */
6199 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6200 expansion of the includer psymtab. We use the dependencies[0] field to
6201 model the includer. But if we go the regular route of calling
6202 expand_psymtab here, and having expand_psymtab call expand_dependencies
6203 to expand the includer, we'll only use expand_psymtab on the includer
6204 (making it a non-toplevel psymtab), while if we expand the includer via
6205 another path, we'll use read_symtab (making it a toplevel psymtab).
6206 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6207 psymtab, and trigger read_symtab on the includer here directly. */
6208 includer ()->read_symtab (objfile
);
6211 void expand_psymtab (struct objfile
*objfile
) override
6213 /* This is not called by read_symtab, and should not be called by any
6214 expand_dependencies. */
6218 bool readin_p (struct objfile
*objfile
) const override
6220 return includer ()->readin_p (objfile
);
6223 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6229 partial_symtab
*includer () const
6231 /* An include psymtab has exactly one dependency: the psymtab that
6233 gdb_assert (this->number_of_dependencies
== 1);
6234 return this->dependencies
[0];
6238 /* Allocate a new partial symtab for file named NAME and mark this new
6239 partial symtab as being an include of PST. */
6242 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6243 struct objfile
*objfile
)
6245 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6247 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6248 subpst
->dirname
= pst
->dirname
;
6250 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6251 subpst
->dependencies
[0] = pst
;
6252 subpst
->number_of_dependencies
= 1;
6255 /* Read the Line Number Program data and extract the list of files
6256 included by the source file represented by PST. Build an include
6257 partial symtab for each of these included files. */
6260 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6261 struct die_info
*die
,
6262 dwarf2_psymtab
*pst
)
6265 struct attribute
*attr
;
6267 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6268 if (attr
!= nullptr)
6269 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6271 return; /* No linetable, so no includes. */
6273 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6274 that we pass in the raw text_low here; that is ok because we're
6275 only decoding the line table to make include partial symtabs, and
6276 so the addresses aren't really used. */
6277 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6278 pst
->raw_text_low (), 1);
6282 hash_signatured_type (const void *item
)
6284 const struct signatured_type
*sig_type
6285 = (const struct signatured_type
*) item
;
6287 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6288 return sig_type
->signature
;
6292 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6294 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6295 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6297 return lhs
->signature
== rhs
->signature
;
6300 /* Allocate a hash table for signatured types. */
6303 allocate_signatured_type_table ()
6305 return htab_up (htab_create_alloc (41,
6306 hash_signatured_type
,
6308 NULL
, xcalloc
, xfree
));
6311 /* A helper function to add a signatured type CU to a table. */
6314 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6316 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6317 std::vector
<signatured_type
*> *all_type_units
6318 = (std::vector
<signatured_type
*> *) datum
;
6320 all_type_units
->push_back (sigt
);
6325 /* A helper for create_debug_types_hash_table. Read types from SECTION
6326 and fill them into TYPES_HTAB. It will process only type units,
6327 therefore DW_UT_type. */
6330 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6331 struct dwo_file
*dwo_file
,
6332 dwarf2_section_info
*section
, htab_up
&types_htab
,
6333 rcuh_kind section_kind
)
6335 struct objfile
*objfile
= per_objfile
->objfile
;
6336 struct dwarf2_section_info
*abbrev_section
;
6338 const gdb_byte
*info_ptr
, *end_ptr
;
6340 abbrev_section
= (dwo_file
!= NULL
6341 ? &dwo_file
->sections
.abbrev
6342 : &per_objfile
->per_bfd
->abbrev
);
6344 if (dwarf_read_debug
)
6345 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6346 section
->get_name (),
6347 abbrev_section
->get_file_name ());
6349 section
->read (objfile
);
6350 info_ptr
= section
->buffer
;
6352 if (info_ptr
== NULL
)
6355 /* We can't set abfd until now because the section may be empty or
6356 not present, in which case the bfd is unknown. */
6357 abfd
= section
->get_bfd_owner ();
6359 /* We don't use cutu_reader here because we don't need to read
6360 any dies: the signature is in the header. */
6362 end_ptr
= info_ptr
+ section
->size
;
6363 while (info_ptr
< end_ptr
)
6365 struct signatured_type
*sig_type
;
6366 struct dwo_unit
*dwo_tu
;
6368 const gdb_byte
*ptr
= info_ptr
;
6369 struct comp_unit_head header
;
6370 unsigned int length
;
6372 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6374 /* Initialize it due to a false compiler warning. */
6375 header
.signature
= -1;
6376 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6378 /* We need to read the type's signature in order to build the hash
6379 table, but we don't need anything else just yet. */
6381 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6382 abbrev_section
, ptr
, section_kind
);
6384 length
= header
.get_length ();
6386 /* Skip dummy type units. */
6387 if (ptr
>= info_ptr
+ length
6388 || peek_abbrev_code (abfd
, ptr
) == 0
6389 || header
.unit_type
!= DW_UT_type
)
6395 if (types_htab
== NULL
)
6398 types_htab
= allocate_dwo_unit_table ();
6400 types_htab
= allocate_signatured_type_table ();
6406 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6407 dwo_tu
->dwo_file
= dwo_file
;
6408 dwo_tu
->signature
= header
.signature
;
6409 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6410 dwo_tu
->section
= section
;
6411 dwo_tu
->sect_off
= sect_off
;
6412 dwo_tu
->length
= length
;
6416 /* N.B.: type_offset is not usable if this type uses a DWO file.
6417 The real type_offset is in the DWO file. */
6419 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6420 sig_type
->signature
= header
.signature
;
6421 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6422 sig_type
->per_cu
.is_debug_types
= 1;
6423 sig_type
->per_cu
.section
= section
;
6424 sig_type
->per_cu
.sect_off
= sect_off
;
6425 sig_type
->per_cu
.length
= length
;
6428 slot
= htab_find_slot (types_htab
.get (),
6429 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6431 gdb_assert (slot
!= NULL
);
6434 sect_offset dup_sect_off
;
6438 const struct dwo_unit
*dup_tu
6439 = (const struct dwo_unit
*) *slot
;
6441 dup_sect_off
= dup_tu
->sect_off
;
6445 const struct signatured_type
*dup_tu
6446 = (const struct signatured_type
*) *slot
;
6448 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6451 complaint (_("debug type entry at offset %s is duplicate to"
6452 " the entry at offset %s, signature %s"),
6453 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6454 hex_string (header
.signature
));
6456 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6458 if (dwarf_read_debug
> 1)
6459 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6460 sect_offset_str (sect_off
),
6461 hex_string (header
.signature
));
6467 /* Create the hash table of all entries in the .debug_types
6468 (or .debug_types.dwo) section(s).
6469 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6470 otherwise it is NULL.
6472 The result is a pointer to the hash table or NULL if there are no types.
6474 Note: This function processes DWO files only, not DWP files. */
6477 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6478 struct dwo_file
*dwo_file
,
6479 gdb::array_view
<dwarf2_section_info
> type_sections
,
6480 htab_up
&types_htab
)
6482 for (dwarf2_section_info
§ion
: type_sections
)
6483 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6487 /* Create the hash table of all entries in the .debug_types section,
6488 and initialize all_type_units.
6489 The result is zero if there is an error (e.g. missing .debug_types section),
6490 otherwise non-zero. */
6493 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6497 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6498 types_htab
, rcuh_kind::COMPILE
);
6499 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6501 if (types_htab
== NULL
)
6503 per_objfile
->per_bfd
->signatured_types
= NULL
;
6507 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6509 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6510 per_objfile
->per_bfd
->all_type_units
.reserve
6511 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6513 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6514 add_signatured_type_cu_to_table
,
6515 &per_objfile
->per_bfd
->all_type_units
);
6520 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6521 If SLOT is non-NULL, it is the entry to use in the hash table.
6522 Otherwise we find one. */
6524 static struct signatured_type
*
6525 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6527 if (per_objfile
->per_bfd
->all_type_units
.size ()
6528 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6529 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6531 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6533 per_objfile
->resize_symtabs ();
6535 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6536 sig_type
->signature
= sig
;
6537 sig_type
->per_cu
.is_debug_types
= 1;
6538 if (per_objfile
->per_bfd
->using_index
)
6540 sig_type
->per_cu
.v
.quick
=
6541 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6542 struct dwarf2_per_cu_quick_data
);
6547 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6550 gdb_assert (*slot
== NULL
);
6552 /* The rest of sig_type must be filled in by the caller. */
6556 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6557 Fill in SIG_ENTRY with DWO_ENTRY. */
6560 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6561 struct signatured_type
*sig_entry
,
6562 struct dwo_unit
*dwo_entry
)
6564 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6566 /* Make sure we're not clobbering something we don't expect to. */
6567 gdb_assert (! sig_entry
->per_cu
.queued
);
6568 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6569 if (per_bfd
->using_index
)
6571 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6572 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6575 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6576 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6577 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6578 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6579 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6581 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6582 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6583 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6584 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6585 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6586 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6587 sig_entry
->dwo_unit
= dwo_entry
;
6590 /* Subroutine of lookup_signatured_type.
6591 If we haven't read the TU yet, create the signatured_type data structure
6592 for a TU to be read in directly from a DWO file, bypassing the stub.
6593 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6594 using .gdb_index, then when reading a CU we want to stay in the DWO file
6595 containing that CU. Otherwise we could end up reading several other DWO
6596 files (due to comdat folding) to process the transitive closure of all the
6597 mentioned TUs, and that can be slow. The current DWO file will have every
6598 type signature that it needs.
6599 We only do this for .gdb_index because in the psymtab case we already have
6600 to read all the DWOs to build the type unit groups. */
6602 static struct signatured_type
*
6603 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6605 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6606 struct dwo_file
*dwo_file
;
6607 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6608 struct signatured_type find_sig_entry
, *sig_entry
;
6611 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6613 /* If TU skeletons have been removed then we may not have read in any
6615 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6616 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6618 /* We only ever need to read in one copy of a signatured type.
6619 Use the global signatured_types array to do our own comdat-folding
6620 of types. If this is the first time we're reading this TU, and
6621 the TU has an entry in .gdb_index, replace the recorded data from
6622 .gdb_index with this TU. */
6624 find_sig_entry
.signature
= sig
;
6625 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6626 &find_sig_entry
, INSERT
);
6627 sig_entry
= (struct signatured_type
*) *slot
;
6629 /* We can get here with the TU already read, *or* in the process of being
6630 read. Don't reassign the global entry to point to this DWO if that's
6631 the case. Also note that if the TU is already being read, it may not
6632 have come from a DWO, the program may be a mix of Fission-compiled
6633 code and non-Fission-compiled code. */
6635 /* Have we already tried to read this TU?
6636 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6637 needn't exist in the global table yet). */
6638 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6641 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6642 dwo_unit of the TU itself. */
6643 dwo_file
= cu
->dwo_unit
->dwo_file
;
6645 /* Ok, this is the first time we're reading this TU. */
6646 if (dwo_file
->tus
== NULL
)
6648 find_dwo_entry
.signature
= sig
;
6649 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6651 if (dwo_entry
== NULL
)
6654 /* If the global table doesn't have an entry for this TU, add one. */
6655 if (sig_entry
== NULL
)
6656 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6658 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6659 sig_entry
->per_cu
.tu_read
= 1;
6663 /* Subroutine of lookup_signatured_type.
6664 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6665 then try the DWP file. If the TU stub (skeleton) has been removed then
6666 it won't be in .gdb_index. */
6668 static struct signatured_type
*
6669 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6671 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6672 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6673 struct dwo_unit
*dwo_entry
;
6674 struct signatured_type find_sig_entry
, *sig_entry
;
6677 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6678 gdb_assert (dwp_file
!= NULL
);
6680 /* If TU skeletons have been removed then we may not have read in any
6682 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6683 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6685 find_sig_entry
.signature
= sig
;
6686 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6687 &find_sig_entry
, INSERT
);
6688 sig_entry
= (struct signatured_type
*) *slot
;
6690 /* Have we already tried to read this TU?
6691 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6692 needn't exist in the global table yet). */
6693 if (sig_entry
!= NULL
)
6696 if (dwp_file
->tus
== NULL
)
6698 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6699 1 /* is_debug_types */);
6700 if (dwo_entry
== NULL
)
6703 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6704 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6709 /* Lookup a signature based type for DW_FORM_ref_sig8.
6710 Returns NULL if signature SIG is not present in the table.
6711 It is up to the caller to complain about this. */
6713 static struct signatured_type
*
6714 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6716 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6718 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6720 /* We're in a DWO/DWP file, and we're using .gdb_index.
6721 These cases require special processing. */
6722 if (get_dwp_file (per_objfile
) == NULL
)
6723 return lookup_dwo_signatured_type (cu
, sig
);
6725 return lookup_dwp_signatured_type (cu
, sig
);
6729 struct signatured_type find_entry
, *entry
;
6731 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6733 find_entry
.signature
= sig
;
6734 entry
= ((struct signatured_type
*)
6735 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6741 /* Low level DIE reading support. */
6743 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6746 init_cu_die_reader (struct die_reader_specs
*reader
,
6747 struct dwarf2_cu
*cu
,
6748 struct dwarf2_section_info
*section
,
6749 struct dwo_file
*dwo_file
,
6750 struct abbrev_table
*abbrev_table
)
6752 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6753 reader
->abfd
= section
->get_bfd_owner ();
6755 reader
->dwo_file
= dwo_file
;
6756 reader
->die_section
= section
;
6757 reader
->buffer
= section
->buffer
;
6758 reader
->buffer_end
= section
->buffer
+ section
->size
;
6759 reader
->abbrev_table
= abbrev_table
;
6762 /* Subroutine of cutu_reader to simplify it.
6763 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6764 There's just a lot of work to do, and cutu_reader is big enough
6767 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6768 from it to the DIE in the DWO. If NULL we are skipping the stub.
6769 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6770 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6771 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6772 STUB_COMP_DIR may be non-NULL.
6773 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6774 are filled in with the info of the DIE from the DWO file.
6775 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6776 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6777 kept around for at least as long as *RESULT_READER.
6779 The result is non-zero if a valid (non-dummy) DIE was found. */
6782 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6783 struct dwo_unit
*dwo_unit
,
6784 struct die_info
*stub_comp_unit_die
,
6785 const char *stub_comp_dir
,
6786 struct die_reader_specs
*result_reader
,
6787 const gdb_byte
**result_info_ptr
,
6788 struct die_info
**result_comp_unit_die
,
6789 abbrev_table_up
*result_dwo_abbrev_table
)
6791 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6792 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6793 struct objfile
*objfile
= per_objfile
->objfile
;
6795 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6796 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6797 int i
,num_extra_attrs
;
6798 struct dwarf2_section_info
*dwo_abbrev_section
;
6799 struct die_info
*comp_unit_die
;
6801 /* At most one of these may be provided. */
6802 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6804 /* These attributes aren't processed until later:
6805 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6806 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6807 referenced later. However, these attributes are found in the stub
6808 which we won't have later. In order to not impose this complication
6809 on the rest of the code, we read them here and copy them to the
6818 if (stub_comp_unit_die
!= NULL
)
6820 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6822 if (!per_cu
->is_debug_types
)
6823 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6824 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6825 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6826 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6827 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6829 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6831 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6832 here (if needed). We need the value before we can process
6834 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6836 else if (stub_comp_dir
!= NULL
)
6838 /* Reconstruct the comp_dir attribute to simplify the code below. */
6839 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6840 comp_dir
->name
= DW_AT_comp_dir
;
6841 comp_dir
->form
= DW_FORM_string
;
6842 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6843 DW_STRING (comp_dir
) = stub_comp_dir
;
6846 /* Set up for reading the DWO CU/TU. */
6847 cu
->dwo_unit
= dwo_unit
;
6848 dwarf2_section_info
*section
= dwo_unit
->section
;
6849 section
->read (objfile
);
6850 abfd
= section
->get_bfd_owner ();
6851 begin_info_ptr
= info_ptr
= (section
->buffer
6852 + to_underlying (dwo_unit
->sect_off
));
6853 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6855 if (per_cu
->is_debug_types
)
6857 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6859 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6860 section
, dwo_abbrev_section
,
6861 info_ptr
, rcuh_kind::TYPE
);
6862 /* This is not an assert because it can be caused by bad debug info. */
6863 if (sig_type
->signature
!= cu
->header
.signature
)
6865 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6866 " TU at offset %s [in module %s]"),
6867 hex_string (sig_type
->signature
),
6868 hex_string (cu
->header
.signature
),
6869 sect_offset_str (dwo_unit
->sect_off
),
6870 bfd_get_filename (abfd
));
6872 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6873 /* For DWOs coming from DWP files, we don't know the CU length
6874 nor the type's offset in the TU until now. */
6875 dwo_unit
->length
= cu
->header
.get_length ();
6876 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6878 /* Establish the type offset that can be used to lookup the type.
6879 For DWO files, we don't know it until now. */
6880 sig_type
->type_offset_in_section
6881 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6885 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6886 section
, dwo_abbrev_section
,
6887 info_ptr
, rcuh_kind::COMPILE
);
6888 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6889 /* For DWOs coming from DWP files, we don't know the CU length
6891 dwo_unit
->length
= cu
->header
.get_length ();
6894 *result_dwo_abbrev_table
6895 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6896 cu
->header
.abbrev_sect_off
);
6897 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6898 result_dwo_abbrev_table
->get ());
6900 /* Read in the die, but leave space to copy over the attributes
6901 from the stub. This has the benefit of simplifying the rest of
6902 the code - all the work to maintain the illusion of a single
6903 DW_TAG_{compile,type}_unit DIE is done here. */
6904 num_extra_attrs
= ((stmt_list
!= NULL
)
6908 + (comp_dir
!= NULL
));
6909 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6912 /* Copy over the attributes from the stub to the DIE we just read in. */
6913 comp_unit_die
= *result_comp_unit_die
;
6914 i
= comp_unit_die
->num_attrs
;
6915 if (stmt_list
!= NULL
)
6916 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6918 comp_unit_die
->attrs
[i
++] = *low_pc
;
6919 if (high_pc
!= NULL
)
6920 comp_unit_die
->attrs
[i
++] = *high_pc
;
6922 comp_unit_die
->attrs
[i
++] = *ranges
;
6923 if (comp_dir
!= NULL
)
6924 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6925 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6927 if (dwarf_die_debug
)
6929 fprintf_unfiltered (gdb_stdlog
,
6930 "Read die from %s@0x%x of %s:\n",
6931 section
->get_name (),
6932 (unsigned) (begin_info_ptr
- section
->buffer
),
6933 bfd_get_filename (abfd
));
6934 dump_die (comp_unit_die
, dwarf_die_debug
);
6937 /* Skip dummy compilation units. */
6938 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6939 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6942 *result_info_ptr
= info_ptr
;
6946 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6947 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6948 signature is part of the header. */
6949 static gdb::optional
<ULONGEST
>
6950 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6952 if (cu
->header
.version
>= 5)
6953 return cu
->header
.signature
;
6954 struct attribute
*attr
;
6955 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6956 if (attr
== nullptr)
6957 return gdb::optional
<ULONGEST
> ();
6958 return DW_UNSND (attr
);
6961 /* Subroutine of cutu_reader to simplify it.
6962 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6963 Returns NULL if the specified DWO unit cannot be found. */
6965 static struct dwo_unit
*
6966 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6968 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6969 struct dwo_unit
*dwo_unit
;
6970 const char *comp_dir
;
6972 gdb_assert (cu
!= NULL
);
6974 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6975 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6976 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6978 if (per_cu
->is_debug_types
)
6979 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6982 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6984 if (!signature
.has_value ())
6985 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6987 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6989 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6995 /* Subroutine of cutu_reader to simplify it.
6996 See it for a description of the parameters.
6997 Read a TU directly from a DWO file, bypassing the stub. */
7000 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7001 dwarf2_per_objfile
*per_objfile
,
7002 dwarf2_cu
*existing_cu
)
7004 struct signatured_type
*sig_type
;
7006 /* Verify we can do the following downcast, and that we have the
7008 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7009 sig_type
= (struct signatured_type
*) this_cu
;
7010 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7014 if (existing_cu
!= nullptr)
7017 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7018 /* There's no need to do the rereading_dwo_cu handling that
7019 cutu_reader does since we don't read the stub. */
7023 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7024 in per_objfile yet. */
7025 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7026 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7027 cu
= m_new_cu
.get ();
7030 /* A future optimization, if needed, would be to use an existing
7031 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7032 could share abbrev tables. */
7034 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7035 NULL
/* stub_comp_unit_die */,
7036 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7039 &m_dwo_abbrev_table
) == 0)
7046 /* Initialize a CU (or TU) and read its DIEs.
7047 If the CU defers to a DWO file, read the DWO file as well.
7049 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7050 Otherwise the table specified in the comp unit header is read in and used.
7051 This is an optimization for when we already have the abbrev table.
7053 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7056 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7057 dwarf2_per_objfile
*per_objfile
,
7058 struct abbrev_table
*abbrev_table
,
7059 dwarf2_cu
*existing_cu
,
7061 : die_reader_specs
{},
7064 struct objfile
*objfile
= per_objfile
->objfile
;
7065 struct dwarf2_section_info
*section
= this_cu
->section
;
7066 bfd
*abfd
= section
->get_bfd_owner ();
7067 const gdb_byte
*begin_info_ptr
;
7068 struct signatured_type
*sig_type
= NULL
;
7069 struct dwarf2_section_info
*abbrev_section
;
7070 /* Non-zero if CU currently points to a DWO file and we need to
7071 reread it. When this happens we need to reread the skeleton die
7072 before we can reread the DWO file (this only applies to CUs, not TUs). */
7073 int rereading_dwo_cu
= 0;
7075 if (dwarf_die_debug
)
7076 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7077 this_cu
->is_debug_types
? "type" : "comp",
7078 sect_offset_str (this_cu
->sect_off
));
7080 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7081 file (instead of going through the stub), short-circuit all of this. */
7082 if (this_cu
->reading_dwo_directly
)
7084 /* Narrow down the scope of possibilities to have to understand. */
7085 gdb_assert (this_cu
->is_debug_types
);
7086 gdb_assert (abbrev_table
== NULL
);
7087 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7091 /* This is cheap if the section is already read in. */
7092 section
->read (objfile
);
7094 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7096 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7100 if (existing_cu
!= nullptr)
7103 /* If this CU is from a DWO file we need to start over, we need to
7104 refetch the attributes from the skeleton CU.
7105 This could be optimized by retrieving those attributes from when we
7106 were here the first time: the previous comp_unit_die was stored in
7107 comp_unit_obstack. But there's no data yet that we need this
7109 if (cu
->dwo_unit
!= NULL
)
7110 rereading_dwo_cu
= 1;
7114 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7115 in per_objfile yet. */
7116 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7117 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7118 cu
= m_new_cu
.get ();
7121 /* Get the header. */
7122 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7124 /* We already have the header, there's no need to read it in again. */
7125 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7129 if (this_cu
->is_debug_types
)
7131 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7132 section
, abbrev_section
,
7133 info_ptr
, rcuh_kind::TYPE
);
7135 /* Since per_cu is the first member of struct signatured_type,
7136 we can go from a pointer to one to a pointer to the other. */
7137 sig_type
= (struct signatured_type
*) this_cu
;
7138 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7139 gdb_assert (sig_type
->type_offset_in_tu
7140 == cu
->header
.type_cu_offset_in_tu
);
7141 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7143 /* LENGTH has not been set yet for type units if we're
7144 using .gdb_index. */
7145 this_cu
->length
= cu
->header
.get_length ();
7147 /* Establish the type offset that can be used to lookup the type. */
7148 sig_type
->type_offset_in_section
=
7149 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7151 this_cu
->dwarf_version
= cu
->header
.version
;
7155 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7156 section
, abbrev_section
,
7158 rcuh_kind::COMPILE
);
7160 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7161 if (this_cu
->length
== 0)
7162 this_cu
->length
= cu
->header
.get_length ();
7164 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7165 this_cu
->dwarf_version
= cu
->header
.version
;
7169 /* Skip dummy compilation units. */
7170 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7171 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7177 /* If we don't have them yet, read the abbrevs for this compilation unit.
7178 And if we need to read them now, make sure they're freed when we're
7180 if (abbrev_table
!= NULL
)
7181 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7184 m_abbrev_table_holder
7185 = abbrev_table::read (objfile
, abbrev_section
,
7186 cu
->header
.abbrev_sect_off
);
7187 abbrev_table
= m_abbrev_table_holder
.get ();
7190 /* Read the top level CU/TU die. */
7191 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7192 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7194 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7200 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7201 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7202 table from the DWO file and pass the ownership over to us. It will be
7203 referenced from READER, so we must make sure to free it after we're done
7206 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7207 DWO CU, that this test will fail (the attribute will not be present). */
7208 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7209 if (dwo_name
!= nullptr)
7211 struct dwo_unit
*dwo_unit
;
7212 struct die_info
*dwo_comp_unit_die
;
7214 if (comp_unit_die
->has_children
)
7216 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7217 " has children (offset %s) [in module %s]"),
7218 sect_offset_str (this_cu
->sect_off
),
7219 bfd_get_filename (abfd
));
7221 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7222 if (dwo_unit
!= NULL
)
7224 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7225 comp_unit_die
, NULL
,
7228 &m_dwo_abbrev_table
) == 0)
7234 comp_unit_die
= dwo_comp_unit_die
;
7238 /* Yikes, we couldn't find the rest of the DIE, we only have
7239 the stub. A complaint has already been logged. There's
7240 not much more we can do except pass on the stub DIE to
7241 die_reader_func. We don't want to throw an error on bad
7248 cutu_reader::keep ()
7250 /* Done, clean up. */
7251 gdb_assert (!dummy_p
);
7252 if (m_new_cu
!= NULL
)
7254 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7256 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7257 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7261 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7262 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7263 assumed to have already done the lookup to find the DWO file).
7265 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7266 THIS_CU->is_debug_types, but nothing else.
7268 We fill in THIS_CU->length.
7270 THIS_CU->cu is always freed when done.
7271 This is done in order to not leave THIS_CU->cu in a state where we have
7272 to care whether it refers to the "main" CU or the DWO CU.
7274 When parent_cu is passed, it is used to provide a default value for
7275 str_offsets_base and addr_base from the parent. */
7277 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7278 dwarf2_per_objfile
*per_objfile
,
7279 struct dwarf2_cu
*parent_cu
,
7280 struct dwo_file
*dwo_file
)
7281 : die_reader_specs
{},
7284 struct objfile
*objfile
= per_objfile
->objfile
;
7285 struct dwarf2_section_info
*section
= this_cu
->section
;
7286 bfd
*abfd
= section
->get_bfd_owner ();
7287 struct dwarf2_section_info
*abbrev_section
;
7288 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7290 if (dwarf_die_debug
)
7291 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7292 this_cu
->is_debug_types
? "type" : "comp",
7293 sect_offset_str (this_cu
->sect_off
));
7295 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7297 abbrev_section
= (dwo_file
!= NULL
7298 ? &dwo_file
->sections
.abbrev
7299 : get_abbrev_section_for_cu (this_cu
));
7301 /* This is cheap if the section is already read in. */
7302 section
->read (objfile
);
7304 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7306 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7307 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7308 section
, abbrev_section
, info_ptr
,
7309 (this_cu
->is_debug_types
7311 : rcuh_kind::COMPILE
));
7313 if (parent_cu
!= nullptr)
7315 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7316 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7318 this_cu
->length
= m_new_cu
->header
.get_length ();
7320 /* Skip dummy compilation units. */
7321 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7322 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7328 m_abbrev_table_holder
7329 = abbrev_table::read (objfile
, abbrev_section
,
7330 m_new_cu
->header
.abbrev_sect_off
);
7332 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7333 m_abbrev_table_holder
.get ());
7334 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7338 /* Type Unit Groups.
7340 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7341 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7342 so that all types coming from the same compilation (.o file) are grouped
7343 together. A future step could be to put the types in the same symtab as
7344 the CU the types ultimately came from. */
7347 hash_type_unit_group (const void *item
)
7349 const struct type_unit_group
*tu_group
7350 = (const struct type_unit_group
*) item
;
7352 return hash_stmt_list_entry (&tu_group
->hash
);
7356 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7358 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7359 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7361 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7364 /* Allocate a hash table for type unit groups. */
7367 allocate_type_unit_groups_table ()
7369 return htab_up (htab_create_alloc (3,
7370 hash_type_unit_group
,
7372 NULL
, xcalloc
, xfree
));
7375 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7376 partial symtabs. We combine several TUs per psymtab to not let the size
7377 of any one psymtab grow too big. */
7378 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7379 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7381 /* Helper routine for get_type_unit_group.
7382 Create the type_unit_group object used to hold one or more TUs. */
7384 static struct type_unit_group
*
7385 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7387 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7388 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7389 struct dwarf2_per_cu_data
*per_cu
;
7390 struct type_unit_group
*tu_group
;
7392 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7393 per_cu
= &tu_group
->per_cu
;
7394 per_cu
->per_bfd
= per_bfd
;
7396 if (per_bfd
->using_index
)
7398 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7399 struct dwarf2_per_cu_quick_data
);
7403 unsigned int line_offset
= to_underlying (line_offset_struct
);
7404 dwarf2_psymtab
*pst
;
7407 /* Give the symtab a useful name for debug purposes. */
7408 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7409 name
= string_printf ("<type_units_%d>",
7410 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7412 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7414 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7415 pst
->anonymous
= true;
7418 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7419 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7424 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7425 STMT_LIST is a DW_AT_stmt_list attribute. */
7427 static struct type_unit_group
*
7428 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7430 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7431 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7432 struct type_unit_group
*tu_group
;
7434 unsigned int line_offset
;
7435 struct type_unit_group type_unit_group_for_lookup
;
7437 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7438 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7440 /* Do we need to create a new group, or can we use an existing one? */
7444 line_offset
= DW_UNSND (stmt_list
);
7445 ++tu_stats
->nr_symtab_sharers
;
7449 /* Ugh, no stmt_list. Rare, but we have to handle it.
7450 We can do various things here like create one group per TU or
7451 spread them over multiple groups to split up the expansion work.
7452 To avoid worst case scenarios (too many groups or too large groups)
7453 we, umm, group them in bunches. */
7454 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7455 | (tu_stats
->nr_stmt_less_type_units
7456 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7457 ++tu_stats
->nr_stmt_less_type_units
;
7460 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7461 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7462 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7463 &type_unit_group_for_lookup
, INSERT
);
7466 tu_group
= (struct type_unit_group
*) *slot
;
7467 gdb_assert (tu_group
!= NULL
);
7471 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7472 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7474 ++tu_stats
->nr_symtabs
;
7480 /* Partial symbol tables. */
7482 /* Create a psymtab named NAME and assign it to PER_CU.
7484 The caller must fill in the following details:
7485 dirname, textlow, texthigh. */
7487 static dwarf2_psymtab
*
7488 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7489 dwarf2_per_objfile
*per_objfile
,
7492 struct objfile
*objfile
= per_objfile
->objfile
;
7493 dwarf2_psymtab
*pst
;
7495 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7497 pst
->psymtabs_addrmap_supported
= true;
7499 /* This is the glue that links PST into GDB's symbol API. */
7500 per_cu
->v
.psymtab
= pst
;
7505 /* DIE reader function for process_psymtab_comp_unit. */
7508 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7509 const gdb_byte
*info_ptr
,
7510 struct die_info
*comp_unit_die
,
7511 enum language pretend_language
)
7513 struct dwarf2_cu
*cu
= reader
->cu
;
7514 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7515 struct objfile
*objfile
= per_objfile
->objfile
;
7516 struct gdbarch
*gdbarch
= objfile
->arch ();
7517 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7519 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7520 dwarf2_psymtab
*pst
;
7521 enum pc_bounds_kind cu_bounds_kind
;
7522 const char *filename
;
7524 gdb_assert (! per_cu
->is_debug_types
);
7526 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7528 /* Allocate a new partial symbol table structure. */
7529 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7530 static const char artificial
[] = "<artificial>";
7531 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7532 if (filename
== NULL
)
7534 else if (strcmp (filename
, artificial
) == 0)
7536 debug_filename
.reset (concat (artificial
, "@",
7537 sect_offset_str (per_cu
->sect_off
),
7539 filename
= debug_filename
.get ();
7542 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7544 /* This must be done before calling dwarf2_build_include_psymtabs. */
7545 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7547 baseaddr
= objfile
->text_section_offset ();
7549 dwarf2_find_base_address (comp_unit_die
, cu
);
7551 /* Possibly set the default values of LOWPC and HIGHPC from
7553 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7554 &best_highpc
, cu
, pst
);
7555 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7558 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7561 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7563 /* Store the contiguous range if it is not empty; it can be
7564 empty for CUs with no code. */
7565 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7569 /* Check if comp unit has_children.
7570 If so, read the rest of the partial symbols from this comp unit.
7571 If not, there's no more debug_info for this comp unit. */
7572 if (comp_unit_die
->has_children
)
7574 struct partial_die_info
*first_die
;
7575 CORE_ADDR lowpc
, highpc
;
7577 lowpc
= ((CORE_ADDR
) -1);
7578 highpc
= ((CORE_ADDR
) 0);
7580 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7582 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7583 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7585 /* If we didn't find a lowpc, set it to highpc to avoid
7586 complaints from `maint check'. */
7587 if (lowpc
== ((CORE_ADDR
) -1))
7590 /* If the compilation unit didn't have an explicit address range,
7591 then use the information extracted from its child dies. */
7592 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7595 best_highpc
= highpc
;
7598 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7599 best_lowpc
+ baseaddr
)
7601 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7602 best_highpc
+ baseaddr
)
7605 end_psymtab_common (objfile
, pst
);
7607 if (!cu
->per_cu
->imported_symtabs_empty ())
7610 int len
= cu
->per_cu
->imported_symtabs_size ();
7612 /* Fill in 'dependencies' here; we fill in 'users' in a
7614 pst
->number_of_dependencies
= len
;
7616 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7617 for (i
= 0; i
< len
; ++i
)
7619 pst
->dependencies
[i
]
7620 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7623 cu
->per_cu
->imported_symtabs_free ();
7626 /* Get the list of files included in the current compilation unit,
7627 and build a psymtab for each of them. */
7628 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7630 if (dwarf_read_debug
)
7631 fprintf_unfiltered (gdb_stdlog
,
7632 "Psymtab for %s unit @%s: %s - %s"
7633 ", %d global, %d static syms\n",
7634 per_cu
->is_debug_types
? "type" : "comp",
7635 sect_offset_str (per_cu
->sect_off
),
7636 paddress (gdbarch
, pst
->text_low (objfile
)),
7637 paddress (gdbarch
, pst
->text_high (objfile
)),
7638 pst
->n_global_syms
, pst
->n_static_syms
);
7641 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7642 Process compilation unit THIS_CU for a psymtab. */
7645 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7646 dwarf2_per_objfile
*per_objfile
,
7647 bool want_partial_unit
,
7648 enum language pretend_language
)
7650 /* If this compilation unit was already read in, free the
7651 cached copy in order to read it in again. This is
7652 necessary because we skipped some symbols when we first
7653 read in the compilation unit (see load_partial_dies).
7654 This problem could be avoided, but the benefit is unclear. */
7655 per_objfile
->remove_cu (this_cu
);
7657 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7659 switch (reader
.comp_unit_die
->tag
)
7661 case DW_TAG_compile_unit
:
7662 this_cu
->unit_type
= DW_UT_compile
;
7664 case DW_TAG_partial_unit
:
7665 this_cu
->unit_type
= DW_UT_partial
;
7675 else if (this_cu
->is_debug_types
)
7676 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7677 reader
.comp_unit_die
);
7678 else if (want_partial_unit
7679 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7680 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7681 reader
.comp_unit_die
,
7684 this_cu
->lang
= reader
.cu
->language
;
7686 /* Age out any secondary CUs. */
7687 per_objfile
->age_comp_units ();
7690 /* Reader function for build_type_psymtabs. */
7693 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7694 const gdb_byte
*info_ptr
,
7695 struct die_info
*type_unit_die
)
7697 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7698 struct objfile
*objfile
= per_objfile
->objfile
;
7699 struct dwarf2_cu
*cu
= reader
->cu
;
7700 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7701 struct signatured_type
*sig_type
;
7702 struct type_unit_group
*tu_group
;
7703 struct attribute
*attr
;
7704 struct partial_die_info
*first_die
;
7705 CORE_ADDR lowpc
, highpc
;
7706 dwarf2_psymtab
*pst
;
7708 gdb_assert (per_cu
->is_debug_types
);
7709 sig_type
= (struct signatured_type
*) per_cu
;
7711 if (! type_unit_die
->has_children
)
7714 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7715 tu_group
= get_type_unit_group (cu
, attr
);
7717 if (tu_group
->tus
== nullptr)
7718 tu_group
->tus
= new std::vector
<signatured_type
*>;
7719 tu_group
->tus
->push_back (sig_type
);
7721 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7722 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7723 pst
->anonymous
= true;
7725 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7727 lowpc
= (CORE_ADDR
) -1;
7728 highpc
= (CORE_ADDR
) 0;
7729 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7731 end_psymtab_common (objfile
, pst
);
7734 /* Struct used to sort TUs by their abbreviation table offset. */
7736 struct tu_abbrev_offset
7738 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7739 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7742 signatured_type
*sig_type
;
7743 sect_offset abbrev_offset
;
7746 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7749 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7750 const struct tu_abbrev_offset
&b
)
7752 return a
.abbrev_offset
< b
.abbrev_offset
;
7755 /* Efficiently read all the type units.
7756 This does the bulk of the work for build_type_psymtabs.
7758 The efficiency is because we sort TUs by the abbrev table they use and
7759 only read each abbrev table once. In one program there are 200K TUs
7760 sharing 8K abbrev tables.
7762 The main purpose of this function is to support building the
7763 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7764 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7765 can collapse the search space by grouping them by stmt_list.
7766 The savings can be significant, in the same program from above the 200K TUs
7767 share 8K stmt_list tables.
7769 FUNC is expected to call get_type_unit_group, which will create the
7770 struct type_unit_group if necessary and add it to
7771 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7774 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7776 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7777 abbrev_table_up abbrev_table
;
7778 sect_offset abbrev_offset
;
7780 /* It's up to the caller to not call us multiple times. */
7781 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7783 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7786 /* TUs typically share abbrev tables, and there can be way more TUs than
7787 abbrev tables. Sort by abbrev table to reduce the number of times we
7788 read each abbrev table in.
7789 Alternatives are to punt or to maintain a cache of abbrev tables.
7790 This is simpler and efficient enough for now.
7792 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7793 symtab to use). Typically TUs with the same abbrev offset have the same
7794 stmt_list value too so in practice this should work well.
7796 The basic algorithm here is:
7798 sort TUs by abbrev table
7799 for each TU with same abbrev table:
7800 read abbrev table if first user
7801 read TU top level DIE
7802 [IWBN if DWO skeletons had DW_AT_stmt_list]
7805 if (dwarf_read_debug
)
7806 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7808 /* Sort in a separate table to maintain the order of all_type_units
7809 for .gdb_index: TU indices directly index all_type_units. */
7810 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7811 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7813 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7814 sorted_by_abbrev
.emplace_back
7815 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7816 sig_type
->per_cu
.sect_off
));
7818 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7819 sort_tu_by_abbrev_offset
);
7821 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7823 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7825 /* Switch to the next abbrev table if necessary. */
7826 if (abbrev_table
== NULL
7827 || tu
.abbrev_offset
!= abbrev_offset
)
7829 abbrev_offset
= tu
.abbrev_offset
;
7831 abbrev_table::read (per_objfile
->objfile
,
7832 &per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7833 ++tu_stats
->nr_uniq_abbrev_tables
;
7836 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7837 abbrev_table
.get (), nullptr, false);
7838 if (!reader
.dummy_p
)
7839 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7840 reader
.comp_unit_die
);
7844 /* Print collected type unit statistics. */
7847 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7849 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7851 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7852 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7853 per_objfile
->per_bfd
->all_type_units
.size ());
7854 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7855 tu_stats
->nr_uniq_abbrev_tables
);
7856 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7857 tu_stats
->nr_symtabs
);
7858 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7859 tu_stats
->nr_symtab_sharers
);
7860 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7861 tu_stats
->nr_stmt_less_type_units
);
7862 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7863 tu_stats
->nr_all_type_units_reallocs
);
7866 /* Traversal function for build_type_psymtabs. */
7869 build_type_psymtab_dependencies (void **slot
, void *info
)
7871 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7872 struct objfile
*objfile
= per_objfile
->objfile
;
7873 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7874 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7875 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7876 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7879 gdb_assert (len
> 0);
7880 gdb_assert (per_cu
->type_unit_group_p ());
7882 pst
->number_of_dependencies
= len
;
7883 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7884 for (i
= 0; i
< len
; ++i
)
7886 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7887 gdb_assert (iter
->per_cu
.is_debug_types
);
7888 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7889 iter
->type_unit_group
= tu_group
;
7892 delete tu_group
->tus
;
7893 tu_group
->tus
= nullptr;
7898 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7899 Build partial symbol tables for the .debug_types comp-units. */
7902 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7904 if (! create_all_type_units (per_objfile
))
7907 build_type_psymtabs_1 (per_objfile
);
7910 /* Traversal function for process_skeletonless_type_unit.
7911 Read a TU in a DWO file and build partial symbols for it. */
7914 process_skeletonless_type_unit (void **slot
, void *info
)
7916 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7917 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7918 struct signatured_type find_entry
, *entry
;
7920 /* If this TU doesn't exist in the global table, add it and read it in. */
7922 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7923 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7925 find_entry
.signature
= dwo_unit
->signature
;
7926 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7927 &find_entry
, INSERT
);
7928 /* If we've already seen this type there's nothing to do. What's happening
7929 is we're doing our own version of comdat-folding here. */
7933 /* This does the job that create_all_type_units would have done for
7935 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7936 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7939 /* This does the job that build_type_psymtabs_1 would have done. */
7940 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7941 if (!reader
.dummy_p
)
7942 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7943 reader
.comp_unit_die
);
7948 /* Traversal function for process_skeletonless_type_units. */
7951 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7953 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7955 if (dwo_file
->tus
!= NULL
)
7956 htab_traverse_noresize (dwo_file
->tus
.get (),
7957 process_skeletonless_type_unit
, info
);
7962 /* Scan all TUs of DWO files, verifying we've processed them.
7963 This is needed in case a TU was emitted without its skeleton.
7964 Note: This can't be done until we know what all the DWO files are. */
7967 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7969 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7970 if (get_dwp_file (per_objfile
) == NULL
7971 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7973 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7974 process_dwo_file_for_skeletonless_type_units
,
7979 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7982 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7984 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7986 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7991 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7993 /* Set the 'user' field only if it is not already set. */
7994 if (pst
->dependencies
[j
]->user
== NULL
)
7995 pst
->dependencies
[j
]->user
= pst
;
8000 /* Build the partial symbol table by doing a quick pass through the
8001 .debug_info and .debug_abbrev sections. */
8004 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8006 struct objfile
*objfile
= per_objfile
->objfile
;
8008 if (dwarf_read_debug
)
8010 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8011 objfile_name (objfile
));
8014 scoped_restore restore_reading_psyms
8015 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8018 per_objfile
->per_bfd
->info
.read (objfile
);
8020 /* Any cached compilation units will be linked by the per-objfile
8021 read_in_chain. Make sure to free them when we're done. */
8022 free_cached_comp_units
freer (per_objfile
);
8024 build_type_psymtabs (per_objfile
);
8026 create_all_comp_units (per_objfile
);
8028 /* Create a temporary address map on a temporary obstack. We later
8029 copy this to the final obstack. */
8030 auto_obstack temp_obstack
;
8032 scoped_restore save_psymtabs_addrmap
8033 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8034 addrmap_create_mutable (&temp_obstack
));
8036 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8038 if (per_cu
->v
.psymtab
!= NULL
)
8039 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8041 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8045 /* This has to wait until we read the CUs, we need the list of DWOs. */
8046 process_skeletonless_type_units (per_objfile
);
8048 /* Now that all TUs have been processed we can fill in the dependencies. */
8049 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8051 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8052 build_type_psymtab_dependencies
, per_objfile
);
8055 if (dwarf_read_debug
)
8056 print_tu_stats (per_objfile
);
8058 set_partial_user (per_objfile
);
8060 objfile
->partial_symtabs
->psymtabs_addrmap
8061 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8062 objfile
->partial_symtabs
->obstack ());
8063 /* At this point we want to keep the address map. */
8064 save_psymtabs_addrmap
.release ();
8066 if (dwarf_read_debug
)
8067 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8068 objfile_name (objfile
));
8071 /* Load the partial DIEs for a secondary CU into memory.
8072 This is also used when rereading a primary CU with load_all_dies. */
8075 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8076 dwarf2_per_objfile
*per_objfile
,
8077 dwarf2_cu
*existing_cu
)
8079 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8081 if (!reader
.dummy_p
)
8083 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8086 /* Check if comp unit has_children.
8087 If so, read the rest of the partial symbols from this comp unit.
8088 If not, there's no more debug_info for this comp unit. */
8089 if (reader
.comp_unit_die
->has_children
)
8090 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8097 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8098 struct dwarf2_section_info
*section
,
8099 struct dwarf2_section_info
*abbrev_section
,
8100 unsigned int is_dwz
)
8102 const gdb_byte
*info_ptr
;
8103 struct objfile
*objfile
= per_objfile
->objfile
;
8105 if (dwarf_read_debug
)
8106 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8107 section
->get_name (),
8108 section
->get_file_name ());
8110 section
->read (objfile
);
8112 info_ptr
= section
->buffer
;
8114 while (info_ptr
< section
->buffer
+ section
->size
)
8116 struct dwarf2_per_cu_data
*this_cu
;
8118 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8120 comp_unit_head cu_header
;
8121 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8122 abbrev_section
, info_ptr
,
8123 rcuh_kind::COMPILE
);
8125 /* Save the compilation unit for later lookup. */
8126 if (cu_header
.unit_type
!= DW_UT_type
)
8127 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8130 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8131 sig_type
->signature
= cu_header
.signature
;
8132 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8133 this_cu
= &sig_type
->per_cu
;
8135 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8136 this_cu
->sect_off
= sect_off
;
8137 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8138 this_cu
->is_dwz
= is_dwz
;
8139 this_cu
->section
= section
;
8141 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8143 info_ptr
= info_ptr
+ this_cu
->length
;
8147 /* Create a list of all compilation units in OBJFILE.
8148 This is only done for -readnow and building partial symtabs. */
8151 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8153 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8154 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8155 &per_objfile
->per_bfd
->abbrev
, 0);
8157 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8159 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8162 /* Process all loaded DIEs for compilation unit CU, starting at
8163 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8164 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8165 DW_AT_ranges). See the comments of add_partial_subprogram on how
8166 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8169 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8170 CORE_ADDR
*highpc
, int set_addrmap
,
8171 struct dwarf2_cu
*cu
)
8173 struct partial_die_info
*pdi
;
8175 /* Now, march along the PDI's, descending into ones which have
8176 interesting children but skipping the children of the other ones,
8177 until we reach the end of the compilation unit. */
8185 /* Anonymous namespaces or modules have no name but have interesting
8186 children, so we need to look at them. Ditto for anonymous
8189 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8190 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8191 || pdi
->tag
== DW_TAG_imported_unit
8192 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8196 case DW_TAG_subprogram
:
8197 case DW_TAG_inlined_subroutine
:
8198 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8199 if (cu
->language
== language_cplus
)
8200 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8203 case DW_TAG_constant
:
8204 case DW_TAG_variable
:
8205 case DW_TAG_typedef
:
8206 case DW_TAG_union_type
:
8207 if (!pdi
->is_declaration
8208 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8210 add_partial_symbol (pdi
, cu
);
8213 case DW_TAG_class_type
:
8214 case DW_TAG_interface_type
:
8215 case DW_TAG_structure_type
:
8216 if (!pdi
->is_declaration
)
8218 add_partial_symbol (pdi
, cu
);
8220 if ((cu
->language
== language_rust
8221 || cu
->language
== language_cplus
) && pdi
->has_children
)
8222 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8225 case DW_TAG_enumeration_type
:
8226 if (!pdi
->is_declaration
)
8227 add_partial_enumeration (pdi
, cu
);
8229 case DW_TAG_base_type
:
8230 case DW_TAG_subrange_type
:
8231 /* File scope base type definitions are added to the partial
8233 add_partial_symbol (pdi
, cu
);
8235 case DW_TAG_namespace
:
8236 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8239 if (!pdi
->is_declaration
)
8240 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8242 case DW_TAG_imported_unit
:
8244 struct dwarf2_per_cu_data
*per_cu
;
8246 /* For now we don't handle imported units in type units. */
8247 if (cu
->per_cu
->is_debug_types
)
8249 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8250 " supported in type units [in module %s]"),
8251 objfile_name (cu
->per_objfile
->objfile
));
8254 per_cu
= dwarf2_find_containing_comp_unit
8255 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8257 /* Go read the partial unit, if needed. */
8258 if (per_cu
->v
.psymtab
== NULL
)
8259 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8262 cu
->per_cu
->imported_symtabs_push (per_cu
);
8265 case DW_TAG_imported_declaration
:
8266 add_partial_symbol (pdi
, cu
);
8273 /* If the die has a sibling, skip to the sibling. */
8275 pdi
= pdi
->die_sibling
;
8279 /* Functions used to compute the fully scoped name of a partial DIE.
8281 Normally, this is simple. For C++, the parent DIE's fully scoped
8282 name is concatenated with "::" and the partial DIE's name.
8283 Enumerators are an exception; they use the scope of their parent
8284 enumeration type, i.e. the name of the enumeration type is not
8285 prepended to the enumerator.
8287 There are two complexities. One is DW_AT_specification; in this
8288 case "parent" means the parent of the target of the specification,
8289 instead of the direct parent of the DIE. The other is compilers
8290 which do not emit DW_TAG_namespace; in this case we try to guess
8291 the fully qualified name of structure types from their members'
8292 linkage names. This must be done using the DIE's children rather
8293 than the children of any DW_AT_specification target. We only need
8294 to do this for structures at the top level, i.e. if the target of
8295 any DW_AT_specification (if any; otherwise the DIE itself) does not
8298 /* Compute the scope prefix associated with PDI's parent, in
8299 compilation unit CU. The result will be allocated on CU's
8300 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8301 field. NULL is returned if no prefix is necessary. */
8303 partial_die_parent_scope (struct partial_die_info
*pdi
,
8304 struct dwarf2_cu
*cu
)
8306 const char *grandparent_scope
;
8307 struct partial_die_info
*parent
, *real_pdi
;
8309 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8310 then this means the parent of the specification DIE. */
8313 while (real_pdi
->has_specification
)
8315 auto res
= find_partial_die (real_pdi
->spec_offset
,
8316 real_pdi
->spec_is_dwz
, cu
);
8321 parent
= real_pdi
->die_parent
;
8325 if (parent
->scope_set
)
8326 return parent
->scope
;
8330 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8332 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8333 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8334 Work around this problem here. */
8335 if (cu
->language
== language_cplus
8336 && parent
->tag
== DW_TAG_namespace
8337 && strcmp (parent
->name (cu
), "::") == 0
8338 && grandparent_scope
== NULL
)
8340 parent
->scope
= NULL
;
8341 parent
->scope_set
= 1;
8345 /* Nested subroutines in Fortran get a prefix. */
8346 if (pdi
->tag
== DW_TAG_enumerator
)
8347 /* Enumerators should not get the name of the enumeration as a prefix. */
8348 parent
->scope
= grandparent_scope
;
8349 else if (parent
->tag
== DW_TAG_namespace
8350 || parent
->tag
== DW_TAG_module
8351 || parent
->tag
== DW_TAG_structure_type
8352 || parent
->tag
== DW_TAG_class_type
8353 || parent
->tag
== DW_TAG_interface_type
8354 || parent
->tag
== DW_TAG_union_type
8355 || parent
->tag
== DW_TAG_enumeration_type
8356 || (cu
->language
== language_fortran
8357 && parent
->tag
== DW_TAG_subprogram
8358 && pdi
->tag
== DW_TAG_subprogram
))
8360 if (grandparent_scope
== NULL
)
8361 parent
->scope
= parent
->name (cu
);
8363 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8365 parent
->name (cu
), 0, cu
);
8369 /* FIXME drow/2004-04-01: What should we be doing with
8370 function-local names? For partial symbols, we should probably be
8372 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8373 dwarf_tag_name (parent
->tag
),
8374 sect_offset_str (pdi
->sect_off
));
8375 parent
->scope
= grandparent_scope
;
8378 parent
->scope_set
= 1;
8379 return parent
->scope
;
8382 /* Return the fully scoped name associated with PDI, from compilation unit
8383 CU. The result will be allocated with malloc. */
8385 static gdb::unique_xmalloc_ptr
<char>
8386 partial_die_full_name (struct partial_die_info
*pdi
,
8387 struct dwarf2_cu
*cu
)
8389 const char *parent_scope
;
8391 /* If this is a template instantiation, we can not work out the
8392 template arguments from partial DIEs. So, unfortunately, we have
8393 to go through the full DIEs. At least any work we do building
8394 types here will be reused if full symbols are loaded later. */
8395 if (pdi
->has_template_arguments
)
8399 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8401 struct die_info
*die
;
8402 struct attribute attr
;
8403 struct dwarf2_cu
*ref_cu
= cu
;
8405 /* DW_FORM_ref_addr is using section offset. */
8406 attr
.name
= (enum dwarf_attribute
) 0;
8407 attr
.form
= DW_FORM_ref_addr
;
8408 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8409 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8411 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8415 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8416 if (parent_scope
== NULL
)
8419 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8425 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8427 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8428 struct objfile
*objfile
= per_objfile
->objfile
;
8429 struct gdbarch
*gdbarch
= objfile
->arch ();
8431 const char *actual_name
= NULL
;
8434 baseaddr
= objfile
->text_section_offset ();
8436 gdb::unique_xmalloc_ptr
<char> built_actual_name
8437 = partial_die_full_name (pdi
, cu
);
8438 if (built_actual_name
!= NULL
)
8439 actual_name
= built_actual_name
.get ();
8441 if (actual_name
== NULL
)
8442 actual_name
= pdi
->name (cu
);
8444 partial_symbol psymbol
;
8445 memset (&psymbol
, 0, sizeof (psymbol
));
8446 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8447 psymbol
.ginfo
.section
= -1;
8449 /* The code below indicates that the psymbol should be installed by
8451 gdb::optional
<psymbol_placement
> where
;
8455 case DW_TAG_inlined_subroutine
:
8456 case DW_TAG_subprogram
:
8457 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8459 if (pdi
->is_external
8460 || cu
->language
== language_ada
8461 || (cu
->language
== language_fortran
8462 && pdi
->die_parent
!= NULL
8463 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8465 /* Normally, only "external" DIEs are part of the global scope.
8466 But in Ada and Fortran, we want to be able to access nested
8467 procedures globally. So all Ada and Fortran subprograms are
8468 stored in the global scope. */
8469 where
= psymbol_placement::GLOBAL
;
8472 where
= psymbol_placement::STATIC
;
8474 psymbol
.domain
= VAR_DOMAIN
;
8475 psymbol
.aclass
= LOC_BLOCK
;
8476 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8477 psymbol
.ginfo
.value
.address
= addr
;
8479 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8480 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8482 case DW_TAG_constant
:
8483 psymbol
.domain
= VAR_DOMAIN
;
8484 psymbol
.aclass
= LOC_STATIC
;
8485 where
= (pdi
->is_external
8486 ? psymbol_placement::GLOBAL
8487 : psymbol_placement::STATIC
);
8489 case DW_TAG_variable
:
8491 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8495 && !per_objfile
->per_bfd
->has_section_at_zero
)
8497 /* A global or static variable may also have been stripped
8498 out by the linker if unused, in which case its address
8499 will be nullified; do not add such variables into partial
8500 symbol table then. */
8502 else if (pdi
->is_external
)
8505 Don't enter into the minimal symbol tables as there is
8506 a minimal symbol table entry from the ELF symbols already.
8507 Enter into partial symbol table if it has a location
8508 descriptor or a type.
8509 If the location descriptor is missing, new_symbol will create
8510 a LOC_UNRESOLVED symbol, the address of the variable will then
8511 be determined from the minimal symbol table whenever the variable
8513 The address for the partial symbol table entry is not
8514 used by GDB, but it comes in handy for debugging partial symbol
8517 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8519 psymbol
.domain
= VAR_DOMAIN
;
8520 psymbol
.aclass
= LOC_STATIC
;
8521 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8522 psymbol
.ginfo
.value
.address
= addr
;
8523 where
= psymbol_placement::GLOBAL
;
8528 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8530 /* Static Variable. Skip symbols whose value we cannot know (those
8531 without location descriptors or constant values). */
8532 if (!has_loc
&& !pdi
->has_const_value
)
8535 psymbol
.domain
= VAR_DOMAIN
;
8536 psymbol
.aclass
= LOC_STATIC
;
8537 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8539 psymbol
.ginfo
.value
.address
= addr
;
8540 where
= psymbol_placement::STATIC
;
8543 case DW_TAG_typedef
:
8544 case DW_TAG_base_type
:
8545 case DW_TAG_subrange_type
:
8546 psymbol
.domain
= VAR_DOMAIN
;
8547 psymbol
.aclass
= LOC_TYPEDEF
;
8548 where
= psymbol_placement::STATIC
;
8550 case DW_TAG_imported_declaration
:
8551 case DW_TAG_namespace
:
8552 psymbol
.domain
= VAR_DOMAIN
;
8553 psymbol
.aclass
= LOC_TYPEDEF
;
8554 where
= psymbol_placement::GLOBAL
;
8557 /* With Fortran 77 there might be a "BLOCK DATA" module
8558 available without any name. If so, we skip the module as it
8559 doesn't bring any value. */
8560 if (actual_name
!= nullptr)
8562 psymbol
.domain
= MODULE_DOMAIN
;
8563 psymbol
.aclass
= LOC_TYPEDEF
;
8564 where
= psymbol_placement::GLOBAL
;
8567 case DW_TAG_class_type
:
8568 case DW_TAG_interface_type
:
8569 case DW_TAG_structure_type
:
8570 case DW_TAG_union_type
:
8571 case DW_TAG_enumeration_type
:
8572 /* Skip external references. The DWARF standard says in the section
8573 about "Structure, Union, and Class Type Entries": "An incomplete
8574 structure, union or class type is represented by a structure,
8575 union or class entry that does not have a byte size attribute
8576 and that has a DW_AT_declaration attribute." */
8577 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8580 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8581 static vs. global. */
8582 psymbol
.domain
= STRUCT_DOMAIN
;
8583 psymbol
.aclass
= LOC_TYPEDEF
;
8584 where
= (cu
->language
== language_cplus
8585 ? psymbol_placement::GLOBAL
8586 : psymbol_placement::STATIC
);
8588 case DW_TAG_enumerator
:
8589 psymbol
.domain
= VAR_DOMAIN
;
8590 psymbol
.aclass
= LOC_CONST
;
8591 where
= (cu
->language
== language_cplus
8592 ? psymbol_placement::GLOBAL
8593 : psymbol_placement::STATIC
);
8599 if (where
.has_value ())
8601 if (built_actual_name
!= nullptr)
8602 actual_name
= objfile
->intern (actual_name
);
8603 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8604 psymbol
.ginfo
.set_linkage_name (actual_name
);
8607 psymbol
.ginfo
.set_demangled_name (actual_name
,
8608 &objfile
->objfile_obstack
);
8609 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8611 add_psymbol_to_list (psymbol
, *where
, objfile
);
8615 /* Read a partial die corresponding to a namespace; also, add a symbol
8616 corresponding to that namespace to the symbol table. NAMESPACE is
8617 the name of the enclosing namespace. */
8620 add_partial_namespace (struct partial_die_info
*pdi
,
8621 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8622 int set_addrmap
, struct dwarf2_cu
*cu
)
8624 /* Add a symbol for the namespace. */
8626 add_partial_symbol (pdi
, cu
);
8628 /* Now scan partial symbols in that namespace. */
8630 if (pdi
->has_children
)
8631 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8634 /* Read a partial die corresponding to a Fortran module. */
8637 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8638 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8640 /* Add a symbol for the namespace. */
8642 add_partial_symbol (pdi
, cu
);
8644 /* Now scan partial symbols in that module. */
8646 if (pdi
->has_children
)
8647 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8650 /* Read a partial die corresponding to a subprogram or an inlined
8651 subprogram and create a partial symbol for that subprogram.
8652 When the CU language allows it, this routine also defines a partial
8653 symbol for each nested subprogram that this subprogram contains.
8654 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8655 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8657 PDI may also be a lexical block, in which case we simply search
8658 recursively for subprograms defined inside that lexical block.
8659 Again, this is only performed when the CU language allows this
8660 type of definitions. */
8663 add_partial_subprogram (struct partial_die_info
*pdi
,
8664 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8665 int set_addrmap
, struct dwarf2_cu
*cu
)
8667 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8669 if (pdi
->has_pc_info
)
8671 if (pdi
->lowpc
< *lowpc
)
8672 *lowpc
= pdi
->lowpc
;
8673 if (pdi
->highpc
> *highpc
)
8674 *highpc
= pdi
->highpc
;
8677 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8678 struct gdbarch
*gdbarch
= objfile
->arch ();
8680 CORE_ADDR this_highpc
;
8681 CORE_ADDR this_lowpc
;
8683 baseaddr
= objfile
->text_section_offset ();
8685 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8686 pdi
->lowpc
+ baseaddr
)
8689 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8690 pdi
->highpc
+ baseaddr
)
8692 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8693 this_lowpc
, this_highpc
- 1,
8694 cu
->per_cu
->v
.psymtab
);
8698 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8700 if (!pdi
->is_declaration
)
8701 /* Ignore subprogram DIEs that do not have a name, they are
8702 illegal. Do not emit a complaint at this point, we will
8703 do so when we convert this psymtab into a symtab. */
8705 add_partial_symbol (pdi
, cu
);
8709 if (! pdi
->has_children
)
8712 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8714 pdi
= pdi
->die_child
;
8718 if (pdi
->tag
== DW_TAG_subprogram
8719 || pdi
->tag
== DW_TAG_inlined_subroutine
8720 || pdi
->tag
== DW_TAG_lexical_block
)
8721 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8722 pdi
= pdi
->die_sibling
;
8727 /* Read a partial die corresponding to an enumeration type. */
8730 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8731 struct dwarf2_cu
*cu
)
8733 struct partial_die_info
*pdi
;
8735 if (enum_pdi
->name (cu
) != NULL
)
8736 add_partial_symbol (enum_pdi
, cu
);
8738 pdi
= enum_pdi
->die_child
;
8741 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8742 complaint (_("malformed enumerator DIE ignored"));
8744 add_partial_symbol (pdi
, cu
);
8745 pdi
= pdi
->die_sibling
;
8749 /* Return the initial uleb128 in the die at INFO_PTR. */
8752 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8754 unsigned int bytes_read
;
8756 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8759 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8760 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8762 Return the corresponding abbrev, or NULL if the number is zero (indicating
8763 an empty DIE). In either case *BYTES_READ will be set to the length of
8764 the initial number. */
8766 static struct abbrev_info
*
8767 peek_die_abbrev (const die_reader_specs
&reader
,
8768 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8770 dwarf2_cu
*cu
= reader
.cu
;
8771 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8772 unsigned int abbrev_number
8773 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8775 if (abbrev_number
== 0)
8778 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8781 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8782 " at offset %s [in module %s]"),
8783 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8784 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8790 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8791 Returns a pointer to the end of a series of DIEs, terminated by an empty
8792 DIE. Any children of the skipped DIEs will also be skipped. */
8794 static const gdb_byte
*
8795 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8799 unsigned int bytes_read
;
8800 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8803 return info_ptr
+ bytes_read
;
8805 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8809 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8810 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8811 abbrev corresponding to that skipped uleb128 should be passed in
8812 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8815 static const gdb_byte
*
8816 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8817 struct abbrev_info
*abbrev
)
8819 unsigned int bytes_read
;
8820 struct attribute attr
;
8821 bfd
*abfd
= reader
->abfd
;
8822 struct dwarf2_cu
*cu
= reader
->cu
;
8823 const gdb_byte
*buffer
= reader
->buffer
;
8824 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8825 unsigned int form
, i
;
8827 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8829 /* The only abbrev we care about is DW_AT_sibling. */
8830 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8833 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8835 if (attr
.form
== DW_FORM_ref_addr
)
8836 complaint (_("ignoring absolute DW_AT_sibling"));
8839 sect_offset off
= attr
.get_ref_die_offset ();
8840 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8842 if (sibling_ptr
< info_ptr
)
8843 complaint (_("DW_AT_sibling points backwards"));
8844 else if (sibling_ptr
> reader
->buffer_end
)
8845 reader
->die_section
->overflow_complaint ();
8851 /* If it isn't DW_AT_sibling, skip this attribute. */
8852 form
= abbrev
->attrs
[i
].form
;
8856 case DW_FORM_ref_addr
:
8857 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8858 and later it is offset sized. */
8859 if (cu
->header
.version
== 2)
8860 info_ptr
+= cu
->header
.addr_size
;
8862 info_ptr
+= cu
->header
.offset_size
;
8864 case DW_FORM_GNU_ref_alt
:
8865 info_ptr
+= cu
->header
.offset_size
;
8868 info_ptr
+= cu
->header
.addr_size
;
8876 case DW_FORM_flag_present
:
8877 case DW_FORM_implicit_const
:
8894 case DW_FORM_ref_sig8
:
8897 case DW_FORM_data16
:
8900 case DW_FORM_string
:
8901 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8902 info_ptr
+= bytes_read
;
8904 case DW_FORM_sec_offset
:
8906 case DW_FORM_GNU_strp_alt
:
8907 info_ptr
+= cu
->header
.offset_size
;
8909 case DW_FORM_exprloc
:
8911 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8912 info_ptr
+= bytes_read
;
8914 case DW_FORM_block1
:
8915 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8917 case DW_FORM_block2
:
8918 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8920 case DW_FORM_block4
:
8921 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8927 case DW_FORM_ref_udata
:
8928 case DW_FORM_GNU_addr_index
:
8929 case DW_FORM_GNU_str_index
:
8930 case DW_FORM_rnglistx
:
8931 case DW_FORM_loclistx
:
8932 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8934 case DW_FORM_indirect
:
8935 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8936 info_ptr
+= bytes_read
;
8937 /* We need to continue parsing from here, so just go back to
8939 goto skip_attribute
;
8942 error (_("Dwarf Error: Cannot handle %s "
8943 "in DWARF reader [in module %s]"),
8944 dwarf_form_name (form
),
8945 bfd_get_filename (abfd
));
8949 if (abbrev
->has_children
)
8950 return skip_children (reader
, info_ptr
);
8955 /* Locate ORIG_PDI's sibling.
8956 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8958 static const gdb_byte
*
8959 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8960 struct partial_die_info
*orig_pdi
,
8961 const gdb_byte
*info_ptr
)
8963 /* Do we know the sibling already? */
8965 if (orig_pdi
->sibling
)
8966 return orig_pdi
->sibling
;
8968 /* Are there any children to deal with? */
8970 if (!orig_pdi
->has_children
)
8973 /* Skip the children the long way. */
8975 return skip_children (reader
, info_ptr
);
8978 /* Expand this partial symbol table into a full symbol table. SELF is
8982 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8984 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8986 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8988 /* If this psymtab is constructed from a debug-only objfile, the
8989 has_section_at_zero flag will not necessarily be correct. We
8990 can get the correct value for this flag by looking at the data
8991 associated with the (presumably stripped) associated objfile. */
8992 if (objfile
->separate_debug_objfile_backlink
)
8994 dwarf2_per_objfile
*per_objfile_backlink
8995 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8997 per_objfile
->per_bfd
->has_section_at_zero
8998 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9001 expand_psymtab (objfile
);
9003 process_cu_includes (per_objfile
);
9006 /* Reading in full CUs. */
9008 /* Add PER_CU to the queue. */
9011 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9012 dwarf2_per_objfile
*per_objfile
,
9013 enum language pretend_language
)
9016 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9019 /* If PER_CU is not yet queued, add it to the queue.
9020 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9022 The result is non-zero if PER_CU was queued, otherwise the result is zero
9023 meaning either PER_CU is already queued or it is already loaded.
9025 N.B. There is an invariant here that if a CU is queued then it is loaded.
9026 The caller is required to load PER_CU if we return non-zero. */
9029 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9030 dwarf2_per_cu_data
*per_cu
,
9031 dwarf2_per_objfile
*per_objfile
,
9032 enum language pretend_language
)
9034 /* We may arrive here during partial symbol reading, if we need full
9035 DIEs to process an unusual case (e.g. template arguments). Do
9036 not queue PER_CU, just tell our caller to load its DIEs. */
9037 if (per_cu
->per_bfd
->reading_partial_symbols
)
9039 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9041 if (cu
== NULL
|| cu
->dies
== NULL
)
9046 /* Mark the dependence relation so that we don't flush PER_CU
9048 if (dependent_cu
!= NULL
)
9049 dwarf2_add_dependence (dependent_cu
, per_cu
);
9051 /* If it's already on the queue, we have nothing to do. */
9055 /* If the compilation unit is already loaded, just mark it as
9057 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9064 /* Add it to the queue. */
9065 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9070 /* Process the queue. */
9073 process_queue (dwarf2_per_objfile
*per_objfile
)
9075 if (dwarf_read_debug
)
9077 fprintf_unfiltered (gdb_stdlog
,
9078 "Expanding one or more symtabs of objfile %s ...\n",
9079 objfile_name (per_objfile
->objfile
));
9082 /* The queue starts out with one item, but following a DIE reference
9083 may load a new CU, adding it to the end of the queue. */
9084 while (!per_objfile
->per_bfd
->queue
.empty ())
9086 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9087 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9089 if (!per_objfile
->symtab_set_p (per_cu
))
9091 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9093 /* Skip dummy CUs. */
9096 unsigned int debug_print_threshold
;
9099 if (per_cu
->is_debug_types
)
9101 struct signatured_type
*sig_type
=
9102 (struct signatured_type
*) per_cu
;
9104 sprintf (buf
, "TU %s at offset %s",
9105 hex_string (sig_type
->signature
),
9106 sect_offset_str (per_cu
->sect_off
));
9107 /* There can be 100s of TUs.
9108 Only print them in verbose mode. */
9109 debug_print_threshold
= 2;
9113 sprintf (buf
, "CU at offset %s",
9114 sect_offset_str (per_cu
->sect_off
));
9115 debug_print_threshold
= 1;
9118 if (dwarf_read_debug
>= debug_print_threshold
)
9119 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9121 if (per_cu
->is_debug_types
)
9122 process_full_type_unit (cu
, item
.pretend_language
);
9124 process_full_comp_unit (cu
, item
.pretend_language
);
9126 if (dwarf_read_debug
>= debug_print_threshold
)
9127 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9132 per_objfile
->per_bfd
->queue
.pop ();
9135 if (dwarf_read_debug
)
9137 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9138 objfile_name (per_objfile
->objfile
));
9142 /* Read in full symbols for PST, and anything it depends on. */
9145 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9147 gdb_assert (!readin_p (objfile
));
9149 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9150 free_cached_comp_units
freer (per_objfile
);
9151 expand_dependencies (objfile
);
9153 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9154 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9157 /* See psympriv.h. */
9160 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9162 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9163 return per_objfile
->symtab_set_p (per_cu_data
);
9166 /* See psympriv.h. */
9169 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9171 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9172 return per_objfile
->get_symtab (per_cu_data
);
9175 /* Trivial hash function for die_info: the hash value of a DIE
9176 is its offset in .debug_info for this objfile. */
9179 die_hash (const void *item
)
9181 const struct die_info
*die
= (const struct die_info
*) item
;
9183 return to_underlying (die
->sect_off
);
9186 /* Trivial comparison function for die_info structures: two DIEs
9187 are equal if they have the same offset. */
9190 die_eq (const void *item_lhs
, const void *item_rhs
)
9192 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9193 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9195 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9198 /* Load the DIEs associated with PER_CU into memory. */
9201 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9202 dwarf2_per_objfile
*per_objfile
,
9204 enum language pretend_language
)
9206 gdb_assert (! this_cu
->is_debug_types
);
9208 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9209 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9213 struct dwarf2_cu
*cu
= reader
.cu
;
9214 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9216 gdb_assert (cu
->die_hash
== NULL
);
9218 htab_create_alloc_ex (cu
->header
.length
/ 12,
9222 &cu
->comp_unit_obstack
,
9223 hashtab_obstack_allocate
,
9224 dummy_obstack_deallocate
);
9226 if (reader
.comp_unit_die
->has_children
)
9227 reader
.comp_unit_die
->child
9228 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9229 &info_ptr
, reader
.comp_unit_die
);
9230 cu
->dies
= reader
.comp_unit_die
;
9231 /* comp_unit_die is not stored in die_hash, no need. */
9233 /* We try not to read any attributes in this function, because not
9234 all CUs needed for references have been loaded yet, and symbol
9235 table processing isn't initialized. But we have to set the CU language,
9236 or we won't be able to build types correctly.
9237 Similarly, if we do not read the producer, we can not apply
9238 producer-specific interpretation. */
9239 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9244 /* Add a DIE to the delayed physname list. */
9247 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9248 const char *name
, struct die_info
*die
,
9249 struct dwarf2_cu
*cu
)
9251 struct delayed_method_info mi
;
9253 mi
.fnfield_index
= fnfield_index
;
9257 cu
->method_list
.push_back (mi
);
9260 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9261 "const" / "volatile". If so, decrements LEN by the length of the
9262 modifier and return true. Otherwise return false. */
9266 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9268 size_t mod_len
= sizeof (mod
) - 1;
9269 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9277 /* Compute the physnames of any methods on the CU's method list.
9279 The computation of method physnames is delayed in order to avoid the
9280 (bad) condition that one of the method's formal parameters is of an as yet
9284 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9286 /* Only C++ delays computing physnames. */
9287 if (cu
->method_list
.empty ())
9289 gdb_assert (cu
->language
== language_cplus
);
9291 for (const delayed_method_info
&mi
: cu
->method_list
)
9293 const char *physname
;
9294 struct fn_fieldlist
*fn_flp
9295 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9296 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9297 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9298 = physname
? physname
: "";
9300 /* Since there's no tag to indicate whether a method is a
9301 const/volatile overload, extract that information out of the
9303 if (physname
!= NULL
)
9305 size_t len
= strlen (physname
);
9309 if (physname
[len
] == ')') /* shortcut */
9311 else if (check_modifier (physname
, len
, " const"))
9312 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9313 else if (check_modifier (physname
, len
, " volatile"))
9314 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9321 /* The list is no longer needed. */
9322 cu
->method_list
.clear ();
9325 /* Go objects should be embedded in a DW_TAG_module DIE,
9326 and it's not clear if/how imported objects will appear.
9327 To keep Go support simple until that's worked out,
9328 go back through what we've read and create something usable.
9329 We could do this while processing each DIE, and feels kinda cleaner,
9330 but that way is more invasive.
9331 This is to, for example, allow the user to type "p var" or "b main"
9332 without having to specify the package name, and allow lookups
9333 of module.object to work in contexts that use the expression
9337 fixup_go_packaging (struct dwarf2_cu
*cu
)
9339 gdb::unique_xmalloc_ptr
<char> package_name
;
9340 struct pending
*list
;
9343 for (list
= *cu
->get_builder ()->get_global_symbols ();
9347 for (i
= 0; i
< list
->nsyms
; ++i
)
9349 struct symbol
*sym
= list
->symbol
[i
];
9351 if (sym
->language () == language_go
9352 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9354 gdb::unique_xmalloc_ptr
<char> this_package_name
9355 (go_symbol_package_name (sym
));
9357 if (this_package_name
== NULL
)
9359 if (package_name
== NULL
)
9360 package_name
= std::move (this_package_name
);
9363 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9364 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9365 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9366 (symbol_symtab (sym
) != NULL
9367 ? symtab_to_filename_for_display
9368 (symbol_symtab (sym
))
9369 : objfile_name (objfile
)),
9370 this_package_name
.get (), package_name
.get ());
9376 if (package_name
!= NULL
)
9378 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9379 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9380 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9381 saved_package_name
);
9384 sym
= new (&objfile
->objfile_obstack
) symbol
;
9385 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9386 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9387 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9388 e.g., "main" finds the "main" module and not C's main(). */
9389 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9390 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9391 SYMBOL_TYPE (sym
) = type
;
9393 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9397 /* Allocate a fully-qualified name consisting of the two parts on the
9401 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9403 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9406 /* A helper that allocates a variant part to attach to a Rust enum
9407 type. OBSTACK is where the results should be allocated. TYPE is
9408 the type we're processing. DISCRIMINANT_INDEX is the index of the
9409 discriminant. It must be the index of one of the fields of TYPE.
9410 DEFAULT_INDEX is the index of the default field; or -1 if there is
9411 no default. RANGES is indexed by "effective" field number (the
9412 field index, but omitting the discriminant and default fields) and
9413 must hold the discriminant values used by the variants. Note that
9414 RANGES must have a lifetime at least as long as OBSTACK -- either
9415 already allocated on it, or static. */
9418 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9419 int discriminant_index
, int default_index
,
9420 gdb::array_view
<discriminant_range
> ranges
)
9422 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9423 must be handled by the caller. */
9424 gdb_assert (discriminant_index
>= 0
9425 && discriminant_index
< type
->num_fields ());
9426 gdb_assert (default_index
== -1
9427 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9429 /* We have one variant for each non-discriminant field. */
9430 int n_variants
= type
->num_fields () - 1;
9432 variant
*variants
= new (obstack
) variant
[n_variants
];
9435 for (int i
= 0; i
< type
->num_fields (); ++i
)
9437 if (i
== discriminant_index
)
9440 variants
[var_idx
].first_field
= i
;
9441 variants
[var_idx
].last_field
= i
+ 1;
9443 /* The default field does not need a range, but other fields do.
9444 We skipped the discriminant above. */
9445 if (i
!= default_index
)
9447 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9454 gdb_assert (range_idx
== ranges
.size ());
9455 gdb_assert (var_idx
== n_variants
);
9457 variant_part
*part
= new (obstack
) variant_part
;
9458 part
->discriminant_index
= discriminant_index
;
9459 part
->is_unsigned
= TYPE_UNSIGNED (type
->field (discriminant_index
).type ());
9460 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9462 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9463 gdb::array_view
<variant_part
> *prop_value
9464 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9466 struct dynamic_prop prop
;
9467 prop
.set_variant_parts (prop_value
);
9469 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9472 /* Some versions of rustc emitted enums in an unusual way.
9474 Ordinary enums were emitted as unions. The first element of each
9475 structure in the union was named "RUST$ENUM$DISR". This element
9476 held the discriminant.
9478 These versions of Rust also implemented the "non-zero"
9479 optimization. When the enum had two values, and one is empty and
9480 the other holds a pointer that cannot be zero, the pointer is used
9481 as the discriminant, with a zero value meaning the empty variant.
9482 Here, the union's first member is of the form
9483 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9484 where the fieldnos are the indices of the fields that should be
9485 traversed in order to find the field (which may be several fields deep)
9486 and the variantname is the name of the variant of the case when the
9489 This function recognizes whether TYPE is of one of these forms,
9490 and, if so, smashes it to be a variant type. */
9493 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9495 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9497 /* We don't need to deal with empty enums. */
9498 if (type
->num_fields () == 0)
9501 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9502 if (type
->num_fields () == 1
9503 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9505 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9507 /* Decode the field name to find the offset of the
9509 ULONGEST bit_offset
= 0;
9510 struct type
*field_type
= type
->field (0).type ();
9511 while (name
[0] >= '0' && name
[0] <= '9')
9514 unsigned long index
= strtoul (name
, &tail
, 10);
9517 || index
>= field_type
->num_fields ()
9518 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9519 != FIELD_LOC_KIND_BITPOS
))
9521 complaint (_("Could not parse Rust enum encoding string \"%s\""
9523 TYPE_FIELD_NAME (type
, 0),
9524 objfile_name (objfile
));
9529 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9530 field_type
= field_type
->field (index
).type ();
9533 /* Smash this type to be a structure type. We have to do this
9534 because the type has already been recorded. */
9535 type
->set_code (TYPE_CODE_STRUCT
);
9536 type
->set_num_fields (3);
9537 /* Save the field we care about. */
9538 struct field saved_field
= type
->field (0);
9540 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9542 /* Put the discriminant at index 0. */
9543 type
->field (0).set_type (field_type
);
9544 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9545 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9546 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9548 /* The order of fields doesn't really matter, so put the real
9549 field at index 1 and the data-less field at index 2. */
9550 type
->field (1) = saved_field
;
9551 TYPE_FIELD_NAME (type
, 1)
9552 = rust_last_path_segment (type
->field (1).type ()->name ());
9553 type
->field (1).type ()->set_name
9554 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9555 TYPE_FIELD_NAME (type
, 1)));
9557 const char *dataless_name
9558 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9560 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9562 type
->field (2).set_type (dataless_type
);
9563 /* NAME points into the original discriminant name, which
9564 already has the correct lifetime. */
9565 TYPE_FIELD_NAME (type
, 2) = name
;
9566 SET_FIELD_BITPOS (type
->field (2), 0);
9568 /* Indicate that this is a variant type. */
9569 static discriminant_range ranges
[1] = { { 0, 0 } };
9570 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9572 /* A union with a single anonymous field is probably an old-style
9574 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9576 /* Smash this type to be a structure type. We have to do this
9577 because the type has already been recorded. */
9578 type
->set_code (TYPE_CODE_STRUCT
);
9580 struct type
*field_type
= type
->field (0).type ();
9581 const char *variant_name
9582 = rust_last_path_segment (field_type
->name ());
9583 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9584 field_type
->set_name
9585 (rust_fully_qualify (&objfile
->objfile_obstack
,
9586 type
->name (), variant_name
));
9590 struct type
*disr_type
= nullptr;
9591 for (int i
= 0; i
< type
->num_fields (); ++i
)
9593 disr_type
= type
->field (i
).type ();
9595 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9597 /* All fields of a true enum will be structs. */
9600 else if (disr_type
->num_fields () == 0)
9602 /* Could be data-less variant, so keep going. */
9603 disr_type
= nullptr;
9605 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9606 "RUST$ENUM$DISR") != 0)
9608 /* Not a Rust enum. */
9618 /* If we got here without a discriminant, then it's probably
9620 if (disr_type
== nullptr)
9623 /* Smash this type to be a structure type. We have to do this
9624 because the type has already been recorded. */
9625 type
->set_code (TYPE_CODE_STRUCT
);
9627 /* Make space for the discriminant field. */
9628 struct field
*disr_field
= &disr_type
->field (0);
9630 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9631 * sizeof (struct field
)));
9632 memcpy (new_fields
+ 1, type
->fields (),
9633 type
->num_fields () * sizeof (struct field
));
9634 type
->set_fields (new_fields
);
9635 type
->set_num_fields (type
->num_fields () + 1);
9637 /* Install the discriminant at index 0 in the union. */
9638 type
->field (0) = *disr_field
;
9639 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9640 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9642 /* We need a way to find the correct discriminant given a
9643 variant name. For convenience we build a map here. */
9644 struct type
*enum_type
= disr_field
->type ();
9645 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9646 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9648 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9651 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9652 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9656 int n_fields
= type
->num_fields ();
9657 /* We don't need a range entry for the discriminant, but we do
9658 need one for every other field, as there is no default
9660 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9663 /* Skip the discriminant here. */
9664 for (int i
= 1; i
< n_fields
; ++i
)
9666 /* Find the final word in the name of this variant's type.
9667 That name can be used to look up the correct
9669 const char *variant_name
9670 = rust_last_path_segment (type
->field (i
).type ()->name ());
9672 auto iter
= discriminant_map
.find (variant_name
);
9673 if (iter
!= discriminant_map
.end ())
9675 ranges
[i
].low
= iter
->second
;
9676 ranges
[i
].high
= iter
->second
;
9679 /* Remove the discriminant field, if it exists. */
9680 struct type
*sub_type
= type
->field (i
).type ();
9681 if (sub_type
->num_fields () > 0)
9683 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9684 sub_type
->set_fields (sub_type
->fields () + 1);
9686 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9688 (rust_fully_qualify (&objfile
->objfile_obstack
,
9689 type
->name (), variant_name
));
9692 /* Indicate that this is a variant type. */
9693 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9694 gdb::array_view
<discriminant_range
> (ranges
,
9699 /* Rewrite some Rust unions to be structures with variants parts. */
9702 rust_union_quirks (struct dwarf2_cu
*cu
)
9704 gdb_assert (cu
->language
== language_rust
);
9705 for (type
*type_
: cu
->rust_unions
)
9706 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9707 /* We don't need this any more. */
9708 cu
->rust_unions
.clear ();
9713 type_unit_group_unshareable
*
9714 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9716 auto iter
= this->m_type_units
.find (tu_group
);
9717 if (iter
!= this->m_type_units
.end ())
9718 return iter
->second
.get ();
9720 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9721 type_unit_group_unshareable
*result
= uniq
.get ();
9722 this->m_type_units
[tu_group
] = std::move (uniq
);
9727 dwarf2_per_objfile::get_type_for_signatured_type
9728 (signatured_type
*sig_type
) const
9730 auto iter
= this->m_type_map
.find (sig_type
);
9731 if (iter
== this->m_type_map
.end ())
9734 return iter
->second
;
9737 void dwarf2_per_objfile::set_type_for_signatured_type
9738 (signatured_type
*sig_type
, struct type
*type
)
9740 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9742 this->m_type_map
[sig_type
] = type
;
9745 /* A helper function for computing the list of all symbol tables
9746 included by PER_CU. */
9749 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9750 htab_t all_children
, htab_t all_type_symtabs
,
9751 dwarf2_per_cu_data
*per_cu
,
9752 dwarf2_per_objfile
*per_objfile
,
9753 struct compunit_symtab
*immediate_parent
)
9755 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9758 /* This inclusion and its children have been processed. */
9764 /* Only add a CU if it has a symbol table. */
9765 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9768 /* If this is a type unit only add its symbol table if we haven't
9769 seen it yet (type unit per_cu's can share symtabs). */
9770 if (per_cu
->is_debug_types
)
9772 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9776 result
->push_back (cust
);
9777 if (cust
->user
== NULL
)
9778 cust
->user
= immediate_parent
;
9783 result
->push_back (cust
);
9784 if (cust
->user
== NULL
)
9785 cust
->user
= immediate_parent
;
9789 if (!per_cu
->imported_symtabs_empty ())
9790 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9792 recursively_compute_inclusions (result
, all_children
,
9793 all_type_symtabs
, ptr
, per_objfile
,
9798 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9802 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9803 dwarf2_per_objfile
*per_objfile
)
9805 gdb_assert (! per_cu
->is_debug_types
);
9807 if (!per_cu
->imported_symtabs_empty ())
9810 std::vector
<compunit_symtab
*> result_symtabs
;
9811 htab_t all_children
, all_type_symtabs
;
9812 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9814 /* If we don't have a symtab, we can just skip this case. */
9818 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9819 NULL
, xcalloc
, xfree
);
9820 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9821 NULL
, xcalloc
, xfree
);
9823 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9825 recursively_compute_inclusions (&result_symtabs
, all_children
,
9826 all_type_symtabs
, ptr
, per_objfile
,
9830 /* Now we have a transitive closure of all the included symtabs. */
9831 len
= result_symtabs
.size ();
9833 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9834 struct compunit_symtab
*, len
+ 1);
9835 memcpy (cust
->includes
, result_symtabs
.data (),
9836 len
* sizeof (compunit_symtab
*));
9837 cust
->includes
[len
] = NULL
;
9839 htab_delete (all_children
);
9840 htab_delete (all_type_symtabs
);
9844 /* Compute the 'includes' field for the symtabs of all the CUs we just
9848 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9850 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9852 if (! iter
->is_debug_types
)
9853 compute_compunit_symtab_includes (iter
, per_objfile
);
9856 per_objfile
->per_bfd
->just_read_cus
.clear ();
9859 /* Generate full symbol information for CU, whose DIEs have
9860 already been loaded into memory. */
9863 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9865 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9866 struct objfile
*objfile
= per_objfile
->objfile
;
9867 struct gdbarch
*gdbarch
= objfile
->arch ();
9868 CORE_ADDR lowpc
, highpc
;
9869 struct compunit_symtab
*cust
;
9871 struct block
*static_block
;
9874 baseaddr
= objfile
->text_section_offset ();
9876 /* Clear the list here in case something was left over. */
9877 cu
->method_list
.clear ();
9879 cu
->language
= pretend_language
;
9880 cu
->language_defn
= language_def (cu
->language
);
9882 /* Do line number decoding in read_file_scope () */
9883 process_die (cu
->dies
, cu
);
9885 /* For now fudge the Go package. */
9886 if (cu
->language
== language_go
)
9887 fixup_go_packaging (cu
);
9889 /* Now that we have processed all the DIEs in the CU, all the types
9890 should be complete, and it should now be safe to compute all of the
9892 compute_delayed_physnames (cu
);
9894 if (cu
->language
== language_rust
)
9895 rust_union_quirks (cu
);
9897 /* Some compilers don't define a DW_AT_high_pc attribute for the
9898 compilation unit. If the DW_AT_high_pc is missing, synthesize
9899 it, by scanning the DIE's below the compilation unit. */
9900 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9902 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9903 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9905 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9906 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9907 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9908 addrmap to help ensure it has an accurate map of pc values belonging to
9910 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9912 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9913 SECT_OFF_TEXT (objfile
),
9918 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9920 /* Set symtab language to language from DW_AT_language. If the
9921 compilation is from a C file generated by language preprocessors, do
9922 not set the language if it was already deduced by start_subfile. */
9923 if (!(cu
->language
== language_c
9924 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9925 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9927 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9928 produce DW_AT_location with location lists but it can be possibly
9929 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9930 there were bugs in prologue debug info, fixed later in GCC-4.5
9931 by "unwind info for epilogues" patch (which is not directly related).
9933 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9934 needed, it would be wrong due to missing DW_AT_producer there.
9936 Still one can confuse GDB by using non-standard GCC compilation
9937 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9939 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9940 cust
->locations_valid
= 1;
9942 if (gcc_4_minor
>= 5)
9943 cust
->epilogue_unwind_valid
= 1;
9945 cust
->call_site_htab
= cu
->call_site_htab
;
9948 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9950 /* Push it for inclusion processing later. */
9951 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9953 /* Not needed any more. */
9954 cu
->reset_builder ();
9957 /* Generate full symbol information for type unit CU, whose DIEs have
9958 already been loaded into memory. */
9961 process_full_type_unit (dwarf2_cu
*cu
,
9962 enum language pretend_language
)
9964 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9965 struct objfile
*objfile
= per_objfile
->objfile
;
9966 struct compunit_symtab
*cust
;
9967 struct signatured_type
*sig_type
;
9969 gdb_assert (cu
->per_cu
->is_debug_types
);
9970 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9972 /* Clear the list here in case something was left over. */
9973 cu
->method_list
.clear ();
9975 cu
->language
= pretend_language
;
9976 cu
->language_defn
= language_def (cu
->language
);
9978 /* The symbol tables are set up in read_type_unit_scope. */
9979 process_die (cu
->dies
, cu
);
9981 /* For now fudge the Go package. */
9982 if (cu
->language
== language_go
)
9983 fixup_go_packaging (cu
);
9985 /* Now that we have processed all the DIEs in the CU, all the types
9986 should be complete, and it should now be safe to compute all of the
9988 compute_delayed_physnames (cu
);
9990 if (cu
->language
== language_rust
)
9991 rust_union_quirks (cu
);
9993 /* TUs share symbol tables.
9994 If this is the first TU to use this symtab, complete the construction
9995 of it with end_expandable_symtab. Otherwise, complete the addition of
9996 this TU's symbols to the existing symtab. */
9997 type_unit_group_unshareable
*tug_unshare
=
9998 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9999 if (tug_unshare
->compunit_symtab
== NULL
)
10001 buildsym_compunit
*builder
= cu
->get_builder ();
10002 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10003 tug_unshare
->compunit_symtab
= cust
;
10007 /* Set symtab language to language from DW_AT_language. If the
10008 compilation is from a C file generated by language preprocessors,
10009 do not set the language if it was already deduced by
10011 if (!(cu
->language
== language_c
10012 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10013 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10018 cu
->get_builder ()->augment_type_symtab ();
10019 cust
= tug_unshare
->compunit_symtab
;
10022 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10024 /* Not needed any more. */
10025 cu
->reset_builder ();
10028 /* Process an imported unit DIE. */
10031 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10033 struct attribute
*attr
;
10035 /* For now we don't handle imported units in type units. */
10036 if (cu
->per_cu
->is_debug_types
)
10038 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10039 " supported in type units [in module %s]"),
10040 objfile_name (cu
->per_objfile
->objfile
));
10043 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10046 sect_offset sect_off
= attr
->get_ref_die_offset ();
10047 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10048 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10049 dwarf2_per_cu_data
*per_cu
10050 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10052 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10053 into another compilation unit, at root level. Regard this as a hint,
10055 if (die
->parent
&& die
->parent
->parent
== NULL
10056 && per_cu
->unit_type
== DW_UT_compile
10057 && per_cu
->lang
== language_cplus
)
10060 /* If necessary, add it to the queue and load its DIEs. */
10061 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10062 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10064 cu
->per_cu
->imported_symtabs_push (per_cu
);
10068 /* RAII object that represents a process_die scope: i.e.,
10069 starts/finishes processing a DIE. */
10070 class process_die_scope
10073 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10074 : m_die (die
), m_cu (cu
)
10076 /* We should only be processing DIEs not already in process. */
10077 gdb_assert (!m_die
->in_process
);
10078 m_die
->in_process
= true;
10081 ~process_die_scope ()
10083 m_die
->in_process
= false;
10085 /* If we're done processing the DIE for the CU that owns the line
10086 header, we don't need the line header anymore. */
10087 if (m_cu
->line_header_die_owner
== m_die
)
10089 delete m_cu
->line_header
;
10090 m_cu
->line_header
= NULL
;
10091 m_cu
->line_header_die_owner
= NULL
;
10100 /* Process a die and its children. */
10103 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10105 process_die_scope
scope (die
, cu
);
10109 case DW_TAG_padding
:
10111 case DW_TAG_compile_unit
:
10112 case DW_TAG_partial_unit
:
10113 read_file_scope (die
, cu
);
10115 case DW_TAG_type_unit
:
10116 read_type_unit_scope (die
, cu
);
10118 case DW_TAG_subprogram
:
10119 /* Nested subprograms in Fortran get a prefix. */
10120 if (cu
->language
== language_fortran
10121 && die
->parent
!= NULL
10122 && die
->parent
->tag
== DW_TAG_subprogram
)
10123 cu
->processing_has_namespace_info
= true;
10124 /* Fall through. */
10125 case DW_TAG_inlined_subroutine
:
10126 read_func_scope (die
, cu
);
10128 case DW_TAG_lexical_block
:
10129 case DW_TAG_try_block
:
10130 case DW_TAG_catch_block
:
10131 read_lexical_block_scope (die
, cu
);
10133 case DW_TAG_call_site
:
10134 case DW_TAG_GNU_call_site
:
10135 read_call_site_scope (die
, cu
);
10137 case DW_TAG_class_type
:
10138 case DW_TAG_interface_type
:
10139 case DW_TAG_structure_type
:
10140 case DW_TAG_union_type
:
10141 process_structure_scope (die
, cu
);
10143 case DW_TAG_enumeration_type
:
10144 process_enumeration_scope (die
, cu
);
10147 /* These dies have a type, but processing them does not create
10148 a symbol or recurse to process the children. Therefore we can
10149 read them on-demand through read_type_die. */
10150 case DW_TAG_subroutine_type
:
10151 case DW_TAG_set_type
:
10152 case DW_TAG_array_type
:
10153 case DW_TAG_pointer_type
:
10154 case DW_TAG_ptr_to_member_type
:
10155 case DW_TAG_reference_type
:
10156 case DW_TAG_rvalue_reference_type
:
10157 case DW_TAG_string_type
:
10160 case DW_TAG_base_type
:
10161 case DW_TAG_subrange_type
:
10162 case DW_TAG_typedef
:
10163 /* Add a typedef symbol for the type definition, if it has a
10165 new_symbol (die
, read_type_die (die
, cu
), cu
);
10167 case DW_TAG_common_block
:
10168 read_common_block (die
, cu
);
10170 case DW_TAG_common_inclusion
:
10172 case DW_TAG_namespace
:
10173 cu
->processing_has_namespace_info
= true;
10174 read_namespace (die
, cu
);
10176 case DW_TAG_module
:
10177 cu
->processing_has_namespace_info
= true;
10178 read_module (die
, cu
);
10180 case DW_TAG_imported_declaration
:
10181 cu
->processing_has_namespace_info
= true;
10182 if (read_namespace_alias (die
, cu
))
10184 /* The declaration is not a global namespace alias. */
10185 /* Fall through. */
10186 case DW_TAG_imported_module
:
10187 cu
->processing_has_namespace_info
= true;
10188 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10189 || cu
->language
!= language_fortran
))
10190 complaint (_("Tag '%s' has unexpected children"),
10191 dwarf_tag_name (die
->tag
));
10192 read_import_statement (die
, cu
);
10195 case DW_TAG_imported_unit
:
10196 process_imported_unit_die (die
, cu
);
10199 case DW_TAG_variable
:
10200 read_variable (die
, cu
);
10204 new_symbol (die
, NULL
, cu
);
10209 /* DWARF name computation. */
10211 /* A helper function for dwarf2_compute_name which determines whether DIE
10212 needs to have the name of the scope prepended to the name listed in the
10216 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10218 struct attribute
*attr
;
10222 case DW_TAG_namespace
:
10223 case DW_TAG_typedef
:
10224 case DW_TAG_class_type
:
10225 case DW_TAG_interface_type
:
10226 case DW_TAG_structure_type
:
10227 case DW_TAG_union_type
:
10228 case DW_TAG_enumeration_type
:
10229 case DW_TAG_enumerator
:
10230 case DW_TAG_subprogram
:
10231 case DW_TAG_inlined_subroutine
:
10232 case DW_TAG_member
:
10233 case DW_TAG_imported_declaration
:
10236 case DW_TAG_variable
:
10237 case DW_TAG_constant
:
10238 /* We only need to prefix "globally" visible variables. These include
10239 any variable marked with DW_AT_external or any variable that
10240 lives in a namespace. [Variables in anonymous namespaces
10241 require prefixing, but they are not DW_AT_external.] */
10243 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10245 struct dwarf2_cu
*spec_cu
= cu
;
10247 return die_needs_namespace (die_specification (die
, &spec_cu
),
10251 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10252 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10253 && die
->parent
->tag
!= DW_TAG_module
)
10255 /* A variable in a lexical block of some kind does not need a
10256 namespace, even though in C++ such variables may be external
10257 and have a mangled name. */
10258 if (die
->parent
->tag
== DW_TAG_lexical_block
10259 || die
->parent
->tag
== DW_TAG_try_block
10260 || die
->parent
->tag
== DW_TAG_catch_block
10261 || die
->parent
->tag
== DW_TAG_subprogram
)
10270 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10271 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10272 defined for the given DIE. */
10274 static struct attribute
*
10275 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10277 struct attribute
*attr
;
10279 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10281 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10286 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10287 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10288 defined for the given DIE. */
10290 static const char *
10291 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10293 const char *linkage_name
;
10295 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10296 if (linkage_name
== NULL
)
10297 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10299 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10300 See https://github.com/rust-lang/rust/issues/32925. */
10301 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10302 && strchr (linkage_name
, '{') != NULL
)
10303 linkage_name
= NULL
;
10305 return linkage_name
;
10308 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10309 compute the physname for the object, which include a method's:
10310 - formal parameters (C++),
10311 - receiver type (Go),
10313 The term "physname" is a bit confusing.
10314 For C++, for example, it is the demangled name.
10315 For Go, for example, it's the mangled name.
10317 For Ada, return the DIE's linkage name rather than the fully qualified
10318 name. PHYSNAME is ignored..
10320 The result is allocated on the objfile->per_bfd's obstack and
10323 static const char *
10324 dwarf2_compute_name (const char *name
,
10325 struct die_info
*die
, struct dwarf2_cu
*cu
,
10328 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10331 name
= dwarf2_name (die
, cu
);
10333 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10334 but otherwise compute it by typename_concat inside GDB.
10335 FIXME: Actually this is not really true, or at least not always true.
10336 It's all very confusing. compute_and_set_names doesn't try to demangle
10337 Fortran names because there is no mangling standard. So new_symbol
10338 will set the demangled name to the result of dwarf2_full_name, and it is
10339 the demangled name that GDB uses if it exists. */
10340 if (cu
->language
== language_ada
10341 || (cu
->language
== language_fortran
&& physname
))
10343 /* For Ada unit, we prefer the linkage name over the name, as
10344 the former contains the exported name, which the user expects
10345 to be able to reference. Ideally, we want the user to be able
10346 to reference this entity using either natural or linkage name,
10347 but we haven't started looking at this enhancement yet. */
10348 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10350 if (linkage_name
!= NULL
)
10351 return linkage_name
;
10354 /* These are the only languages we know how to qualify names in. */
10356 && (cu
->language
== language_cplus
10357 || cu
->language
== language_fortran
|| cu
->language
== language_d
10358 || cu
->language
== language_rust
))
10360 if (die_needs_namespace (die
, cu
))
10362 const char *prefix
;
10363 const char *canonical_name
= NULL
;
10367 prefix
= determine_prefix (die
, cu
);
10368 if (*prefix
!= '\0')
10370 gdb::unique_xmalloc_ptr
<char> prefixed_name
10371 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10373 buf
.puts (prefixed_name
.get ());
10378 /* Template parameters may be specified in the DIE's DW_AT_name, or
10379 as children with DW_TAG_template_type_param or
10380 DW_TAG_value_type_param. If the latter, add them to the name
10381 here. If the name already has template parameters, then
10382 skip this step; some versions of GCC emit both, and
10383 it is more efficient to use the pre-computed name.
10385 Something to keep in mind about this process: it is very
10386 unlikely, or in some cases downright impossible, to produce
10387 something that will match the mangled name of a function.
10388 If the definition of the function has the same debug info,
10389 we should be able to match up with it anyway. But fallbacks
10390 using the minimal symbol, for instance to find a method
10391 implemented in a stripped copy of libstdc++, will not work.
10392 If we do not have debug info for the definition, we will have to
10393 match them up some other way.
10395 When we do name matching there is a related problem with function
10396 templates; two instantiated function templates are allowed to
10397 differ only by their return types, which we do not add here. */
10399 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10401 struct attribute
*attr
;
10402 struct die_info
*child
;
10405 die
->building_fullname
= 1;
10407 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10411 const gdb_byte
*bytes
;
10412 struct dwarf2_locexpr_baton
*baton
;
10415 if (child
->tag
!= DW_TAG_template_type_param
10416 && child
->tag
!= DW_TAG_template_value_param
)
10427 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10430 complaint (_("template parameter missing DW_AT_type"));
10431 buf
.puts ("UNKNOWN_TYPE");
10434 type
= die_type (child
, cu
);
10436 if (child
->tag
== DW_TAG_template_type_param
)
10438 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10439 &type_print_raw_options
);
10443 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10446 complaint (_("template parameter missing "
10447 "DW_AT_const_value"));
10448 buf
.puts ("UNKNOWN_VALUE");
10452 dwarf2_const_value_attr (attr
, type
, name
,
10453 &cu
->comp_unit_obstack
, cu
,
10454 &value
, &bytes
, &baton
);
10456 if (TYPE_NOSIGN (type
))
10457 /* GDB prints characters as NUMBER 'CHAR'. If that's
10458 changed, this can use value_print instead. */
10459 c_printchar (value
, type
, &buf
);
10462 struct value_print_options opts
;
10465 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10469 baton
->per_objfile
);
10470 else if (bytes
!= NULL
)
10472 v
= allocate_value (type
);
10473 memcpy (value_contents_writeable (v
), bytes
,
10474 TYPE_LENGTH (type
));
10477 v
= value_from_longest (type
, value
);
10479 /* Specify decimal so that we do not depend on
10481 get_formatted_print_options (&opts
, 'd');
10483 value_print (v
, &buf
, &opts
);
10488 die
->building_fullname
= 0;
10492 /* Close the argument list, with a space if necessary
10493 (nested templates). */
10494 if (!buf
.empty () && buf
.string ().back () == '>')
10501 /* For C++ methods, append formal parameter type
10502 information, if PHYSNAME. */
10504 if (physname
&& die
->tag
== DW_TAG_subprogram
10505 && cu
->language
== language_cplus
)
10507 struct type
*type
= read_type_die (die
, cu
);
10509 c_type_print_args (type
, &buf
, 1, cu
->language
,
10510 &type_print_raw_options
);
10512 if (cu
->language
== language_cplus
)
10514 /* Assume that an artificial first parameter is
10515 "this", but do not crash if it is not. RealView
10516 marks unnamed (and thus unused) parameters as
10517 artificial; there is no way to differentiate
10519 if (type
->num_fields () > 0
10520 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10521 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10522 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10523 buf
.puts (" const");
10527 const std::string
&intermediate_name
= buf
.string ();
10529 if (cu
->language
== language_cplus
)
10531 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10534 /* If we only computed INTERMEDIATE_NAME, or if
10535 INTERMEDIATE_NAME is already canonical, then we need to
10537 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10538 name
= objfile
->intern (intermediate_name
);
10540 name
= canonical_name
;
10547 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10548 If scope qualifiers are appropriate they will be added. The result
10549 will be allocated on the storage_obstack, or NULL if the DIE does
10550 not have a name. NAME may either be from a previous call to
10551 dwarf2_name or NULL.
10553 The output string will be canonicalized (if C++). */
10555 static const char *
10556 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10558 return dwarf2_compute_name (name
, die
, cu
, 0);
10561 /* Construct a physname for the given DIE in CU. NAME may either be
10562 from a previous call to dwarf2_name or NULL. The result will be
10563 allocated on the objfile_objstack or NULL if the DIE does not have a
10566 The output string will be canonicalized (if C++). */
10568 static const char *
10569 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10571 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10572 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10575 /* In this case dwarf2_compute_name is just a shortcut not building anything
10577 if (!die_needs_namespace (die
, cu
))
10578 return dwarf2_compute_name (name
, die
, cu
, 1);
10580 if (cu
->language
!= language_rust
)
10581 mangled
= dw2_linkage_name (die
, cu
);
10583 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10585 gdb::unique_xmalloc_ptr
<char> demangled
;
10586 if (mangled
!= NULL
)
10589 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10591 /* Do nothing (do not demangle the symbol name). */
10593 else if (cu
->language
== language_go
)
10595 /* This is a lie, but we already lie to the caller new_symbol.
10596 new_symbol assumes we return the mangled name.
10597 This just undoes that lie until things are cleaned up. */
10601 /* Use DMGL_RET_DROP for C++ template functions to suppress
10602 their return type. It is easier for GDB users to search
10603 for such functions as `name(params)' than `long name(params)'.
10604 In such case the minimal symbol names do not match the full
10605 symbol names but for template functions there is never a need
10606 to look up their definition from their declaration so
10607 the only disadvantage remains the minimal symbol variant
10608 `long name(params)' does not have the proper inferior type. */
10609 demangled
.reset (gdb_demangle (mangled
,
10610 (DMGL_PARAMS
| DMGL_ANSI
10611 | DMGL_RET_DROP
)));
10614 canon
= demangled
.get ();
10622 if (canon
== NULL
|| check_physname
)
10624 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10626 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10628 /* It may not mean a bug in GDB. The compiler could also
10629 compute DW_AT_linkage_name incorrectly. But in such case
10630 GDB would need to be bug-to-bug compatible. */
10632 complaint (_("Computed physname <%s> does not match demangled <%s> "
10633 "(from linkage <%s>) - DIE at %s [in module %s]"),
10634 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10635 objfile_name (objfile
));
10637 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10638 is available here - over computed PHYSNAME. It is safer
10639 against both buggy GDB and buggy compilers. */
10653 retval
= objfile
->intern (retval
);
10658 /* Inspect DIE in CU for a namespace alias. If one exists, record
10659 a new symbol for it.
10661 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10664 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10666 struct attribute
*attr
;
10668 /* If the die does not have a name, this is not a namespace
10670 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10674 struct die_info
*d
= die
;
10675 struct dwarf2_cu
*imported_cu
= cu
;
10677 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10678 keep inspecting DIEs until we hit the underlying import. */
10679 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10680 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10682 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10686 d
= follow_die_ref (d
, attr
, &imported_cu
);
10687 if (d
->tag
!= DW_TAG_imported_declaration
)
10691 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10693 complaint (_("DIE at %s has too many recursively imported "
10694 "declarations"), sect_offset_str (d
->sect_off
));
10701 sect_offset sect_off
= attr
->get_ref_die_offset ();
10703 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10704 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10706 /* This declaration is a global namespace alias. Add
10707 a symbol for it whose type is the aliased namespace. */
10708 new_symbol (die
, type
, cu
);
10717 /* Return the using directives repository (global or local?) to use in the
10718 current context for CU.
10720 For Ada, imported declarations can materialize renamings, which *may* be
10721 global. However it is impossible (for now?) in DWARF to distinguish
10722 "external" imported declarations and "static" ones. As all imported
10723 declarations seem to be static in all other languages, make them all CU-wide
10724 global only in Ada. */
10726 static struct using_direct
**
10727 using_directives (struct dwarf2_cu
*cu
)
10729 if (cu
->language
== language_ada
10730 && cu
->get_builder ()->outermost_context_p ())
10731 return cu
->get_builder ()->get_global_using_directives ();
10733 return cu
->get_builder ()->get_local_using_directives ();
10736 /* Read the import statement specified by the given die and record it. */
10739 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10741 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10742 struct attribute
*import_attr
;
10743 struct die_info
*imported_die
, *child_die
;
10744 struct dwarf2_cu
*imported_cu
;
10745 const char *imported_name
;
10746 const char *imported_name_prefix
;
10747 const char *canonical_name
;
10748 const char *import_alias
;
10749 const char *imported_declaration
= NULL
;
10750 const char *import_prefix
;
10751 std::vector
<const char *> excludes
;
10753 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10754 if (import_attr
== NULL
)
10756 complaint (_("Tag '%s' has no DW_AT_import"),
10757 dwarf_tag_name (die
->tag
));
10762 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10763 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10764 if (imported_name
== NULL
)
10766 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10768 The import in the following code:
10782 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10783 <52> DW_AT_decl_file : 1
10784 <53> DW_AT_decl_line : 6
10785 <54> DW_AT_import : <0x75>
10786 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10787 <59> DW_AT_name : B
10788 <5b> DW_AT_decl_file : 1
10789 <5c> DW_AT_decl_line : 2
10790 <5d> DW_AT_type : <0x6e>
10792 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10793 <76> DW_AT_byte_size : 4
10794 <77> DW_AT_encoding : 5 (signed)
10796 imports the wrong die ( 0x75 instead of 0x58 ).
10797 This case will be ignored until the gcc bug is fixed. */
10801 /* Figure out the local name after import. */
10802 import_alias
= dwarf2_name (die
, cu
);
10804 /* Figure out where the statement is being imported to. */
10805 import_prefix
= determine_prefix (die
, cu
);
10807 /* Figure out what the scope of the imported die is and prepend it
10808 to the name of the imported die. */
10809 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10811 if (imported_die
->tag
!= DW_TAG_namespace
10812 && imported_die
->tag
!= DW_TAG_module
)
10814 imported_declaration
= imported_name
;
10815 canonical_name
= imported_name_prefix
;
10817 else if (strlen (imported_name_prefix
) > 0)
10818 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10819 imported_name_prefix
,
10820 (cu
->language
== language_d
? "." : "::"),
10821 imported_name
, (char *) NULL
);
10823 canonical_name
= imported_name
;
10825 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10826 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10827 child_die
= child_die
->sibling
)
10829 /* DWARF-4: A Fortran use statement with a “rename list” may be
10830 represented by an imported module entry with an import attribute
10831 referring to the module and owned entries corresponding to those
10832 entities that are renamed as part of being imported. */
10834 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10836 complaint (_("child DW_TAG_imported_declaration expected "
10837 "- DIE at %s [in module %s]"),
10838 sect_offset_str (child_die
->sect_off
),
10839 objfile_name (objfile
));
10843 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10844 if (import_attr
== NULL
)
10846 complaint (_("Tag '%s' has no DW_AT_import"),
10847 dwarf_tag_name (child_die
->tag
));
10852 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10854 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10855 if (imported_name
== NULL
)
10857 complaint (_("child DW_TAG_imported_declaration has unknown "
10858 "imported name - DIE at %s [in module %s]"),
10859 sect_offset_str (child_die
->sect_off
),
10860 objfile_name (objfile
));
10864 excludes
.push_back (imported_name
);
10866 process_die (child_die
, cu
);
10869 add_using_directive (using_directives (cu
),
10873 imported_declaration
,
10876 &objfile
->objfile_obstack
);
10879 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10880 types, but gives them a size of zero. Starting with version 14,
10881 ICC is compatible with GCC. */
10884 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10886 if (!cu
->checked_producer
)
10887 check_producer (cu
);
10889 return cu
->producer_is_icc_lt_14
;
10892 /* ICC generates a DW_AT_type for C void functions. This was observed on
10893 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10894 which says that void functions should not have a DW_AT_type. */
10897 producer_is_icc (struct dwarf2_cu
*cu
)
10899 if (!cu
->checked_producer
)
10900 check_producer (cu
);
10902 return cu
->producer_is_icc
;
10905 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10906 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10907 this, it was first present in GCC release 4.3.0. */
10910 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10912 if (!cu
->checked_producer
)
10913 check_producer (cu
);
10915 return cu
->producer_is_gcc_lt_4_3
;
10918 static file_and_directory
10919 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10921 file_and_directory res
;
10923 /* Find the filename. Do not use dwarf2_name here, since the filename
10924 is not a source language identifier. */
10925 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10926 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10928 if (res
.comp_dir
== NULL
10929 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10930 && IS_ABSOLUTE_PATH (res
.name
))
10932 res
.comp_dir_storage
= ldirname (res
.name
);
10933 if (!res
.comp_dir_storage
.empty ())
10934 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10936 if (res
.comp_dir
!= NULL
)
10938 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10939 directory, get rid of it. */
10940 const char *cp
= strchr (res
.comp_dir
, ':');
10942 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10943 res
.comp_dir
= cp
+ 1;
10946 if (res
.name
== NULL
)
10947 res
.name
= "<unknown>";
10952 /* Handle DW_AT_stmt_list for a compilation unit.
10953 DIE is the DW_TAG_compile_unit die for CU.
10954 COMP_DIR is the compilation directory. LOWPC is passed to
10955 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10958 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10959 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10961 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10962 struct attribute
*attr
;
10963 struct line_header line_header_local
;
10964 hashval_t line_header_local_hash
;
10966 int decode_mapping
;
10968 gdb_assert (! cu
->per_cu
->is_debug_types
);
10970 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10974 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10976 /* The line header hash table is only created if needed (it exists to
10977 prevent redundant reading of the line table for partial_units).
10978 If we're given a partial_unit, we'll need it. If we're given a
10979 compile_unit, then use the line header hash table if it's already
10980 created, but don't create one just yet. */
10982 if (per_objfile
->line_header_hash
== NULL
10983 && die
->tag
== DW_TAG_partial_unit
)
10985 per_objfile
->line_header_hash
10986 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10987 line_header_eq_voidp
,
10988 free_line_header_voidp
,
10992 line_header_local
.sect_off
= line_offset
;
10993 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10994 line_header_local_hash
= line_header_hash (&line_header_local
);
10995 if (per_objfile
->line_header_hash
!= NULL
)
10997 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10998 &line_header_local
,
10999 line_header_local_hash
, NO_INSERT
);
11001 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11002 is not present in *SLOT (since if there is something in *SLOT then
11003 it will be for a partial_unit). */
11004 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11006 gdb_assert (*slot
!= NULL
);
11007 cu
->line_header
= (struct line_header
*) *slot
;
11012 /* dwarf_decode_line_header does not yet provide sufficient information.
11013 We always have to call also dwarf_decode_lines for it. */
11014 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11018 cu
->line_header
= lh
.release ();
11019 cu
->line_header_die_owner
= die
;
11021 if (per_objfile
->line_header_hash
== NULL
)
11025 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11026 &line_header_local
,
11027 line_header_local_hash
, INSERT
);
11028 gdb_assert (slot
!= NULL
);
11030 if (slot
!= NULL
&& *slot
== NULL
)
11032 /* This newly decoded line number information unit will be owned
11033 by line_header_hash hash table. */
11034 *slot
= cu
->line_header
;
11035 cu
->line_header_die_owner
= NULL
;
11039 /* We cannot free any current entry in (*slot) as that struct line_header
11040 may be already used by multiple CUs. Create only temporary decoded
11041 line_header for this CU - it may happen at most once for each line
11042 number information unit. And if we're not using line_header_hash
11043 then this is what we want as well. */
11044 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11046 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11047 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11052 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11055 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11057 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11058 struct objfile
*objfile
= per_objfile
->objfile
;
11059 struct gdbarch
*gdbarch
= objfile
->arch ();
11060 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11061 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11062 struct attribute
*attr
;
11063 struct die_info
*child_die
;
11064 CORE_ADDR baseaddr
;
11066 prepare_one_comp_unit (cu
, die
, cu
->language
);
11067 baseaddr
= objfile
->text_section_offset ();
11069 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11071 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11072 from finish_block. */
11073 if (lowpc
== ((CORE_ADDR
) -1))
11075 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11077 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11079 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11080 standardised yet. As a workaround for the language detection we fall
11081 back to the DW_AT_producer string. */
11082 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11083 cu
->language
= language_opencl
;
11085 /* Similar hack for Go. */
11086 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11087 set_cu_language (DW_LANG_Go
, cu
);
11089 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11091 /* Decode line number information if present. We do this before
11092 processing child DIEs, so that the line header table is available
11093 for DW_AT_decl_file. */
11094 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11096 /* Process all dies in compilation unit. */
11097 if (die
->child
!= NULL
)
11099 child_die
= die
->child
;
11100 while (child_die
&& child_die
->tag
)
11102 process_die (child_die
, cu
);
11103 child_die
= child_die
->sibling
;
11107 /* Decode macro information, if present. Dwarf 2 macro information
11108 refers to information in the line number info statement program
11109 header, so we can only read it if we've read the header
11111 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11113 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11114 if (attr
&& cu
->line_header
)
11116 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11117 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11119 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11123 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11124 if (attr
&& cu
->line_header
)
11126 unsigned int macro_offset
= DW_UNSND (attr
);
11128 dwarf_decode_macros (cu
, macro_offset
, 0);
11134 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11136 struct type_unit_group
*tu_group
;
11138 struct attribute
*attr
;
11140 struct signatured_type
*sig_type
;
11142 gdb_assert (per_cu
->is_debug_types
);
11143 sig_type
= (struct signatured_type
*) per_cu
;
11145 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11147 /* If we're using .gdb_index (includes -readnow) then
11148 per_cu->type_unit_group may not have been set up yet. */
11149 if (sig_type
->type_unit_group
== NULL
)
11150 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11151 tu_group
= sig_type
->type_unit_group
;
11153 /* If we've already processed this stmt_list there's no real need to
11154 do it again, we could fake it and just recreate the part we need
11155 (file name,index -> symtab mapping). If data shows this optimization
11156 is useful we can do it then. */
11157 type_unit_group_unshareable
*tug_unshare
11158 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11159 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11161 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11166 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11167 lh
= dwarf_decode_line_header (line_offset
, this);
11172 start_symtab ("", NULL
, 0);
11175 gdb_assert (tug_unshare
->symtabs
== NULL
);
11176 gdb_assert (m_builder
== nullptr);
11177 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11178 m_builder
.reset (new struct buildsym_compunit
11179 (COMPUNIT_OBJFILE (cust
), "",
11180 COMPUNIT_DIRNAME (cust
),
11181 compunit_language (cust
),
11183 list_in_scope
= get_builder ()->get_file_symbols ();
11188 line_header
= lh
.release ();
11189 line_header_die_owner
= die
;
11193 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11195 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11196 still initializing it, and our caller (a few levels up)
11197 process_full_type_unit still needs to know if this is the first
11200 tug_unshare
->symtabs
11201 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11202 struct symtab
*, line_header
->file_names_size ());
11204 auto &file_names
= line_header
->file_names ();
11205 for (i
= 0; i
< file_names
.size (); ++i
)
11207 file_entry
&fe
= file_names
[i
];
11208 dwarf2_start_subfile (this, fe
.name
,
11209 fe
.include_dir (line_header
));
11210 buildsym_compunit
*b
= get_builder ();
11211 if (b
->get_current_subfile ()->symtab
== NULL
)
11213 /* NOTE: start_subfile will recognize when it's been
11214 passed a file it has already seen. So we can't
11215 assume there's a simple mapping from
11216 cu->line_header->file_names to subfiles, plus
11217 cu->line_header->file_names may contain dups. */
11218 b
->get_current_subfile ()->symtab
11219 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11222 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11223 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11228 gdb_assert (m_builder
== nullptr);
11229 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11230 m_builder
.reset (new struct buildsym_compunit
11231 (COMPUNIT_OBJFILE (cust
), "",
11232 COMPUNIT_DIRNAME (cust
),
11233 compunit_language (cust
),
11235 list_in_scope
= get_builder ()->get_file_symbols ();
11237 auto &file_names
= line_header
->file_names ();
11238 for (i
= 0; i
< file_names
.size (); ++i
)
11240 file_entry
&fe
= file_names
[i
];
11241 fe
.symtab
= tug_unshare
->symtabs
[i
];
11245 /* The main symtab is allocated last. Type units don't have DW_AT_name
11246 so they don't have a "real" (so to speak) symtab anyway.
11247 There is later code that will assign the main symtab to all symbols
11248 that don't have one. We need to handle the case of a symbol with a
11249 missing symtab (DW_AT_decl_file) anyway. */
11252 /* Process DW_TAG_type_unit.
11253 For TUs we want to skip the first top level sibling if it's not the
11254 actual type being defined by this TU. In this case the first top
11255 level sibling is there to provide context only. */
11258 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11260 struct die_info
*child_die
;
11262 prepare_one_comp_unit (cu
, die
, language_minimal
);
11264 /* Initialize (or reinitialize) the machinery for building symtabs.
11265 We do this before processing child DIEs, so that the line header table
11266 is available for DW_AT_decl_file. */
11267 cu
->setup_type_unit_groups (die
);
11269 if (die
->child
!= NULL
)
11271 child_die
= die
->child
;
11272 while (child_die
&& child_die
->tag
)
11274 process_die (child_die
, cu
);
11275 child_die
= child_die
->sibling
;
11282 http://gcc.gnu.org/wiki/DebugFission
11283 http://gcc.gnu.org/wiki/DebugFissionDWP
11285 To simplify handling of both DWO files ("object" files with the DWARF info)
11286 and DWP files (a file with the DWOs packaged up into one file), we treat
11287 DWP files as having a collection of virtual DWO files. */
11290 hash_dwo_file (const void *item
)
11292 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11295 hash
= htab_hash_string (dwo_file
->dwo_name
);
11296 if (dwo_file
->comp_dir
!= NULL
)
11297 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11302 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11304 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11305 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11307 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11309 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11310 return lhs
->comp_dir
== rhs
->comp_dir
;
11311 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11314 /* Allocate a hash table for DWO files. */
11317 allocate_dwo_file_hash_table ()
11319 auto delete_dwo_file
= [] (void *item
)
11321 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11326 return htab_up (htab_create_alloc (41,
11333 /* Lookup DWO file DWO_NAME. */
11336 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11337 const char *dwo_name
,
11338 const char *comp_dir
)
11340 struct dwo_file find_entry
;
11343 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11344 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11346 find_entry
.dwo_name
= dwo_name
;
11347 find_entry
.comp_dir
= comp_dir
;
11348 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11355 hash_dwo_unit (const void *item
)
11357 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11359 /* This drops the top 32 bits of the id, but is ok for a hash. */
11360 return dwo_unit
->signature
;
11364 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11366 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11367 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11369 /* The signature is assumed to be unique within the DWO file.
11370 So while object file CU dwo_id's always have the value zero,
11371 that's OK, assuming each object file DWO file has only one CU,
11372 and that's the rule for now. */
11373 return lhs
->signature
== rhs
->signature
;
11376 /* Allocate a hash table for DWO CUs,TUs.
11377 There is one of these tables for each of CUs,TUs for each DWO file. */
11380 allocate_dwo_unit_table ()
11382 /* Start out with a pretty small number.
11383 Generally DWO files contain only one CU and maybe some TUs. */
11384 return htab_up (htab_create_alloc (3,
11387 NULL
, xcalloc
, xfree
));
11390 /* die_reader_func for create_dwo_cu. */
11393 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11394 const gdb_byte
*info_ptr
,
11395 struct die_info
*comp_unit_die
,
11396 struct dwo_file
*dwo_file
,
11397 struct dwo_unit
*dwo_unit
)
11399 struct dwarf2_cu
*cu
= reader
->cu
;
11400 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11401 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11403 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11404 if (!signature
.has_value ())
11406 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11407 " its dwo_id [in module %s]"),
11408 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11412 dwo_unit
->dwo_file
= dwo_file
;
11413 dwo_unit
->signature
= *signature
;
11414 dwo_unit
->section
= section
;
11415 dwo_unit
->sect_off
= sect_off
;
11416 dwo_unit
->length
= cu
->per_cu
->length
;
11418 if (dwarf_read_debug
)
11419 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11420 sect_offset_str (sect_off
),
11421 hex_string (dwo_unit
->signature
));
11424 /* Create the dwo_units for the CUs in a DWO_FILE.
11425 Note: This function processes DWO files only, not DWP files. */
11428 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11429 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11430 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11432 struct objfile
*objfile
= per_objfile
->objfile
;
11433 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11434 const gdb_byte
*info_ptr
, *end_ptr
;
11436 section
.read (objfile
);
11437 info_ptr
= section
.buffer
;
11439 if (info_ptr
== NULL
)
11442 if (dwarf_read_debug
)
11444 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11445 section
.get_name (),
11446 section
.get_file_name ());
11449 end_ptr
= info_ptr
+ section
.size
;
11450 while (info_ptr
< end_ptr
)
11452 struct dwarf2_per_cu_data per_cu
;
11453 struct dwo_unit read_unit
{};
11454 struct dwo_unit
*dwo_unit
;
11456 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11458 memset (&per_cu
, 0, sizeof (per_cu
));
11459 per_cu
.per_bfd
= per_bfd
;
11460 per_cu
.is_debug_types
= 0;
11461 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11462 per_cu
.section
= §ion
;
11464 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11465 if (!reader
.dummy_p
)
11466 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11467 &dwo_file
, &read_unit
);
11468 info_ptr
+= per_cu
.length
;
11470 // If the unit could not be parsed, skip it.
11471 if (read_unit
.dwo_file
== NULL
)
11474 if (cus_htab
== NULL
)
11475 cus_htab
= allocate_dwo_unit_table ();
11477 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11479 *dwo_unit
= read_unit
;
11480 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11481 gdb_assert (slot
!= NULL
);
11484 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11485 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11487 complaint (_("debug cu entry at offset %s is duplicate to"
11488 " the entry at offset %s, signature %s"),
11489 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11490 hex_string (dwo_unit
->signature
));
11492 *slot
= (void *)dwo_unit
;
11496 /* DWP file .debug_{cu,tu}_index section format:
11497 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11501 Both index sections have the same format, and serve to map a 64-bit
11502 signature to a set of section numbers. Each section begins with a header,
11503 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11504 indexes, and a pool of 32-bit section numbers. The index sections will be
11505 aligned at 8-byte boundaries in the file.
11507 The index section header consists of:
11509 V, 32 bit version number
11511 N, 32 bit number of compilation units or type units in the index
11512 M, 32 bit number of slots in the hash table
11514 Numbers are recorded using the byte order of the application binary.
11516 The hash table begins at offset 16 in the section, and consists of an array
11517 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11518 order of the application binary). Unused slots in the hash table are 0.
11519 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11521 The parallel table begins immediately after the hash table
11522 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11523 array of 32-bit indexes (using the byte order of the application binary),
11524 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11525 table contains a 32-bit index into the pool of section numbers. For unused
11526 hash table slots, the corresponding entry in the parallel table will be 0.
11528 The pool of section numbers begins immediately following the hash table
11529 (at offset 16 + 12 * M from the beginning of the section). The pool of
11530 section numbers consists of an array of 32-bit words (using the byte order
11531 of the application binary). Each item in the array is indexed starting
11532 from 0. The hash table entry provides the index of the first section
11533 number in the set. Additional section numbers in the set follow, and the
11534 set is terminated by a 0 entry (section number 0 is not used in ELF).
11536 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11537 section must be the first entry in the set, and the .debug_abbrev.dwo must
11538 be the second entry. Other members of the set may follow in any order.
11544 DWP Version 2 combines all the .debug_info, etc. sections into one,
11545 and the entries in the index tables are now offsets into these sections.
11546 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11549 Index Section Contents:
11551 Hash Table of Signatures dwp_hash_table.hash_table
11552 Parallel Table of Indices dwp_hash_table.unit_table
11553 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11554 Table of Section Sizes dwp_hash_table.v2.sizes
11556 The index section header consists of:
11558 V, 32 bit version number
11559 L, 32 bit number of columns in the table of section offsets
11560 N, 32 bit number of compilation units or type units in the index
11561 M, 32 bit number of slots in the hash table
11563 Numbers are recorded using the byte order of the application binary.
11565 The hash table has the same format as version 1.
11566 The parallel table of indices has the same format as version 1,
11567 except that the entries are origin-1 indices into the table of sections
11568 offsets and the table of section sizes.
11570 The table of offsets begins immediately following the parallel table
11571 (at offset 16 + 12 * M from the beginning of the section). The table is
11572 a two-dimensional array of 32-bit words (using the byte order of the
11573 application binary), with L columns and N+1 rows, in row-major order.
11574 Each row in the array is indexed starting from 0. The first row provides
11575 a key to the remaining rows: each column in this row provides an identifier
11576 for a debug section, and the offsets in the same column of subsequent rows
11577 refer to that section. The section identifiers are:
11579 DW_SECT_INFO 1 .debug_info.dwo
11580 DW_SECT_TYPES 2 .debug_types.dwo
11581 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11582 DW_SECT_LINE 4 .debug_line.dwo
11583 DW_SECT_LOC 5 .debug_loc.dwo
11584 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11585 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11586 DW_SECT_MACRO 8 .debug_macro.dwo
11588 The offsets provided by the CU and TU index sections are the base offsets
11589 for the contributions made by each CU or TU to the corresponding section
11590 in the package file. Each CU and TU header contains an abbrev_offset
11591 field, used to find the abbreviations table for that CU or TU within the
11592 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11593 be interpreted as relative to the base offset given in the index section.
11594 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11595 should be interpreted as relative to the base offset for .debug_line.dwo,
11596 and offsets into other debug sections obtained from DWARF attributes should
11597 also be interpreted as relative to the corresponding base offset.
11599 The table of sizes begins immediately following the table of offsets.
11600 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11601 with L columns and N rows, in row-major order. Each row in the array is
11602 indexed starting from 1 (row 0 is shared by the two tables).
11606 Hash table lookup is handled the same in version 1 and 2:
11608 We assume that N and M will not exceed 2^32 - 1.
11609 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11611 Given a 64-bit compilation unit signature or a type signature S, an entry
11612 in the hash table is located as follows:
11614 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11615 the low-order k bits all set to 1.
11617 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11619 3) If the hash table entry at index H matches the signature, use that
11620 entry. If the hash table entry at index H is unused (all zeroes),
11621 terminate the search: the signature is not present in the table.
11623 4) Let H = (H + H') modulo M. Repeat at Step 3.
11625 Because M > N and H' and M are relatively prime, the search is guaranteed
11626 to stop at an unused slot or find the match. */
11628 /* Create a hash table to map DWO IDs to their CU/TU entry in
11629 .debug_{info,types}.dwo in DWP_FILE.
11630 Returns NULL if there isn't one.
11631 Note: This function processes DWP files only, not DWO files. */
11633 static struct dwp_hash_table
*
11634 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11635 struct dwp_file
*dwp_file
, int is_debug_types
)
11637 struct objfile
*objfile
= per_objfile
->objfile
;
11638 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11639 const gdb_byte
*index_ptr
, *index_end
;
11640 struct dwarf2_section_info
*index
;
11641 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11642 struct dwp_hash_table
*htab
;
11644 if (is_debug_types
)
11645 index
= &dwp_file
->sections
.tu_index
;
11647 index
= &dwp_file
->sections
.cu_index
;
11649 if (index
->empty ())
11651 index
->read (objfile
);
11653 index_ptr
= index
->buffer
;
11654 index_end
= index_ptr
+ index
->size
;
11656 version
= read_4_bytes (dbfd
, index_ptr
);
11659 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11663 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11665 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11668 if (version
!= 1 && version
!= 2)
11670 error (_("Dwarf Error: unsupported DWP file version (%s)"
11671 " [in module %s]"),
11672 pulongest (version
), dwp_file
->name
);
11674 if (nr_slots
!= (nr_slots
& -nr_slots
))
11676 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11677 " is not power of 2 [in module %s]"),
11678 pulongest (nr_slots
), dwp_file
->name
);
11681 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11682 htab
->version
= version
;
11683 htab
->nr_columns
= nr_columns
;
11684 htab
->nr_units
= nr_units
;
11685 htab
->nr_slots
= nr_slots
;
11686 htab
->hash_table
= index_ptr
;
11687 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11689 /* Exit early if the table is empty. */
11690 if (nr_slots
== 0 || nr_units
== 0
11691 || (version
== 2 && nr_columns
== 0))
11693 /* All must be zero. */
11694 if (nr_slots
!= 0 || nr_units
!= 0
11695 || (version
== 2 && nr_columns
!= 0))
11697 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11698 " all zero [in modules %s]"),
11706 htab
->section_pool
.v1
.indices
=
11707 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11708 /* It's harder to decide whether the section is too small in v1.
11709 V1 is deprecated anyway so we punt. */
11713 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11714 int *ids
= htab
->section_pool
.v2
.section_ids
;
11715 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11716 /* Reverse map for error checking. */
11717 int ids_seen
[DW_SECT_MAX
+ 1];
11720 if (nr_columns
< 2)
11722 error (_("Dwarf Error: bad DWP hash table, too few columns"
11723 " in section table [in module %s]"),
11726 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11728 error (_("Dwarf Error: bad DWP hash table, too many columns"
11729 " in section table [in module %s]"),
11732 memset (ids
, 255, sizeof_ids
);
11733 memset (ids_seen
, 255, sizeof (ids_seen
));
11734 for (i
= 0; i
< nr_columns
; ++i
)
11736 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11738 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11740 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11741 " in section table [in module %s]"),
11742 id
, dwp_file
->name
);
11744 if (ids_seen
[id
] != -1)
11746 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11747 " id %d in section table [in module %s]"),
11748 id
, dwp_file
->name
);
11753 /* Must have exactly one info or types section. */
11754 if (((ids_seen
[DW_SECT_INFO
] != -1)
11755 + (ids_seen
[DW_SECT_TYPES
] != -1))
11758 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11759 " DWO info/types section [in module %s]"),
11762 /* Must have an abbrev section. */
11763 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11765 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11766 " section [in module %s]"),
11769 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11770 htab
->section_pool
.v2
.sizes
=
11771 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11772 * nr_units
* nr_columns
);
11773 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11774 * nr_units
* nr_columns
))
11777 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11778 " [in module %s]"),
11786 /* Update SECTIONS with the data from SECTP.
11788 This function is like the other "locate" section routines that are
11789 passed to bfd_map_over_sections, but in this context the sections to
11790 read comes from the DWP V1 hash table, not the full ELF section table.
11792 The result is non-zero for success, or zero if an error was found. */
11795 locate_v1_virtual_dwo_sections (asection
*sectp
,
11796 struct virtual_v1_dwo_sections
*sections
)
11798 const struct dwop_section_names
*names
= &dwop_section_names
;
11800 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11802 /* There can be only one. */
11803 if (sections
->abbrev
.s
.section
!= NULL
)
11805 sections
->abbrev
.s
.section
= sectp
;
11806 sections
->abbrev
.size
= bfd_section_size (sectp
);
11808 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11809 || section_is_p (sectp
->name
, &names
->types_dwo
))
11811 /* There can be only one. */
11812 if (sections
->info_or_types
.s
.section
!= NULL
)
11814 sections
->info_or_types
.s
.section
= sectp
;
11815 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11817 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11819 /* There can be only one. */
11820 if (sections
->line
.s
.section
!= NULL
)
11822 sections
->line
.s
.section
= sectp
;
11823 sections
->line
.size
= bfd_section_size (sectp
);
11825 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11827 /* There can be only one. */
11828 if (sections
->loc
.s
.section
!= NULL
)
11830 sections
->loc
.s
.section
= sectp
;
11831 sections
->loc
.size
= bfd_section_size (sectp
);
11833 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11835 /* There can be only one. */
11836 if (sections
->macinfo
.s
.section
!= NULL
)
11838 sections
->macinfo
.s
.section
= sectp
;
11839 sections
->macinfo
.size
= bfd_section_size (sectp
);
11841 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11843 /* There can be only one. */
11844 if (sections
->macro
.s
.section
!= NULL
)
11846 sections
->macro
.s
.section
= sectp
;
11847 sections
->macro
.size
= bfd_section_size (sectp
);
11849 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11851 /* There can be only one. */
11852 if (sections
->str_offsets
.s
.section
!= NULL
)
11854 sections
->str_offsets
.s
.section
= sectp
;
11855 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11859 /* No other kind of section is valid. */
11866 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11867 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11868 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11869 This is for DWP version 1 files. */
11871 static struct dwo_unit
*
11872 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11873 struct dwp_file
*dwp_file
,
11874 uint32_t unit_index
,
11875 const char *comp_dir
,
11876 ULONGEST signature
, int is_debug_types
)
11878 const struct dwp_hash_table
*dwp_htab
=
11879 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11880 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11881 const char *kind
= is_debug_types
? "TU" : "CU";
11882 struct dwo_file
*dwo_file
;
11883 struct dwo_unit
*dwo_unit
;
11884 struct virtual_v1_dwo_sections sections
;
11885 void **dwo_file_slot
;
11888 gdb_assert (dwp_file
->version
== 1);
11890 if (dwarf_read_debug
)
11892 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11894 pulongest (unit_index
), hex_string (signature
),
11898 /* Fetch the sections of this DWO unit.
11899 Put a limit on the number of sections we look for so that bad data
11900 doesn't cause us to loop forever. */
11902 #define MAX_NR_V1_DWO_SECTIONS \
11903 (1 /* .debug_info or .debug_types */ \
11904 + 1 /* .debug_abbrev */ \
11905 + 1 /* .debug_line */ \
11906 + 1 /* .debug_loc */ \
11907 + 1 /* .debug_str_offsets */ \
11908 + 1 /* .debug_macro or .debug_macinfo */ \
11909 + 1 /* trailing zero */)
11911 memset (§ions
, 0, sizeof (sections
));
11913 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11916 uint32_t section_nr
=
11917 read_4_bytes (dbfd
,
11918 dwp_htab
->section_pool
.v1
.indices
11919 + (unit_index
+ i
) * sizeof (uint32_t));
11921 if (section_nr
== 0)
11923 if (section_nr
>= dwp_file
->num_sections
)
11925 error (_("Dwarf Error: bad DWP hash table, section number too large"
11926 " [in module %s]"),
11930 sectp
= dwp_file
->elf_sections
[section_nr
];
11931 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11933 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11934 " [in module %s]"),
11940 || sections
.info_or_types
.empty ()
11941 || sections
.abbrev
.empty ())
11943 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11944 " [in module %s]"),
11947 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11949 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11950 " [in module %s]"),
11954 /* It's easier for the rest of the code if we fake a struct dwo_file and
11955 have dwo_unit "live" in that. At least for now.
11957 The DWP file can be made up of a random collection of CUs and TUs.
11958 However, for each CU + set of TUs that came from the same original DWO
11959 file, we can combine them back into a virtual DWO file to save space
11960 (fewer struct dwo_file objects to allocate). Remember that for really
11961 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11963 std::string virtual_dwo_name
=
11964 string_printf ("virtual-dwo/%d-%d-%d-%d",
11965 sections
.abbrev
.get_id (),
11966 sections
.line
.get_id (),
11967 sections
.loc
.get_id (),
11968 sections
.str_offsets
.get_id ());
11969 /* Can we use an existing virtual DWO file? */
11970 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11972 /* Create one if necessary. */
11973 if (*dwo_file_slot
== NULL
)
11975 if (dwarf_read_debug
)
11977 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11978 virtual_dwo_name
.c_str ());
11980 dwo_file
= new struct dwo_file
;
11981 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11982 dwo_file
->comp_dir
= comp_dir
;
11983 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11984 dwo_file
->sections
.line
= sections
.line
;
11985 dwo_file
->sections
.loc
= sections
.loc
;
11986 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11987 dwo_file
->sections
.macro
= sections
.macro
;
11988 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11989 /* The "str" section is global to the entire DWP file. */
11990 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11991 /* The info or types section is assigned below to dwo_unit,
11992 there's no need to record it in dwo_file.
11993 Also, we can't simply record type sections in dwo_file because
11994 we record a pointer into the vector in dwo_unit. As we collect more
11995 types we'll grow the vector and eventually have to reallocate space
11996 for it, invalidating all copies of pointers into the previous
11998 *dwo_file_slot
= dwo_file
;
12002 if (dwarf_read_debug
)
12004 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12005 virtual_dwo_name
.c_str ());
12007 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12010 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12011 dwo_unit
->dwo_file
= dwo_file
;
12012 dwo_unit
->signature
= signature
;
12013 dwo_unit
->section
=
12014 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12015 *dwo_unit
->section
= sections
.info_or_types
;
12016 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12021 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12022 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12023 piece within that section used by a TU/CU, return a virtual section
12024 of just that piece. */
12026 static struct dwarf2_section_info
12027 create_dwp_v2_section (dwarf2_per_objfile
*per_objfile
,
12028 struct dwarf2_section_info
*section
,
12029 bfd_size_type offset
, bfd_size_type size
)
12031 struct dwarf2_section_info result
;
12034 gdb_assert (section
!= NULL
);
12035 gdb_assert (!section
->is_virtual
);
12037 memset (&result
, 0, sizeof (result
));
12038 result
.s
.containing_section
= section
;
12039 result
.is_virtual
= true;
12044 sectp
= section
->get_bfd_section ();
12046 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12047 bounds of the real section. This is a pretty-rare event, so just
12048 flag an error (easier) instead of a warning and trying to cope. */
12050 || offset
+ size
> bfd_section_size (sectp
))
12052 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12053 " in section %s [in module %s]"),
12054 sectp
? bfd_section_name (sectp
) : "<unknown>",
12055 objfile_name (per_objfile
->objfile
));
12058 result
.virtual_offset
= offset
;
12059 result
.size
= size
;
12063 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12064 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12065 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12066 This is for DWP version 2 files. */
12068 static struct dwo_unit
*
12069 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12070 struct dwp_file
*dwp_file
,
12071 uint32_t unit_index
,
12072 const char *comp_dir
,
12073 ULONGEST signature
, int is_debug_types
)
12075 const struct dwp_hash_table
*dwp_htab
=
12076 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12077 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12078 const char *kind
= is_debug_types
? "TU" : "CU";
12079 struct dwo_file
*dwo_file
;
12080 struct dwo_unit
*dwo_unit
;
12081 struct virtual_v2_dwo_sections sections
;
12082 void **dwo_file_slot
;
12085 gdb_assert (dwp_file
->version
== 2);
12087 if (dwarf_read_debug
)
12089 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12091 pulongest (unit_index
), hex_string (signature
),
12095 /* Fetch the section offsets of this DWO unit. */
12097 memset (§ions
, 0, sizeof (sections
));
12099 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12101 uint32_t offset
= read_4_bytes (dbfd
,
12102 dwp_htab
->section_pool
.v2
.offsets
12103 + (((unit_index
- 1) * dwp_htab
->nr_columns
12105 * sizeof (uint32_t)));
12106 uint32_t size
= read_4_bytes (dbfd
,
12107 dwp_htab
->section_pool
.v2
.sizes
12108 + (((unit_index
- 1) * dwp_htab
->nr_columns
12110 * sizeof (uint32_t)));
12112 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12115 case DW_SECT_TYPES
:
12116 sections
.info_or_types_offset
= offset
;
12117 sections
.info_or_types_size
= size
;
12119 case DW_SECT_ABBREV
:
12120 sections
.abbrev_offset
= offset
;
12121 sections
.abbrev_size
= size
;
12124 sections
.line_offset
= offset
;
12125 sections
.line_size
= size
;
12128 sections
.loc_offset
= offset
;
12129 sections
.loc_size
= size
;
12131 case DW_SECT_STR_OFFSETS
:
12132 sections
.str_offsets_offset
= offset
;
12133 sections
.str_offsets_size
= size
;
12135 case DW_SECT_MACINFO
:
12136 sections
.macinfo_offset
= offset
;
12137 sections
.macinfo_size
= size
;
12139 case DW_SECT_MACRO
:
12140 sections
.macro_offset
= offset
;
12141 sections
.macro_size
= size
;
12146 /* It's easier for the rest of the code if we fake a struct dwo_file and
12147 have dwo_unit "live" in that. At least for now.
12149 The DWP file can be made up of a random collection of CUs and TUs.
12150 However, for each CU + set of TUs that came from the same original DWO
12151 file, we can combine them back into a virtual DWO file to save space
12152 (fewer struct dwo_file objects to allocate). Remember that for really
12153 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12155 std::string virtual_dwo_name
=
12156 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12157 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12158 (long) (sections
.line_size
? sections
.line_offset
: 0),
12159 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12160 (long) (sections
.str_offsets_size
12161 ? sections
.str_offsets_offset
: 0));
12162 /* Can we use an existing virtual DWO file? */
12163 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12165 /* Create one if necessary. */
12166 if (*dwo_file_slot
== NULL
)
12168 if (dwarf_read_debug
)
12170 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12171 virtual_dwo_name
.c_str ());
12173 dwo_file
= new struct dwo_file
;
12174 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12175 dwo_file
->comp_dir
= comp_dir
;
12176 dwo_file
->sections
.abbrev
=
12177 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12178 sections
.abbrev_offset
, sections
.abbrev_size
);
12179 dwo_file
->sections
.line
=
12180 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.line
,
12181 sections
.line_offset
, sections
.line_size
);
12182 dwo_file
->sections
.loc
=
12183 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.loc
,
12184 sections
.loc_offset
, sections
.loc_size
);
12185 dwo_file
->sections
.macinfo
=
12186 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12187 sections
.macinfo_offset
, sections
.macinfo_size
);
12188 dwo_file
->sections
.macro
=
12189 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macro
,
12190 sections
.macro_offset
, sections
.macro_size
);
12191 dwo_file
->sections
.str_offsets
=
12192 create_dwp_v2_section (per_objfile
,
12193 &dwp_file
->sections
.str_offsets
,
12194 sections
.str_offsets_offset
,
12195 sections
.str_offsets_size
);
12196 /* The "str" section is global to the entire DWP file. */
12197 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12198 /* The info or types section is assigned below to dwo_unit,
12199 there's no need to record it in dwo_file.
12200 Also, we can't simply record type sections in dwo_file because
12201 we record a pointer into the vector in dwo_unit. As we collect more
12202 types we'll grow the vector and eventually have to reallocate space
12203 for it, invalidating all copies of pointers into the previous
12205 *dwo_file_slot
= dwo_file
;
12209 if (dwarf_read_debug
)
12211 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12212 virtual_dwo_name
.c_str ());
12214 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12217 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12218 dwo_unit
->dwo_file
= dwo_file
;
12219 dwo_unit
->signature
= signature
;
12220 dwo_unit
->section
=
12221 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12222 *dwo_unit
->section
= create_dwp_v2_section (per_objfile
,
12224 ? &dwp_file
->sections
.types
12225 : &dwp_file
->sections
.info
,
12226 sections
.info_or_types_offset
,
12227 sections
.info_or_types_size
);
12228 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12233 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12234 Returns NULL if the signature isn't found. */
12236 static struct dwo_unit
*
12237 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12238 struct dwp_file
*dwp_file
, const char *comp_dir
,
12239 ULONGEST signature
, int is_debug_types
)
12241 const struct dwp_hash_table
*dwp_htab
=
12242 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12243 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12244 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12245 uint32_t hash
= signature
& mask
;
12246 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12249 struct dwo_unit find_dwo_cu
;
12251 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12252 find_dwo_cu
.signature
= signature
;
12253 slot
= htab_find_slot (is_debug_types
12254 ? dwp_file
->loaded_tus
.get ()
12255 : dwp_file
->loaded_cus
.get (),
12256 &find_dwo_cu
, INSERT
);
12259 return (struct dwo_unit
*) *slot
;
12261 /* Use a for loop so that we don't loop forever on bad debug info. */
12262 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12264 ULONGEST signature_in_table
;
12266 signature_in_table
=
12267 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12268 if (signature_in_table
== signature
)
12270 uint32_t unit_index
=
12271 read_4_bytes (dbfd
,
12272 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12274 if (dwp_file
->version
== 1)
12276 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12277 unit_index
, comp_dir
,
12278 signature
, is_debug_types
);
12282 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12283 unit_index
, comp_dir
,
12284 signature
, is_debug_types
);
12286 return (struct dwo_unit
*) *slot
;
12288 if (signature_in_table
== 0)
12290 hash
= (hash
+ hash2
) & mask
;
12293 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12294 " [in module %s]"),
12298 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12299 Open the file specified by FILE_NAME and hand it off to BFD for
12300 preliminary analysis. Return a newly initialized bfd *, which
12301 includes a canonicalized copy of FILE_NAME.
12302 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12303 SEARCH_CWD is true if the current directory is to be searched.
12304 It will be searched before debug-file-directory.
12305 If successful, the file is added to the bfd include table of the
12306 objfile's bfd (see gdb_bfd_record_inclusion).
12307 If unable to find/open the file, return NULL.
12308 NOTE: This function is derived from symfile_bfd_open. */
12310 static gdb_bfd_ref_ptr
12311 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12312 const char *file_name
, int is_dwp
, int search_cwd
)
12315 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12316 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12317 to debug_file_directory. */
12318 const char *search_path
;
12319 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12321 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12324 if (*debug_file_directory
!= '\0')
12326 search_path_holder
.reset (concat (".", dirname_separator_string
,
12327 debug_file_directory
,
12329 search_path
= search_path_holder
.get ();
12335 search_path
= debug_file_directory
;
12337 openp_flags flags
= OPF_RETURN_REALPATH
;
12339 flags
|= OPF_SEARCH_IN_PATH
;
12341 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12342 desc
= openp (search_path
, flags
, file_name
,
12343 O_RDONLY
| O_BINARY
, &absolute_name
);
12347 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12349 if (sym_bfd
== NULL
)
12351 bfd_set_cacheable (sym_bfd
.get (), 1);
12353 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12356 /* Success. Record the bfd as having been included by the objfile's bfd.
12357 This is important because things like demangled_names_hash lives in the
12358 objfile's per_bfd space and may have references to things like symbol
12359 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12360 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12365 /* Try to open DWO file FILE_NAME.
12366 COMP_DIR is the DW_AT_comp_dir attribute.
12367 The result is the bfd handle of the file.
12368 If there is a problem finding or opening the file, return NULL.
12369 Upon success, the canonicalized path of the file is stored in the bfd,
12370 same as symfile_bfd_open. */
12372 static gdb_bfd_ref_ptr
12373 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12374 const char *file_name
, const char *comp_dir
)
12376 if (IS_ABSOLUTE_PATH (file_name
))
12377 return try_open_dwop_file (per_objfile
, file_name
,
12378 0 /*is_dwp*/, 0 /*search_cwd*/);
12380 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12382 if (comp_dir
!= NULL
)
12384 gdb::unique_xmalloc_ptr
<char> path_to_try
12385 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12387 /* NOTE: If comp_dir is a relative path, this will also try the
12388 search path, which seems useful. */
12389 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12391 1 /*search_cwd*/));
12396 /* That didn't work, try debug-file-directory, which, despite its name,
12397 is a list of paths. */
12399 if (*debug_file_directory
== '\0')
12402 return try_open_dwop_file (per_objfile
, file_name
,
12403 0 /*is_dwp*/, 1 /*search_cwd*/);
12406 /* This function is mapped across the sections and remembers the offset and
12407 size of each of the DWO debugging sections we are interested in. */
12410 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12412 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12413 const struct dwop_section_names
*names
= &dwop_section_names
;
12415 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12417 dwo_sections
->abbrev
.s
.section
= sectp
;
12418 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12420 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12422 dwo_sections
->info
.s
.section
= sectp
;
12423 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12425 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12427 dwo_sections
->line
.s
.section
= sectp
;
12428 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12430 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12432 dwo_sections
->loc
.s
.section
= sectp
;
12433 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12435 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12437 dwo_sections
->loclists
.s
.section
= sectp
;
12438 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12440 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12442 dwo_sections
->macinfo
.s
.section
= sectp
;
12443 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12445 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12447 dwo_sections
->macro
.s
.section
= sectp
;
12448 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12450 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12452 dwo_sections
->str
.s
.section
= sectp
;
12453 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12455 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12457 dwo_sections
->str_offsets
.s
.section
= sectp
;
12458 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12460 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12462 struct dwarf2_section_info type_section
;
12464 memset (&type_section
, 0, sizeof (type_section
));
12465 type_section
.s
.section
= sectp
;
12466 type_section
.size
= bfd_section_size (sectp
);
12467 dwo_sections
->types
.push_back (type_section
);
12471 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12472 by PER_CU. This is for the non-DWP case.
12473 The result is NULL if DWO_NAME can't be found. */
12475 static struct dwo_file
*
12476 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12477 const char *comp_dir
)
12479 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12481 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12484 if (dwarf_read_debug
)
12485 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12489 dwo_file_up
dwo_file (new struct dwo_file
);
12490 dwo_file
->dwo_name
= dwo_name
;
12491 dwo_file
->comp_dir
= comp_dir
;
12492 dwo_file
->dbfd
= std::move (dbfd
);
12494 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12495 &dwo_file
->sections
);
12497 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12500 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12501 dwo_file
->sections
.types
, dwo_file
->tus
);
12503 if (dwarf_read_debug
)
12504 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12506 return dwo_file
.release ();
12509 /* This function is mapped across the sections and remembers the offset and
12510 size of each of the DWP debugging sections common to version 1 and 2 that
12511 we are interested in. */
12514 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12515 void *dwp_file_ptr
)
12517 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12518 const struct dwop_section_names
*names
= &dwop_section_names
;
12519 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12521 /* Record the ELF section number for later lookup: this is what the
12522 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12523 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12524 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12526 /* Look for specific sections that we need. */
12527 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12529 dwp_file
->sections
.str
.s
.section
= sectp
;
12530 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12532 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12534 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12535 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12537 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12539 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12540 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12544 /* This function is mapped across the sections and remembers the offset and
12545 size of each of the DWP version 2 debugging sections that we are interested
12546 in. This is split into a separate function because we don't know if we
12547 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12550 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12552 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12553 const struct dwop_section_names
*names
= &dwop_section_names
;
12554 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12556 /* Record the ELF section number for later lookup: this is what the
12557 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12558 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12559 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12561 /* Look for specific sections that we need. */
12562 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12564 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12565 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12567 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12569 dwp_file
->sections
.info
.s
.section
= sectp
;
12570 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12572 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12574 dwp_file
->sections
.line
.s
.section
= sectp
;
12575 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12577 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12579 dwp_file
->sections
.loc
.s
.section
= sectp
;
12580 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12582 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12584 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12585 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12587 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12589 dwp_file
->sections
.macro
.s
.section
= sectp
;
12590 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12592 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12594 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12595 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12597 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12599 dwp_file
->sections
.types
.s
.section
= sectp
;
12600 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12604 /* Hash function for dwp_file loaded CUs/TUs. */
12607 hash_dwp_loaded_cutus (const void *item
)
12609 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12611 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12612 return dwo_unit
->signature
;
12615 /* Equality function for dwp_file loaded CUs/TUs. */
12618 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12620 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12621 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12623 return dua
->signature
== dub
->signature
;
12626 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12629 allocate_dwp_loaded_cutus_table ()
12631 return htab_up (htab_create_alloc (3,
12632 hash_dwp_loaded_cutus
,
12633 eq_dwp_loaded_cutus
,
12634 NULL
, xcalloc
, xfree
));
12637 /* Try to open DWP file FILE_NAME.
12638 The result is the bfd handle of the file.
12639 If there is a problem finding or opening the file, return NULL.
12640 Upon success, the canonicalized path of the file is stored in the bfd,
12641 same as symfile_bfd_open. */
12643 static gdb_bfd_ref_ptr
12644 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12646 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12648 1 /*search_cwd*/));
12652 /* Work around upstream bug 15652.
12653 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12654 [Whether that's a "bug" is debatable, but it is getting in our way.]
12655 We have no real idea where the dwp file is, because gdb's realpath-ing
12656 of the executable's path may have discarded the needed info.
12657 [IWBN if the dwp file name was recorded in the executable, akin to
12658 .gnu_debuglink, but that doesn't exist yet.]
12659 Strip the directory from FILE_NAME and search again. */
12660 if (*debug_file_directory
!= '\0')
12662 /* Don't implicitly search the current directory here.
12663 If the user wants to search "." to handle this case,
12664 it must be added to debug-file-directory. */
12665 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12673 /* Initialize the use of the DWP file for the current objfile.
12674 By convention the name of the DWP file is ${objfile}.dwp.
12675 The result is NULL if it can't be found. */
12677 static std::unique_ptr
<struct dwp_file
>
12678 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12680 struct objfile
*objfile
= per_objfile
->objfile
;
12682 /* Try to find first .dwp for the binary file before any symbolic links
12685 /* If the objfile is a debug file, find the name of the real binary
12686 file and get the name of dwp file from there. */
12687 std::string dwp_name
;
12688 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12690 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12691 const char *backlink_basename
= lbasename (backlink
->original_name
);
12693 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12696 dwp_name
= objfile
->original_name
;
12698 dwp_name
+= ".dwp";
12700 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12702 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12704 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12705 dwp_name
= objfile_name (objfile
);
12706 dwp_name
+= ".dwp";
12707 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12712 if (dwarf_read_debug
)
12713 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12714 return std::unique_ptr
<dwp_file
> ();
12717 const char *name
= bfd_get_filename (dbfd
.get ());
12718 std::unique_ptr
<struct dwp_file
> dwp_file
12719 (new struct dwp_file (name
, std::move (dbfd
)));
12721 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12722 dwp_file
->elf_sections
=
12723 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12724 dwp_file
->num_sections
, asection
*);
12726 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12727 dwarf2_locate_common_dwp_sections
,
12730 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12732 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12734 /* The DWP file version is stored in the hash table. Oh well. */
12735 if (dwp_file
->cus
&& dwp_file
->tus
12736 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12738 /* Technically speaking, we should try to limp along, but this is
12739 pretty bizarre. We use pulongest here because that's the established
12740 portability solution (e.g, we cannot use %u for uint32_t). */
12741 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12742 " TU version %s [in DWP file %s]"),
12743 pulongest (dwp_file
->cus
->version
),
12744 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12748 dwp_file
->version
= dwp_file
->cus
->version
;
12749 else if (dwp_file
->tus
)
12750 dwp_file
->version
= dwp_file
->tus
->version
;
12752 dwp_file
->version
= 2;
12754 if (dwp_file
->version
== 2)
12755 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12756 dwarf2_locate_v2_dwp_sections
,
12759 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12760 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12762 if (dwarf_read_debug
)
12764 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12765 fprintf_unfiltered (gdb_stdlog
,
12766 " %s CUs, %s TUs\n",
12767 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12768 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12774 /* Wrapper around open_and_init_dwp_file, only open it once. */
12776 static struct dwp_file
*
12777 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12779 if (!per_objfile
->per_bfd
->dwp_checked
)
12781 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12782 per_objfile
->per_bfd
->dwp_checked
= 1;
12784 return per_objfile
->per_bfd
->dwp_file
.get ();
12787 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12788 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12789 or in the DWP file for the objfile, referenced by THIS_UNIT.
12790 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12791 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12793 This is called, for example, when wanting to read a variable with a
12794 complex location. Therefore we don't want to do file i/o for every call.
12795 Therefore we don't want to look for a DWO file on every call.
12796 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12797 then we check if we've already seen DWO_NAME, and only THEN do we check
12800 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12801 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12803 static struct dwo_unit
*
12804 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12805 ULONGEST signature
, int is_debug_types
)
12807 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12808 struct objfile
*objfile
= per_objfile
->objfile
;
12809 const char *kind
= is_debug_types
? "TU" : "CU";
12810 void **dwo_file_slot
;
12811 struct dwo_file
*dwo_file
;
12812 struct dwp_file
*dwp_file
;
12814 /* First see if there's a DWP file.
12815 If we have a DWP file but didn't find the DWO inside it, don't
12816 look for the original DWO file. It makes gdb behave differently
12817 depending on whether one is debugging in the build tree. */
12819 dwp_file
= get_dwp_file (per_objfile
);
12820 if (dwp_file
!= NULL
)
12822 const struct dwp_hash_table
*dwp_htab
=
12823 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12825 if (dwp_htab
!= NULL
)
12827 struct dwo_unit
*dwo_cutu
=
12828 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12831 if (dwo_cutu
!= NULL
)
12833 if (dwarf_read_debug
)
12835 fprintf_unfiltered (gdb_stdlog
,
12836 "Virtual DWO %s %s found: @%s\n",
12837 kind
, hex_string (signature
),
12838 host_address_to_string (dwo_cutu
));
12846 /* No DWP file, look for the DWO file. */
12848 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12849 if (*dwo_file_slot
== NULL
)
12851 /* Read in the file and build a table of the CUs/TUs it contains. */
12852 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12854 /* NOTE: This will be NULL if unable to open the file. */
12855 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12857 if (dwo_file
!= NULL
)
12859 struct dwo_unit
*dwo_cutu
= NULL
;
12861 if (is_debug_types
&& dwo_file
->tus
)
12863 struct dwo_unit find_dwo_cutu
;
12865 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12866 find_dwo_cutu
.signature
= signature
;
12868 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12871 else if (!is_debug_types
&& dwo_file
->cus
)
12873 struct dwo_unit find_dwo_cutu
;
12875 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12876 find_dwo_cutu
.signature
= signature
;
12877 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12881 if (dwo_cutu
!= NULL
)
12883 if (dwarf_read_debug
)
12885 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12886 kind
, dwo_name
, hex_string (signature
),
12887 host_address_to_string (dwo_cutu
));
12894 /* We didn't find it. This could mean a dwo_id mismatch, or
12895 someone deleted the DWO/DWP file, or the search path isn't set up
12896 correctly to find the file. */
12898 if (dwarf_read_debug
)
12900 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12901 kind
, dwo_name
, hex_string (signature
));
12904 /* This is a warning and not a complaint because it can be caused by
12905 pilot error (e.g., user accidentally deleting the DWO). */
12907 /* Print the name of the DWP file if we looked there, helps the user
12908 better diagnose the problem. */
12909 std::string dwp_text
;
12911 if (dwp_file
!= NULL
)
12912 dwp_text
= string_printf (" [in DWP file %s]",
12913 lbasename (dwp_file
->name
));
12915 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12916 " [in module %s]"),
12917 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12918 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12923 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12924 See lookup_dwo_cutu_unit for details. */
12926 static struct dwo_unit
*
12927 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12928 ULONGEST signature
)
12930 gdb_assert (!cu
->per_cu
->is_debug_types
);
12932 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12935 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12936 See lookup_dwo_cutu_unit for details. */
12938 static struct dwo_unit
*
12939 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12941 gdb_assert (cu
->per_cu
->is_debug_types
);
12943 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12945 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12948 /* Traversal function for queue_and_load_all_dwo_tus. */
12951 queue_and_load_dwo_tu (void **slot
, void *info
)
12953 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12954 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12955 ULONGEST signature
= dwo_unit
->signature
;
12956 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12958 if (sig_type
!= NULL
)
12960 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12962 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12963 a real dependency of PER_CU on SIG_TYPE. That is detected later
12964 while processing PER_CU. */
12965 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12966 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12967 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12973 /* Queue all TUs contained in the DWO of CU to be read in.
12974 The DWO may have the only definition of the type, though it may not be
12975 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12976 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12979 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12981 struct dwo_unit
*dwo_unit
;
12982 struct dwo_file
*dwo_file
;
12984 gdb_assert (cu
!= nullptr);
12985 gdb_assert (!cu
->per_cu
->is_debug_types
);
12986 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12988 dwo_unit
= cu
->dwo_unit
;
12989 gdb_assert (dwo_unit
!= NULL
);
12991 dwo_file
= dwo_unit
->dwo_file
;
12992 if (dwo_file
->tus
!= NULL
)
12993 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12996 /* Read in various DIEs. */
12998 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12999 Inherit only the children of the DW_AT_abstract_origin DIE not being
13000 already referenced by DW_AT_abstract_origin from the children of the
13004 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13006 struct die_info
*child_die
;
13007 sect_offset
*offsetp
;
13008 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13009 struct die_info
*origin_die
;
13010 /* Iterator of the ORIGIN_DIE children. */
13011 struct die_info
*origin_child_die
;
13012 struct attribute
*attr
;
13013 struct dwarf2_cu
*origin_cu
;
13014 struct pending
**origin_previous_list_in_scope
;
13016 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13020 /* Note that following die references may follow to a die in a
13024 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13026 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13028 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13029 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13031 if (die
->tag
!= origin_die
->tag
13032 && !(die
->tag
== DW_TAG_inlined_subroutine
13033 && origin_die
->tag
== DW_TAG_subprogram
))
13034 complaint (_("DIE %s and its abstract origin %s have different tags"),
13035 sect_offset_str (die
->sect_off
),
13036 sect_offset_str (origin_die
->sect_off
));
13038 std::vector
<sect_offset
> offsets
;
13040 for (child_die
= die
->child
;
13041 child_die
&& child_die
->tag
;
13042 child_die
= child_die
->sibling
)
13044 struct die_info
*child_origin_die
;
13045 struct dwarf2_cu
*child_origin_cu
;
13047 /* We are trying to process concrete instance entries:
13048 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13049 it's not relevant to our analysis here. i.e. detecting DIEs that are
13050 present in the abstract instance but not referenced in the concrete
13052 if (child_die
->tag
== DW_TAG_call_site
13053 || child_die
->tag
== DW_TAG_GNU_call_site
)
13056 /* For each CHILD_DIE, find the corresponding child of
13057 ORIGIN_DIE. If there is more than one layer of
13058 DW_AT_abstract_origin, follow them all; there shouldn't be,
13059 but GCC versions at least through 4.4 generate this (GCC PR
13061 child_origin_die
= child_die
;
13062 child_origin_cu
= cu
;
13065 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13069 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13073 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13074 counterpart may exist. */
13075 if (child_origin_die
!= child_die
)
13077 if (child_die
->tag
!= child_origin_die
->tag
13078 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13079 && child_origin_die
->tag
== DW_TAG_subprogram
))
13080 complaint (_("Child DIE %s and its abstract origin %s have "
13082 sect_offset_str (child_die
->sect_off
),
13083 sect_offset_str (child_origin_die
->sect_off
));
13084 if (child_origin_die
->parent
!= origin_die
)
13085 complaint (_("Child DIE %s and its abstract origin %s have "
13086 "different parents"),
13087 sect_offset_str (child_die
->sect_off
),
13088 sect_offset_str (child_origin_die
->sect_off
));
13090 offsets
.push_back (child_origin_die
->sect_off
);
13093 std::sort (offsets
.begin (), offsets
.end ());
13094 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13095 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13096 if (offsetp
[-1] == *offsetp
)
13097 complaint (_("Multiple children of DIE %s refer "
13098 "to DIE %s as their abstract origin"),
13099 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13101 offsetp
= offsets
.data ();
13102 origin_child_die
= origin_die
->child
;
13103 while (origin_child_die
&& origin_child_die
->tag
)
13105 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13106 while (offsetp
< offsets_end
13107 && *offsetp
< origin_child_die
->sect_off
)
13109 if (offsetp
>= offsets_end
13110 || *offsetp
> origin_child_die
->sect_off
)
13112 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13113 Check whether we're already processing ORIGIN_CHILD_DIE.
13114 This can happen with mutually referenced abstract_origins.
13116 if (!origin_child_die
->in_process
)
13117 process_die (origin_child_die
, origin_cu
);
13119 origin_child_die
= origin_child_die
->sibling
;
13121 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13123 if (cu
!= origin_cu
)
13124 compute_delayed_physnames (origin_cu
);
13128 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13130 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13131 struct gdbarch
*gdbarch
= objfile
->arch ();
13132 struct context_stack
*newobj
;
13135 struct die_info
*child_die
;
13136 struct attribute
*attr
, *call_line
, *call_file
;
13138 CORE_ADDR baseaddr
;
13139 struct block
*block
;
13140 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13141 std::vector
<struct symbol
*> template_args
;
13142 struct template_symbol
*templ_func
= NULL
;
13146 /* If we do not have call site information, we can't show the
13147 caller of this inlined function. That's too confusing, so
13148 only use the scope for local variables. */
13149 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13150 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13151 if (call_line
== NULL
|| call_file
== NULL
)
13153 read_lexical_block_scope (die
, cu
);
13158 baseaddr
= objfile
->text_section_offset ();
13160 name
= dwarf2_name (die
, cu
);
13162 /* Ignore functions with missing or empty names. These are actually
13163 illegal according to the DWARF standard. */
13166 complaint (_("missing name for subprogram DIE at %s"),
13167 sect_offset_str (die
->sect_off
));
13171 /* Ignore functions with missing or invalid low and high pc attributes. */
13172 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13173 <= PC_BOUNDS_INVALID
)
13175 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13176 if (!attr
|| !DW_UNSND (attr
))
13177 complaint (_("cannot get low and high bounds "
13178 "for subprogram DIE at %s"),
13179 sect_offset_str (die
->sect_off
));
13183 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13184 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13186 /* If we have any template arguments, then we must allocate a
13187 different sort of symbol. */
13188 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13190 if (child_die
->tag
== DW_TAG_template_type_param
13191 || child_die
->tag
== DW_TAG_template_value_param
)
13193 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13194 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13199 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13200 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13201 (struct symbol
*) templ_func
);
13203 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13204 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13207 /* If there is a location expression for DW_AT_frame_base, record
13209 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13210 if (attr
!= nullptr)
13211 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13213 /* If there is a location for the static link, record it. */
13214 newobj
->static_link
= NULL
;
13215 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13216 if (attr
!= nullptr)
13218 newobj
->static_link
13219 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13220 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13224 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13226 if (die
->child
!= NULL
)
13228 child_die
= die
->child
;
13229 while (child_die
&& child_die
->tag
)
13231 if (child_die
->tag
== DW_TAG_template_type_param
13232 || child_die
->tag
== DW_TAG_template_value_param
)
13234 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13237 template_args
.push_back (arg
);
13240 process_die (child_die
, cu
);
13241 child_die
= child_die
->sibling
;
13245 inherit_abstract_dies (die
, cu
);
13247 /* If we have a DW_AT_specification, we might need to import using
13248 directives from the context of the specification DIE. See the
13249 comment in determine_prefix. */
13250 if (cu
->language
== language_cplus
13251 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13253 struct dwarf2_cu
*spec_cu
= cu
;
13254 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13258 child_die
= spec_die
->child
;
13259 while (child_die
&& child_die
->tag
)
13261 if (child_die
->tag
== DW_TAG_imported_module
)
13262 process_die (child_die
, spec_cu
);
13263 child_die
= child_die
->sibling
;
13266 /* In some cases, GCC generates specification DIEs that
13267 themselves contain DW_AT_specification attributes. */
13268 spec_die
= die_specification (spec_die
, &spec_cu
);
13272 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13273 /* Make a block for the local symbols within. */
13274 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13275 cstk
.static_link
, lowpc
, highpc
);
13277 /* For C++, set the block's scope. */
13278 if ((cu
->language
== language_cplus
13279 || cu
->language
== language_fortran
13280 || cu
->language
== language_d
13281 || cu
->language
== language_rust
)
13282 && cu
->processing_has_namespace_info
)
13283 block_set_scope (block
, determine_prefix (die
, cu
),
13284 &objfile
->objfile_obstack
);
13286 /* If we have address ranges, record them. */
13287 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13289 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13291 /* Attach template arguments to function. */
13292 if (!template_args
.empty ())
13294 gdb_assert (templ_func
!= NULL
);
13296 templ_func
->n_template_arguments
= template_args
.size ();
13297 templ_func
->template_arguments
13298 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13299 templ_func
->n_template_arguments
);
13300 memcpy (templ_func
->template_arguments
,
13301 template_args
.data (),
13302 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13304 /* Make sure that the symtab is set on the new symbols. Even
13305 though they don't appear in this symtab directly, other parts
13306 of gdb assume that symbols do, and this is reasonably
13308 for (symbol
*sym
: template_args
)
13309 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13312 /* In C++, we can have functions nested inside functions (e.g., when
13313 a function declares a class that has methods). This means that
13314 when we finish processing a function scope, we may need to go
13315 back to building a containing block's symbol lists. */
13316 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13317 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13319 /* If we've finished processing a top-level function, subsequent
13320 symbols go in the file symbol list. */
13321 if (cu
->get_builder ()->outermost_context_p ())
13322 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13325 /* Process all the DIES contained within a lexical block scope. Start
13326 a new scope, process the dies, and then close the scope. */
13329 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13331 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13332 struct gdbarch
*gdbarch
= objfile
->arch ();
13333 CORE_ADDR lowpc
, highpc
;
13334 struct die_info
*child_die
;
13335 CORE_ADDR baseaddr
;
13337 baseaddr
= objfile
->text_section_offset ();
13339 /* Ignore blocks with missing or invalid low and high pc attributes. */
13340 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13341 as multiple lexical blocks? Handling children in a sane way would
13342 be nasty. Might be easier to properly extend generic blocks to
13343 describe ranges. */
13344 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13346 case PC_BOUNDS_NOT_PRESENT
:
13347 /* DW_TAG_lexical_block has no attributes, process its children as if
13348 there was no wrapping by that DW_TAG_lexical_block.
13349 GCC does no longer produces such DWARF since GCC r224161. */
13350 for (child_die
= die
->child
;
13351 child_die
!= NULL
&& child_die
->tag
;
13352 child_die
= child_die
->sibling
)
13354 /* We might already be processing this DIE. This can happen
13355 in an unusual circumstance -- where a subroutine A
13356 appears lexically in another subroutine B, but A actually
13357 inlines B. The recursion is broken here, rather than in
13358 inherit_abstract_dies, because it seems better to simply
13359 drop concrete children here. */
13360 if (!child_die
->in_process
)
13361 process_die (child_die
, cu
);
13364 case PC_BOUNDS_INVALID
:
13367 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13368 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13370 cu
->get_builder ()->push_context (0, lowpc
);
13371 if (die
->child
!= NULL
)
13373 child_die
= die
->child
;
13374 while (child_die
&& child_die
->tag
)
13376 process_die (child_die
, cu
);
13377 child_die
= child_die
->sibling
;
13380 inherit_abstract_dies (die
, cu
);
13381 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13383 if (*cu
->get_builder ()->get_local_symbols () != NULL
13384 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13386 struct block
*block
13387 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13388 cstk
.start_addr
, highpc
);
13390 /* Note that recording ranges after traversing children, as we
13391 do here, means that recording a parent's ranges entails
13392 walking across all its children's ranges as they appear in
13393 the address map, which is quadratic behavior.
13395 It would be nicer to record the parent's ranges before
13396 traversing its children, simply overriding whatever you find
13397 there. But since we don't even decide whether to create a
13398 block until after we've traversed its children, that's hard
13400 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13402 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13403 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13406 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13409 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13411 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13412 struct objfile
*objfile
= per_objfile
->objfile
;
13413 struct gdbarch
*gdbarch
= objfile
->arch ();
13414 CORE_ADDR pc
, baseaddr
;
13415 struct attribute
*attr
;
13416 struct call_site
*call_site
, call_site_local
;
13419 struct die_info
*child_die
;
13421 baseaddr
= objfile
->text_section_offset ();
13423 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13426 /* This was a pre-DWARF-5 GNU extension alias
13427 for DW_AT_call_return_pc. */
13428 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13432 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13433 "DIE %s [in module %s]"),
13434 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13437 pc
= attr
->value_as_address () + baseaddr
;
13438 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13440 if (cu
->call_site_htab
== NULL
)
13441 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13442 NULL
, &objfile
->objfile_obstack
,
13443 hashtab_obstack_allocate
, NULL
);
13444 call_site_local
.pc
= pc
;
13445 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13448 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13449 "DIE %s [in module %s]"),
13450 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13451 objfile_name (objfile
));
13455 /* Count parameters at the caller. */
13458 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13459 child_die
= child_die
->sibling
)
13461 if (child_die
->tag
!= DW_TAG_call_site_parameter
13462 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13464 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13465 "DW_TAG_call_site child DIE %s [in module %s]"),
13466 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13467 objfile_name (objfile
));
13475 = ((struct call_site
*)
13476 obstack_alloc (&objfile
->objfile_obstack
,
13477 sizeof (*call_site
)
13478 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13480 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13481 call_site
->pc
= pc
;
13483 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13484 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13486 struct die_info
*func_die
;
13488 /* Skip also over DW_TAG_inlined_subroutine. */
13489 for (func_die
= die
->parent
;
13490 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13491 && func_die
->tag
!= DW_TAG_subroutine_type
;
13492 func_die
= func_die
->parent
);
13494 /* DW_AT_call_all_calls is a superset
13495 of DW_AT_call_all_tail_calls. */
13497 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13498 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13499 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13500 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13502 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13503 not complete. But keep CALL_SITE for look ups via call_site_htab,
13504 both the initial caller containing the real return address PC and
13505 the final callee containing the current PC of a chain of tail
13506 calls do not need to have the tail call list complete. But any
13507 function candidate for a virtual tail call frame searched via
13508 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13509 determined unambiguously. */
13513 struct type
*func_type
= NULL
;
13516 func_type
= get_die_type (func_die
, cu
);
13517 if (func_type
!= NULL
)
13519 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13521 /* Enlist this call site to the function. */
13522 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13523 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13526 complaint (_("Cannot find function owning DW_TAG_call_site "
13527 "DIE %s [in module %s]"),
13528 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13532 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13534 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13536 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13539 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13540 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13542 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13543 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13544 /* Keep NULL DWARF_BLOCK. */;
13545 else if (attr
->form_is_block ())
13547 struct dwarf2_locexpr_baton
*dlbaton
;
13549 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13550 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13551 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13552 dlbaton
->per_objfile
= per_objfile
;
13553 dlbaton
->per_cu
= cu
->per_cu
;
13555 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13557 else if (attr
->form_is_ref ())
13559 struct dwarf2_cu
*target_cu
= cu
;
13560 struct die_info
*target_die
;
13562 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13563 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13564 if (die_is_declaration (target_die
, target_cu
))
13566 const char *target_physname
;
13568 /* Prefer the mangled name; otherwise compute the demangled one. */
13569 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13570 if (target_physname
== NULL
)
13571 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13572 if (target_physname
== NULL
)
13573 complaint (_("DW_AT_call_target target DIE has invalid "
13574 "physname, for referencing DIE %s [in module %s]"),
13575 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13577 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13583 /* DW_AT_entry_pc should be preferred. */
13584 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13585 <= PC_BOUNDS_INVALID
)
13586 complaint (_("DW_AT_call_target target DIE has invalid "
13587 "low pc, for referencing DIE %s [in module %s]"),
13588 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13591 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13592 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13597 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13598 "block nor reference, for DIE %s [in module %s]"),
13599 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13601 call_site
->per_cu
= cu
->per_cu
;
13602 call_site
->per_objfile
= per_objfile
;
13604 for (child_die
= die
->child
;
13605 child_die
&& child_die
->tag
;
13606 child_die
= child_die
->sibling
)
13608 struct call_site_parameter
*parameter
;
13609 struct attribute
*loc
, *origin
;
13611 if (child_die
->tag
!= DW_TAG_call_site_parameter
13612 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13614 /* Already printed the complaint above. */
13618 gdb_assert (call_site
->parameter_count
< nparams
);
13619 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13621 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13622 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13623 register is contained in DW_AT_call_value. */
13625 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13626 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13627 if (origin
== NULL
)
13629 /* This was a pre-DWARF-5 GNU extension alias
13630 for DW_AT_call_parameter. */
13631 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13633 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13635 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13637 sect_offset sect_off
= origin
->get_ref_die_offset ();
13638 if (!cu
->header
.offset_in_cu_p (sect_off
))
13640 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13641 binding can be done only inside one CU. Such referenced DIE
13642 therefore cannot be even moved to DW_TAG_partial_unit. */
13643 complaint (_("DW_AT_call_parameter offset is not in CU for "
13644 "DW_TAG_call_site child DIE %s [in module %s]"),
13645 sect_offset_str (child_die
->sect_off
),
13646 objfile_name (objfile
));
13649 parameter
->u
.param_cu_off
13650 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13652 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13654 complaint (_("No DW_FORM_block* DW_AT_location for "
13655 "DW_TAG_call_site child DIE %s [in module %s]"),
13656 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13661 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13662 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13663 if (parameter
->u
.dwarf_reg
!= -1)
13664 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13665 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13666 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13667 ¶meter
->u
.fb_offset
))
13668 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13671 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13672 "for DW_FORM_block* DW_AT_location is supported for "
13673 "DW_TAG_call_site child DIE %s "
13675 sect_offset_str (child_die
->sect_off
),
13676 objfile_name (objfile
));
13681 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13683 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13684 if (attr
== NULL
|| !attr
->form_is_block ())
13686 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13687 "DW_TAG_call_site child DIE %s [in module %s]"),
13688 sect_offset_str (child_die
->sect_off
),
13689 objfile_name (objfile
));
13692 parameter
->value
= DW_BLOCK (attr
)->data
;
13693 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13695 /* Parameters are not pre-cleared by memset above. */
13696 parameter
->data_value
= NULL
;
13697 parameter
->data_value_size
= 0;
13698 call_site
->parameter_count
++;
13700 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13702 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13703 if (attr
!= nullptr)
13705 if (!attr
->form_is_block ())
13706 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13707 "DW_TAG_call_site child DIE %s [in module %s]"),
13708 sect_offset_str (child_die
->sect_off
),
13709 objfile_name (objfile
));
13712 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13713 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13719 /* Helper function for read_variable. If DIE represents a virtual
13720 table, then return the type of the concrete object that is
13721 associated with the virtual table. Otherwise, return NULL. */
13723 static struct type
*
13724 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13726 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13730 /* Find the type DIE. */
13731 struct die_info
*type_die
= NULL
;
13732 struct dwarf2_cu
*type_cu
= cu
;
13734 if (attr
->form_is_ref ())
13735 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13736 if (type_die
== NULL
)
13739 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13741 return die_containing_type (type_die
, type_cu
);
13744 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13747 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13749 struct rust_vtable_symbol
*storage
= NULL
;
13751 if (cu
->language
== language_rust
)
13753 struct type
*containing_type
= rust_containing_type (die
, cu
);
13755 if (containing_type
!= NULL
)
13757 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13759 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13760 storage
->concrete_type
= containing_type
;
13761 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13765 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13766 struct attribute
*abstract_origin
13767 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13768 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13769 if (res
== NULL
&& loc
&& abstract_origin
)
13771 /* We have a variable without a name, but with a location and an abstract
13772 origin. This may be a concrete instance of an abstract variable
13773 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13775 struct dwarf2_cu
*origin_cu
= cu
;
13776 struct die_info
*origin_die
13777 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13778 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13779 per_objfile
->per_bfd
->abstract_to_concrete
13780 [origin_die
->sect_off
].push_back (die
->sect_off
);
13784 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13785 reading .debug_rnglists.
13786 Callback's type should be:
13787 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13788 Return true if the attributes are present and valid, otherwise,
13791 template <typename Callback
>
13793 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13794 Callback
&&callback
)
13796 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13797 struct objfile
*objfile
= per_objfile
->objfile
;
13798 bfd
*obfd
= objfile
->obfd
;
13799 /* Base address selection entry. */
13800 gdb::optional
<CORE_ADDR
> base
;
13801 const gdb_byte
*buffer
;
13802 CORE_ADDR baseaddr
;
13803 bool overflow
= false;
13805 base
= cu
->base_address
;
13807 per_objfile
->per_bfd
->rnglists
.read (objfile
);
13808 if (offset
>= per_objfile
->per_bfd
->rnglists
.size
)
13810 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13814 buffer
= per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13816 baseaddr
= objfile
->text_section_offset ();
13820 /* Initialize it due to a false compiler warning. */
13821 CORE_ADDR range_beginning
= 0, range_end
= 0;
13822 const gdb_byte
*buf_end
= (per_objfile
->per_bfd
->rnglists
.buffer
13823 + per_objfile
->per_bfd
->rnglists
.size
);
13824 unsigned int bytes_read
;
13826 if (buffer
== buf_end
)
13831 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13834 case DW_RLE_end_of_list
:
13836 case DW_RLE_base_address
:
13837 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13842 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13843 buffer
+= bytes_read
;
13845 case DW_RLE_start_length
:
13846 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13851 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13853 buffer
+= bytes_read
;
13854 range_end
= (range_beginning
13855 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13856 buffer
+= bytes_read
;
13857 if (buffer
> buf_end
)
13863 case DW_RLE_offset_pair
:
13864 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13865 buffer
+= bytes_read
;
13866 if (buffer
> buf_end
)
13871 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13872 buffer
+= bytes_read
;
13873 if (buffer
> buf_end
)
13879 case DW_RLE_start_end
:
13880 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13885 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13887 buffer
+= bytes_read
;
13888 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13889 buffer
+= bytes_read
;
13892 complaint (_("Invalid .debug_rnglists data (no base address)"));
13895 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13897 if (rlet
== DW_RLE_base_address
)
13900 if (!base
.has_value ())
13902 /* We have no valid base address for the ranges
13904 complaint (_("Invalid .debug_rnglists data (no base address)"));
13908 if (range_beginning
> range_end
)
13910 /* Inverted range entries are invalid. */
13911 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13915 /* Empty range entries have no effect. */
13916 if (range_beginning
== range_end
)
13919 range_beginning
+= *base
;
13920 range_end
+= *base
;
13922 /* A not-uncommon case of bad debug info.
13923 Don't pollute the addrmap with bad data. */
13924 if (range_beginning
+ baseaddr
== 0
13925 && !per_objfile
->per_bfd
->has_section_at_zero
)
13927 complaint (_(".debug_rnglists entry has start address of zero"
13928 " [in module %s]"), objfile_name (objfile
));
13932 callback (range_beginning
, range_end
);
13937 complaint (_("Offset %d is not terminated "
13938 "for DW_AT_ranges attribute"),
13946 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13947 Callback's type should be:
13948 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13949 Return 1 if the attributes are present and valid, otherwise, return 0. */
13951 template <typename Callback
>
13953 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13954 Callback
&&callback
)
13956 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13957 struct objfile
*objfile
= per_objfile
->objfile
;
13958 struct comp_unit_head
*cu_header
= &cu
->header
;
13959 bfd
*obfd
= objfile
->obfd
;
13960 unsigned int addr_size
= cu_header
->addr_size
;
13961 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13962 /* Base address selection entry. */
13963 gdb::optional
<CORE_ADDR
> base
;
13964 unsigned int dummy
;
13965 const gdb_byte
*buffer
;
13966 CORE_ADDR baseaddr
;
13968 if (cu_header
->version
>= 5)
13969 return dwarf2_rnglists_process (offset
, cu
, callback
);
13971 base
= cu
->base_address
;
13973 per_objfile
->per_bfd
->ranges
.read (objfile
);
13974 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13976 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13980 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13982 baseaddr
= objfile
->text_section_offset ();
13986 CORE_ADDR range_beginning
, range_end
;
13988 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13989 buffer
+= addr_size
;
13990 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13991 buffer
+= addr_size
;
13992 offset
+= 2 * addr_size
;
13994 /* An end of list marker is a pair of zero addresses. */
13995 if (range_beginning
== 0 && range_end
== 0)
13996 /* Found the end of list entry. */
13999 /* Each base address selection entry is a pair of 2 values.
14000 The first is the largest possible address, the second is
14001 the base address. Check for a base address here. */
14002 if ((range_beginning
& mask
) == mask
)
14004 /* If we found the largest possible address, then we already
14005 have the base address in range_end. */
14010 if (!base
.has_value ())
14012 /* We have no valid base address for the ranges
14014 complaint (_("Invalid .debug_ranges data (no base address)"));
14018 if (range_beginning
> range_end
)
14020 /* Inverted range entries are invalid. */
14021 complaint (_("Invalid .debug_ranges data (inverted range)"));
14025 /* Empty range entries have no effect. */
14026 if (range_beginning
== range_end
)
14029 range_beginning
+= *base
;
14030 range_end
+= *base
;
14032 /* A not-uncommon case of bad debug info.
14033 Don't pollute the addrmap with bad data. */
14034 if (range_beginning
+ baseaddr
== 0
14035 && !per_objfile
->per_bfd
->has_section_at_zero
)
14037 complaint (_(".debug_ranges entry has start address of zero"
14038 " [in module %s]"), objfile_name (objfile
));
14042 callback (range_beginning
, range_end
);
14048 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14049 Return 1 if the attributes are present and valid, otherwise, return 0.
14050 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14053 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14054 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14055 dwarf2_psymtab
*ranges_pst
)
14057 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14058 struct gdbarch
*gdbarch
= objfile
->arch ();
14059 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14062 CORE_ADDR high
= 0;
14065 retval
= dwarf2_ranges_process (offset
, cu
,
14066 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14068 if (ranges_pst
!= NULL
)
14073 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14074 range_beginning
+ baseaddr
)
14076 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14077 range_end
+ baseaddr
)
14079 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14080 lowpc
, highpc
- 1, ranges_pst
);
14083 /* FIXME: This is recording everything as a low-high
14084 segment of consecutive addresses. We should have a
14085 data structure for discontiguous block ranges
14089 low
= range_beginning
;
14095 if (range_beginning
< low
)
14096 low
= range_beginning
;
14097 if (range_end
> high
)
14105 /* If the first entry is an end-of-list marker, the range
14106 describes an empty scope, i.e. no instructions. */
14112 *high_return
= high
;
14116 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14117 definition for the return value. *LOWPC and *HIGHPC are set iff
14118 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14120 static enum pc_bounds_kind
14121 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14122 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14123 dwarf2_psymtab
*pst
)
14125 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14126 struct attribute
*attr
;
14127 struct attribute
*attr_high
;
14129 CORE_ADDR high
= 0;
14130 enum pc_bounds_kind ret
;
14132 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14135 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14136 if (attr
!= nullptr)
14138 low
= attr
->value_as_address ();
14139 high
= attr_high
->value_as_address ();
14140 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14144 /* Found high w/o low attribute. */
14145 return PC_BOUNDS_INVALID
;
14147 /* Found consecutive range of addresses. */
14148 ret
= PC_BOUNDS_HIGH_LOW
;
14152 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14155 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14156 We take advantage of the fact that DW_AT_ranges does not appear
14157 in DW_TAG_compile_unit of DWO files. */
14158 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14159 unsigned int ranges_offset
= (DW_UNSND (attr
)
14160 + (need_ranges_base
14164 /* Value of the DW_AT_ranges attribute is the offset in the
14165 .debug_ranges section. */
14166 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14167 return PC_BOUNDS_INVALID
;
14168 /* Found discontinuous range of addresses. */
14169 ret
= PC_BOUNDS_RANGES
;
14172 return PC_BOUNDS_NOT_PRESENT
;
14175 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14177 return PC_BOUNDS_INVALID
;
14179 /* When using the GNU linker, .gnu.linkonce. sections are used to
14180 eliminate duplicate copies of functions and vtables and such.
14181 The linker will arbitrarily choose one and discard the others.
14182 The AT_*_pc values for such functions refer to local labels in
14183 these sections. If the section from that file was discarded, the
14184 labels are not in the output, so the relocs get a value of 0.
14185 If this is a discarded function, mark the pc bounds as invalid,
14186 so that GDB will ignore it. */
14187 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14188 return PC_BOUNDS_INVALID
;
14196 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14197 its low and high PC addresses. Do nothing if these addresses could not
14198 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14199 and HIGHPC to the high address if greater than HIGHPC. */
14202 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14203 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14204 struct dwarf2_cu
*cu
)
14206 CORE_ADDR low
, high
;
14207 struct die_info
*child
= die
->child
;
14209 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14211 *lowpc
= std::min (*lowpc
, low
);
14212 *highpc
= std::max (*highpc
, high
);
14215 /* If the language does not allow nested subprograms (either inside
14216 subprograms or lexical blocks), we're done. */
14217 if (cu
->language
!= language_ada
)
14220 /* Check all the children of the given DIE. If it contains nested
14221 subprograms, then check their pc bounds. Likewise, we need to
14222 check lexical blocks as well, as they may also contain subprogram
14224 while (child
&& child
->tag
)
14226 if (child
->tag
== DW_TAG_subprogram
14227 || child
->tag
== DW_TAG_lexical_block
)
14228 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14229 child
= child
->sibling
;
14233 /* Get the low and high pc's represented by the scope DIE, and store
14234 them in *LOWPC and *HIGHPC. If the correct values can't be
14235 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14238 get_scope_pc_bounds (struct die_info
*die
,
14239 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14240 struct dwarf2_cu
*cu
)
14242 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14243 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14244 CORE_ADDR current_low
, current_high
;
14246 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14247 >= PC_BOUNDS_RANGES
)
14249 best_low
= current_low
;
14250 best_high
= current_high
;
14254 struct die_info
*child
= die
->child
;
14256 while (child
&& child
->tag
)
14258 switch (child
->tag
) {
14259 case DW_TAG_subprogram
:
14260 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14262 case DW_TAG_namespace
:
14263 case DW_TAG_module
:
14264 /* FIXME: carlton/2004-01-16: Should we do this for
14265 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14266 that current GCC's always emit the DIEs corresponding
14267 to definitions of methods of classes as children of a
14268 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14269 the DIEs giving the declarations, which could be
14270 anywhere). But I don't see any reason why the
14271 standards says that they have to be there. */
14272 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14274 if (current_low
!= ((CORE_ADDR
) -1))
14276 best_low
= std::min (best_low
, current_low
);
14277 best_high
= std::max (best_high
, current_high
);
14285 child
= child
->sibling
;
14290 *highpc
= best_high
;
14293 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14297 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14298 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14300 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14301 struct gdbarch
*gdbarch
= objfile
->arch ();
14302 struct attribute
*attr
;
14303 struct attribute
*attr_high
;
14305 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14308 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14309 if (attr
!= nullptr)
14311 CORE_ADDR low
= attr
->value_as_address ();
14312 CORE_ADDR high
= attr_high
->value_as_address ();
14314 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14317 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14318 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14319 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14323 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14324 if (attr
!= nullptr)
14326 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14327 We take advantage of the fact that DW_AT_ranges does not appear
14328 in DW_TAG_compile_unit of DWO files. */
14329 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14331 /* The value of the DW_AT_ranges attribute is the offset of the
14332 address range list in the .debug_ranges section. */
14333 unsigned long offset
= (DW_UNSND (attr
)
14334 + (need_ranges_base
? cu
->ranges_base
: 0));
14336 std::vector
<blockrange
> blockvec
;
14337 dwarf2_ranges_process (offset
, cu
,
14338 [&] (CORE_ADDR start
, CORE_ADDR end
)
14342 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14343 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14344 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14345 blockvec
.emplace_back (start
, end
);
14348 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14352 /* Check whether the producer field indicates either of GCC < 4.6, or the
14353 Intel C/C++ compiler, and cache the result in CU. */
14356 check_producer (struct dwarf2_cu
*cu
)
14360 if (cu
->producer
== NULL
)
14362 /* For unknown compilers expect their behavior is DWARF version
14365 GCC started to support .debug_types sections by -gdwarf-4 since
14366 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14367 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14368 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14369 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14371 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14373 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14374 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14376 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14378 cu
->producer_is_icc
= true;
14379 cu
->producer_is_icc_lt_14
= major
< 14;
14381 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14382 cu
->producer_is_codewarrior
= true;
14385 /* For other non-GCC compilers, expect their behavior is DWARF version
14389 cu
->checked_producer
= true;
14392 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14393 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14394 during 4.6.0 experimental. */
14397 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14399 if (!cu
->checked_producer
)
14400 check_producer (cu
);
14402 return cu
->producer_is_gxx_lt_4_6
;
14406 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14407 with incorrect is_stmt attributes. */
14410 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14412 if (!cu
->checked_producer
)
14413 check_producer (cu
);
14415 return cu
->producer_is_codewarrior
;
14418 /* Return the default accessibility type if it is not overridden by
14419 DW_AT_accessibility. */
14421 static enum dwarf_access_attribute
14422 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14424 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14426 /* The default DWARF 2 accessibility for members is public, the default
14427 accessibility for inheritance is private. */
14429 if (die
->tag
!= DW_TAG_inheritance
)
14430 return DW_ACCESS_public
;
14432 return DW_ACCESS_private
;
14436 /* DWARF 3+ defines the default accessibility a different way. The same
14437 rules apply now for DW_TAG_inheritance as for the members and it only
14438 depends on the container kind. */
14440 if (die
->parent
->tag
== DW_TAG_class_type
)
14441 return DW_ACCESS_private
;
14443 return DW_ACCESS_public
;
14447 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14448 offset. If the attribute was not found return 0, otherwise return
14449 1. If it was found but could not properly be handled, set *OFFSET
14453 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14456 struct attribute
*attr
;
14458 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14463 /* Note that we do not check for a section offset first here.
14464 This is because DW_AT_data_member_location is new in DWARF 4,
14465 so if we see it, we can assume that a constant form is really
14466 a constant and not a section offset. */
14467 if (attr
->form_is_constant ())
14468 *offset
= attr
->constant_value (0);
14469 else if (attr
->form_is_section_offset ())
14470 dwarf2_complex_location_expr_complaint ();
14471 else if (attr
->form_is_block ())
14472 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14474 dwarf2_complex_location_expr_complaint ();
14482 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14485 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14486 struct field
*field
)
14488 struct attribute
*attr
;
14490 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14493 if (attr
->form_is_constant ())
14495 LONGEST offset
= attr
->constant_value (0);
14496 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14498 else if (attr
->form_is_section_offset ())
14499 dwarf2_complex_location_expr_complaint ();
14500 else if (attr
->form_is_block ())
14503 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14505 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14508 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14509 struct objfile
*objfile
= per_objfile
->objfile
;
14510 struct dwarf2_locexpr_baton
*dlbaton
14511 = XOBNEW (&objfile
->objfile_obstack
,
14512 struct dwarf2_locexpr_baton
);
14513 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14514 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14515 /* When using this baton, we want to compute the address
14516 of the field, not the value. This is why
14517 is_reference is set to false here. */
14518 dlbaton
->is_reference
= false;
14519 dlbaton
->per_objfile
= per_objfile
;
14520 dlbaton
->per_cu
= cu
->per_cu
;
14522 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14526 dwarf2_complex_location_expr_complaint ();
14530 /* Add an aggregate field to the field list. */
14533 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14534 struct dwarf2_cu
*cu
)
14536 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14537 struct gdbarch
*gdbarch
= objfile
->arch ();
14538 struct nextfield
*new_field
;
14539 struct attribute
*attr
;
14541 const char *fieldname
= "";
14543 if (die
->tag
== DW_TAG_inheritance
)
14545 fip
->baseclasses
.emplace_back ();
14546 new_field
= &fip
->baseclasses
.back ();
14550 fip
->fields
.emplace_back ();
14551 new_field
= &fip
->fields
.back ();
14554 new_field
->offset
= die
->sect_off
;
14556 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14557 if (attr
!= nullptr)
14558 new_field
->accessibility
= DW_UNSND (attr
);
14560 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14561 if (new_field
->accessibility
!= DW_ACCESS_public
)
14562 fip
->non_public_fields
= 1;
14564 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14565 if (attr
!= nullptr)
14566 new_field
->virtuality
= DW_UNSND (attr
);
14568 new_field
->virtuality
= DW_VIRTUALITY_none
;
14570 fp
= &new_field
->field
;
14572 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14574 /* Data member other than a C++ static data member. */
14576 /* Get type of field. */
14577 fp
->set_type (die_type (die
, cu
));
14579 SET_FIELD_BITPOS (*fp
, 0);
14581 /* Get bit size of field (zero if none). */
14582 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14583 if (attr
!= nullptr)
14585 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14589 FIELD_BITSIZE (*fp
) = 0;
14592 /* Get bit offset of field. */
14593 handle_data_member_location (die
, cu
, fp
);
14594 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14595 if (attr
!= nullptr)
14597 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14599 /* For big endian bits, the DW_AT_bit_offset gives the
14600 additional bit offset from the MSB of the containing
14601 anonymous object to the MSB of the field. We don't
14602 have to do anything special since we don't need to
14603 know the size of the anonymous object. */
14604 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14608 /* For little endian bits, compute the bit offset to the
14609 MSB of the anonymous object, subtract off the number of
14610 bits from the MSB of the field to the MSB of the
14611 object, and then subtract off the number of bits of
14612 the field itself. The result is the bit offset of
14613 the LSB of the field. */
14614 int anonymous_size
;
14615 int bit_offset
= DW_UNSND (attr
);
14617 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14618 if (attr
!= nullptr)
14620 /* The size of the anonymous object containing
14621 the bit field is explicit, so use the
14622 indicated size (in bytes). */
14623 anonymous_size
= DW_UNSND (attr
);
14627 /* The size of the anonymous object containing
14628 the bit field must be inferred from the type
14629 attribute of the data member containing the
14631 anonymous_size
= TYPE_LENGTH (fp
->type ());
14633 SET_FIELD_BITPOS (*fp
,
14634 (FIELD_BITPOS (*fp
)
14635 + anonymous_size
* bits_per_byte
14636 - bit_offset
- FIELD_BITSIZE (*fp
)));
14639 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14641 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14642 + attr
->constant_value (0)));
14644 /* Get name of field. */
14645 fieldname
= dwarf2_name (die
, cu
);
14646 if (fieldname
== NULL
)
14649 /* The name is already allocated along with this objfile, so we don't
14650 need to duplicate it for the type. */
14651 fp
->name
= fieldname
;
14653 /* Change accessibility for artificial fields (e.g. virtual table
14654 pointer or virtual base class pointer) to private. */
14655 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14657 FIELD_ARTIFICIAL (*fp
) = 1;
14658 new_field
->accessibility
= DW_ACCESS_private
;
14659 fip
->non_public_fields
= 1;
14662 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14664 /* C++ static member. */
14666 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14667 is a declaration, but all versions of G++ as of this writing
14668 (so through at least 3.2.1) incorrectly generate
14669 DW_TAG_variable tags. */
14671 const char *physname
;
14673 /* Get name of field. */
14674 fieldname
= dwarf2_name (die
, cu
);
14675 if (fieldname
== NULL
)
14678 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14680 /* Only create a symbol if this is an external value.
14681 new_symbol checks this and puts the value in the global symbol
14682 table, which we want. If it is not external, new_symbol
14683 will try to put the value in cu->list_in_scope which is wrong. */
14684 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14686 /* A static const member, not much different than an enum as far as
14687 we're concerned, except that we can support more types. */
14688 new_symbol (die
, NULL
, cu
);
14691 /* Get physical name. */
14692 physname
= dwarf2_physname (fieldname
, die
, cu
);
14694 /* The name is already allocated along with this objfile, so we don't
14695 need to duplicate it for the type. */
14696 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14697 fp
->set_type (die_type (die
, cu
));
14698 FIELD_NAME (*fp
) = fieldname
;
14700 else if (die
->tag
== DW_TAG_inheritance
)
14702 /* C++ base class field. */
14703 handle_data_member_location (die
, cu
, fp
);
14704 FIELD_BITSIZE (*fp
) = 0;
14705 fp
->set_type (die_type (die
, cu
));
14706 FIELD_NAME (*fp
) = fp
->type ()->name ();
14709 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14712 /* Can the type given by DIE define another type? */
14715 type_can_define_types (const struct die_info
*die
)
14719 case DW_TAG_typedef
:
14720 case DW_TAG_class_type
:
14721 case DW_TAG_structure_type
:
14722 case DW_TAG_union_type
:
14723 case DW_TAG_enumeration_type
:
14731 /* Add a type definition defined in the scope of the FIP's class. */
14734 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14735 struct dwarf2_cu
*cu
)
14737 struct decl_field fp
;
14738 memset (&fp
, 0, sizeof (fp
));
14740 gdb_assert (type_can_define_types (die
));
14742 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14743 fp
.name
= dwarf2_name (die
, cu
);
14744 fp
.type
= read_type_die (die
, cu
);
14746 /* Save accessibility. */
14747 enum dwarf_access_attribute accessibility
;
14748 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14750 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14752 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14753 switch (accessibility
)
14755 case DW_ACCESS_public
:
14756 /* The assumed value if neither private nor protected. */
14758 case DW_ACCESS_private
:
14761 case DW_ACCESS_protected
:
14762 fp
.is_protected
= 1;
14765 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14768 if (die
->tag
== DW_TAG_typedef
)
14769 fip
->typedef_field_list
.push_back (fp
);
14771 fip
->nested_types_list
.push_back (fp
);
14774 /* A convenience typedef that's used when finding the discriminant
14775 field for a variant part. */
14776 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14779 /* Compute the discriminant range for a given variant. OBSTACK is
14780 where the results will be stored. VARIANT is the variant to
14781 process. IS_UNSIGNED indicates whether the discriminant is signed
14784 static const gdb::array_view
<discriminant_range
>
14785 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14788 std::vector
<discriminant_range
> ranges
;
14790 if (variant
.default_branch
)
14793 if (variant
.discr_list_data
== nullptr)
14795 discriminant_range r
14796 = {variant
.discriminant_value
, variant
.discriminant_value
};
14797 ranges
.push_back (r
);
14801 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14802 variant
.discr_list_data
->size
);
14803 while (!data
.empty ())
14805 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14807 complaint (_("invalid discriminant marker: %d"), data
[0]);
14810 bool is_range
= data
[0] == DW_DSC_range
;
14811 data
= data
.slice (1);
14813 ULONGEST low
, high
;
14814 unsigned int bytes_read
;
14818 complaint (_("DW_AT_discr_list missing low value"));
14822 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14824 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14826 data
= data
.slice (bytes_read
);
14832 complaint (_("DW_AT_discr_list missing high value"));
14836 high
= read_unsigned_leb128 (nullptr, data
.data (),
14839 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14841 data
= data
.slice (bytes_read
);
14846 ranges
.push_back ({ low
, high
});
14850 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14852 std::copy (ranges
.begin (), ranges
.end (), result
);
14853 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14856 static const gdb::array_view
<variant_part
> create_variant_parts
14857 (struct obstack
*obstack
,
14858 const offset_map_type
&offset_map
,
14859 struct field_info
*fi
,
14860 const std::vector
<variant_part_builder
> &variant_parts
);
14862 /* Fill in a "struct variant" for a given variant field. RESULT is
14863 the variant to fill in. OBSTACK is where any needed allocations
14864 will be done. OFFSET_MAP holds the mapping from section offsets to
14865 fields for the type. FI describes the fields of the type we're
14866 processing. FIELD is the variant field we're converting. */
14869 create_one_variant (variant
&result
, struct obstack
*obstack
,
14870 const offset_map_type
&offset_map
,
14871 struct field_info
*fi
, const variant_field
&field
)
14873 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14874 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14875 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14876 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14877 field
.variant_parts
);
14880 /* Fill in a "struct variant_part" for a given variant part. RESULT
14881 is the variant part to fill in. OBSTACK is where any needed
14882 allocations will be done. OFFSET_MAP holds the mapping from
14883 section offsets to fields for the type. FI describes the fields of
14884 the type we're processing. BUILDER is the variant part to be
14888 create_one_variant_part (variant_part
&result
,
14889 struct obstack
*obstack
,
14890 const offset_map_type
&offset_map
,
14891 struct field_info
*fi
,
14892 const variant_part_builder
&builder
)
14894 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14895 if (iter
== offset_map
.end ())
14897 result
.discriminant_index
= -1;
14898 /* Doesn't matter. */
14899 result
.is_unsigned
= false;
14903 result
.discriminant_index
= iter
->second
;
14905 = TYPE_UNSIGNED (fi
->fields
[result
.discriminant_index
].field
.type ());
14908 size_t n
= builder
.variants
.size ();
14909 variant
*output
= new (obstack
) variant
[n
];
14910 for (size_t i
= 0; i
< n
; ++i
)
14911 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14912 builder
.variants
[i
]);
14914 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14917 /* Create a vector of variant parts that can be attached to a type.
14918 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14919 holds the mapping from section offsets to fields for the type. FI
14920 describes the fields of the type we're processing. VARIANT_PARTS
14921 is the vector to convert. */
14923 static const gdb::array_view
<variant_part
>
14924 create_variant_parts (struct obstack
*obstack
,
14925 const offset_map_type
&offset_map
,
14926 struct field_info
*fi
,
14927 const std::vector
<variant_part_builder
> &variant_parts
)
14929 if (variant_parts
.empty ())
14932 size_t n
= variant_parts
.size ();
14933 variant_part
*result
= new (obstack
) variant_part
[n
];
14934 for (size_t i
= 0; i
< n
; ++i
)
14935 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14938 return gdb::array_view
<variant_part
> (result
, n
);
14941 /* Compute the variant part vector for FIP, attaching it to TYPE when
14945 add_variant_property (struct field_info
*fip
, struct type
*type
,
14946 struct dwarf2_cu
*cu
)
14948 /* Map section offsets of fields to their field index. Note the
14949 field index here does not take the number of baseclasses into
14951 offset_map_type offset_map
;
14952 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14953 offset_map
[fip
->fields
[i
].offset
] = i
;
14955 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14956 gdb::array_view
<variant_part
> parts
14957 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14958 fip
->variant_parts
);
14960 struct dynamic_prop prop
;
14961 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14962 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14965 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14968 /* Create the vector of fields, and attach it to the type. */
14971 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14972 struct dwarf2_cu
*cu
)
14974 int nfields
= fip
->nfields ();
14976 /* Record the field count, allocate space for the array of fields,
14977 and create blank accessibility bitfields if necessary. */
14978 type
->set_num_fields (nfields
);
14980 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14982 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14984 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14986 TYPE_FIELD_PRIVATE_BITS (type
) =
14987 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14988 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14990 TYPE_FIELD_PROTECTED_BITS (type
) =
14991 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14992 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14994 TYPE_FIELD_IGNORE_BITS (type
) =
14995 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14996 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14999 /* If the type has baseclasses, allocate and clear a bit vector for
15000 TYPE_FIELD_VIRTUAL_BITS. */
15001 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15003 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15004 unsigned char *pointer
;
15006 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15007 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15008 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15009 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15010 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15013 if (!fip
->variant_parts
.empty ())
15014 add_variant_property (fip
, type
, cu
);
15016 /* Copy the saved-up fields into the field vector. */
15017 for (int i
= 0; i
< nfields
; ++i
)
15019 struct nextfield
&field
15020 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15021 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15023 type
->field (i
) = field
.field
;
15024 switch (field
.accessibility
)
15026 case DW_ACCESS_private
:
15027 if (cu
->language
!= language_ada
)
15028 SET_TYPE_FIELD_PRIVATE (type
, i
);
15031 case DW_ACCESS_protected
:
15032 if (cu
->language
!= language_ada
)
15033 SET_TYPE_FIELD_PROTECTED (type
, i
);
15036 case DW_ACCESS_public
:
15040 /* Unknown accessibility. Complain and treat it as public. */
15042 complaint (_("unsupported accessibility %d"),
15043 field
.accessibility
);
15047 if (i
< fip
->baseclasses
.size ())
15049 switch (field
.virtuality
)
15051 case DW_VIRTUALITY_virtual
:
15052 case DW_VIRTUALITY_pure_virtual
:
15053 if (cu
->language
== language_ada
)
15054 error (_("unexpected virtuality in component of Ada type"));
15055 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15062 /* Return true if this member function is a constructor, false
15066 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15068 const char *fieldname
;
15069 const char *type_name
;
15072 if (die
->parent
== NULL
)
15075 if (die
->parent
->tag
!= DW_TAG_structure_type
15076 && die
->parent
->tag
!= DW_TAG_union_type
15077 && die
->parent
->tag
!= DW_TAG_class_type
)
15080 fieldname
= dwarf2_name (die
, cu
);
15081 type_name
= dwarf2_name (die
->parent
, cu
);
15082 if (fieldname
== NULL
|| type_name
== NULL
)
15085 len
= strlen (fieldname
);
15086 return (strncmp (fieldname
, type_name
, len
) == 0
15087 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15090 /* Check if the given VALUE is a recognized enum
15091 dwarf_defaulted_attribute constant according to DWARF5 spec,
15095 is_valid_DW_AT_defaulted (ULONGEST value
)
15099 case DW_DEFAULTED_no
:
15100 case DW_DEFAULTED_in_class
:
15101 case DW_DEFAULTED_out_of_class
:
15105 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15109 /* Add a member function to the proper fieldlist. */
15112 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15113 struct type
*type
, struct dwarf2_cu
*cu
)
15115 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15116 struct attribute
*attr
;
15118 struct fnfieldlist
*flp
= nullptr;
15119 struct fn_field
*fnp
;
15120 const char *fieldname
;
15121 struct type
*this_type
;
15122 enum dwarf_access_attribute accessibility
;
15124 if (cu
->language
== language_ada
)
15125 error (_("unexpected member function in Ada type"));
15127 /* Get name of member function. */
15128 fieldname
= dwarf2_name (die
, cu
);
15129 if (fieldname
== NULL
)
15132 /* Look up member function name in fieldlist. */
15133 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15135 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15137 flp
= &fip
->fnfieldlists
[i
];
15142 /* Create a new fnfieldlist if necessary. */
15143 if (flp
== nullptr)
15145 fip
->fnfieldlists
.emplace_back ();
15146 flp
= &fip
->fnfieldlists
.back ();
15147 flp
->name
= fieldname
;
15148 i
= fip
->fnfieldlists
.size () - 1;
15151 /* Create a new member function field and add it to the vector of
15153 flp
->fnfields
.emplace_back ();
15154 fnp
= &flp
->fnfields
.back ();
15156 /* Delay processing of the physname until later. */
15157 if (cu
->language
== language_cplus
)
15158 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15162 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15163 fnp
->physname
= physname
? physname
: "";
15166 fnp
->type
= alloc_type (objfile
);
15167 this_type
= read_type_die (die
, cu
);
15168 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15170 int nparams
= this_type
->num_fields ();
15172 /* TYPE is the domain of this method, and THIS_TYPE is the type
15173 of the method itself (TYPE_CODE_METHOD). */
15174 smash_to_method_type (fnp
->type
, type
,
15175 TYPE_TARGET_TYPE (this_type
),
15176 this_type
->fields (),
15177 this_type
->num_fields (),
15178 TYPE_VARARGS (this_type
));
15180 /* Handle static member functions.
15181 Dwarf2 has no clean way to discern C++ static and non-static
15182 member functions. G++ helps GDB by marking the first
15183 parameter for non-static member functions (which is the this
15184 pointer) as artificial. We obtain this information from
15185 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15186 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15187 fnp
->voffset
= VOFFSET_STATIC
;
15190 complaint (_("member function type missing for '%s'"),
15191 dwarf2_full_name (fieldname
, die
, cu
));
15193 /* Get fcontext from DW_AT_containing_type if present. */
15194 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15195 fnp
->fcontext
= die_containing_type (die
, cu
);
15197 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15198 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15200 /* Get accessibility. */
15201 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15202 if (attr
!= nullptr)
15203 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15205 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15206 switch (accessibility
)
15208 case DW_ACCESS_private
:
15209 fnp
->is_private
= 1;
15211 case DW_ACCESS_protected
:
15212 fnp
->is_protected
= 1;
15216 /* Check for artificial methods. */
15217 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15218 if (attr
&& DW_UNSND (attr
) != 0)
15219 fnp
->is_artificial
= 1;
15221 /* Check for defaulted methods. */
15222 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15223 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15224 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15226 /* Check for deleted methods. */
15227 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15228 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15229 fnp
->is_deleted
= 1;
15231 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15233 /* Get index in virtual function table if it is a virtual member
15234 function. For older versions of GCC, this is an offset in the
15235 appropriate virtual table, as specified by DW_AT_containing_type.
15236 For everyone else, it is an expression to be evaluated relative
15237 to the object address. */
15239 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15240 if (attr
!= nullptr)
15242 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15244 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15246 /* Old-style GCC. */
15247 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15249 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15250 || (DW_BLOCK (attr
)->size
> 1
15251 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15252 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15254 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15255 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15256 dwarf2_complex_location_expr_complaint ();
15258 fnp
->voffset
/= cu
->header
.addr_size
;
15262 dwarf2_complex_location_expr_complaint ();
15264 if (!fnp
->fcontext
)
15266 /* If there is no `this' field and no DW_AT_containing_type,
15267 we cannot actually find a base class context for the
15269 if (this_type
->num_fields () == 0
15270 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15272 complaint (_("cannot determine context for virtual member "
15273 "function \"%s\" (offset %s)"),
15274 fieldname
, sect_offset_str (die
->sect_off
));
15279 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15283 else if (attr
->form_is_section_offset ())
15285 dwarf2_complex_location_expr_complaint ();
15289 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15295 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15296 if (attr
&& DW_UNSND (attr
))
15298 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15299 complaint (_("Member function \"%s\" (offset %s) is virtual "
15300 "but the vtable offset is not specified"),
15301 fieldname
, sect_offset_str (die
->sect_off
));
15302 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15303 TYPE_CPLUS_DYNAMIC (type
) = 1;
15308 /* Create the vector of member function fields, and attach it to the type. */
15311 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15312 struct dwarf2_cu
*cu
)
15314 if (cu
->language
== language_ada
)
15315 error (_("unexpected member functions in Ada type"));
15317 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15318 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15320 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15322 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15324 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15325 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15327 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15328 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15329 fn_flp
->fn_fields
= (struct fn_field
*)
15330 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15332 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15333 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15336 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15339 /* Returns non-zero if NAME is the name of a vtable member in CU's
15340 language, zero otherwise. */
15342 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15344 static const char vptr
[] = "_vptr";
15346 /* Look for the C++ form of the vtable. */
15347 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15353 /* GCC outputs unnamed structures that are really pointers to member
15354 functions, with the ABI-specified layout. If TYPE describes
15355 such a structure, smash it into a member function type.
15357 GCC shouldn't do this; it should just output pointer to member DIEs.
15358 This is GCC PR debug/28767. */
15361 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15363 struct type
*pfn_type
, *self_type
, *new_type
;
15365 /* Check for a structure with no name and two children. */
15366 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15369 /* Check for __pfn and __delta members. */
15370 if (TYPE_FIELD_NAME (type
, 0) == NULL
15371 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15372 || TYPE_FIELD_NAME (type
, 1) == NULL
15373 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15376 /* Find the type of the method. */
15377 pfn_type
= type
->field (0).type ();
15378 if (pfn_type
== NULL
15379 || pfn_type
->code () != TYPE_CODE_PTR
15380 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15383 /* Look for the "this" argument. */
15384 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15385 if (pfn_type
->num_fields () == 0
15386 /* || pfn_type->field (0).type () == NULL */
15387 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15390 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15391 new_type
= alloc_type (objfile
);
15392 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15393 pfn_type
->fields (), pfn_type
->num_fields (),
15394 TYPE_VARARGS (pfn_type
));
15395 smash_to_methodptr_type (type
, new_type
);
15398 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15399 appropriate error checking and issuing complaints if there is a
15403 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15405 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15407 if (attr
== nullptr)
15410 if (!attr
->form_is_constant ())
15412 complaint (_("DW_AT_alignment must have constant form"
15413 " - DIE at %s [in module %s]"),
15414 sect_offset_str (die
->sect_off
),
15415 objfile_name (cu
->per_objfile
->objfile
));
15420 if (attr
->form
== DW_FORM_sdata
)
15422 LONGEST val
= DW_SND (attr
);
15425 complaint (_("DW_AT_alignment value must not be negative"
15426 " - DIE at %s [in module %s]"),
15427 sect_offset_str (die
->sect_off
),
15428 objfile_name (cu
->per_objfile
->objfile
));
15434 align
= DW_UNSND (attr
);
15438 complaint (_("DW_AT_alignment value must not be zero"
15439 " - DIE at %s [in module %s]"),
15440 sect_offset_str (die
->sect_off
),
15441 objfile_name (cu
->per_objfile
->objfile
));
15444 if ((align
& (align
- 1)) != 0)
15446 complaint (_("DW_AT_alignment value must be a power of 2"
15447 " - DIE at %s [in module %s]"),
15448 sect_offset_str (die
->sect_off
),
15449 objfile_name (cu
->per_objfile
->objfile
));
15456 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15457 the alignment for TYPE. */
15460 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15463 if (!set_type_align (type
, get_alignment (cu
, die
)))
15464 complaint (_("DW_AT_alignment value too large"
15465 " - DIE at %s [in module %s]"),
15466 sect_offset_str (die
->sect_off
),
15467 objfile_name (cu
->per_objfile
->objfile
));
15470 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15471 constant for a type, according to DWARF5 spec, Table 5.5. */
15474 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15479 case DW_CC_pass_by_reference
:
15480 case DW_CC_pass_by_value
:
15484 complaint (_("unrecognized DW_AT_calling_convention value "
15485 "(%s) for a type"), pulongest (value
));
15490 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15491 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15492 also according to GNU-specific values (see include/dwarf2.h). */
15495 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15500 case DW_CC_program
:
15504 case DW_CC_GNU_renesas_sh
:
15505 case DW_CC_GNU_borland_fastcall_i386
:
15506 case DW_CC_GDB_IBM_OpenCL
:
15510 complaint (_("unrecognized DW_AT_calling_convention value "
15511 "(%s) for a subroutine"), pulongest (value
));
15516 /* Called when we find the DIE that starts a structure or union scope
15517 (definition) to create a type for the structure or union. Fill in
15518 the type's name and general properties; the members will not be
15519 processed until process_structure_scope. A symbol table entry for
15520 the type will also not be done until process_structure_scope (assuming
15521 the type has a name).
15523 NOTE: we need to call these functions regardless of whether or not the
15524 DIE has a DW_AT_name attribute, since it might be an anonymous
15525 structure or union. This gets the type entered into our set of
15526 user defined types. */
15528 static struct type
*
15529 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15531 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15533 struct attribute
*attr
;
15536 /* If the definition of this type lives in .debug_types, read that type.
15537 Don't follow DW_AT_specification though, that will take us back up
15538 the chain and we want to go down. */
15539 attr
= die
->attr (DW_AT_signature
);
15540 if (attr
!= nullptr)
15542 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15544 /* The type's CU may not be the same as CU.
15545 Ensure TYPE is recorded with CU in die_type_hash. */
15546 return set_die_type (die
, type
, cu
);
15549 type
= alloc_type (objfile
);
15550 INIT_CPLUS_SPECIFIC (type
);
15552 name
= dwarf2_name (die
, cu
);
15555 if (cu
->language
== language_cplus
15556 || cu
->language
== language_d
15557 || cu
->language
== language_rust
)
15559 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15561 /* dwarf2_full_name might have already finished building the DIE's
15562 type. If so, there is no need to continue. */
15563 if (get_die_type (die
, cu
) != NULL
)
15564 return get_die_type (die
, cu
);
15566 type
->set_name (full_name
);
15570 /* The name is already allocated along with this objfile, so
15571 we don't need to duplicate it for the type. */
15572 type
->set_name (name
);
15576 if (die
->tag
== DW_TAG_structure_type
)
15578 type
->set_code (TYPE_CODE_STRUCT
);
15580 else if (die
->tag
== DW_TAG_union_type
)
15582 type
->set_code (TYPE_CODE_UNION
);
15586 type
->set_code (TYPE_CODE_STRUCT
);
15589 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15590 TYPE_DECLARED_CLASS (type
) = 1;
15592 /* Store the calling convention in the type if it's available in
15593 the die. Otherwise the calling convention remains set to
15594 the default value DW_CC_normal. */
15595 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15596 if (attr
!= nullptr
15597 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15599 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15600 TYPE_CPLUS_CALLING_CONVENTION (type
)
15601 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15604 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15605 if (attr
!= nullptr)
15607 if (attr
->form_is_constant ())
15608 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15611 struct dynamic_prop prop
;
15612 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15613 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15614 TYPE_LENGTH (type
) = 0;
15619 TYPE_LENGTH (type
) = 0;
15622 maybe_set_alignment (cu
, die
, type
);
15624 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15626 /* ICC<14 does not output the required DW_AT_declaration on
15627 incomplete types, but gives them a size of zero. */
15628 TYPE_STUB (type
) = 1;
15631 TYPE_STUB_SUPPORTED (type
) = 1;
15633 if (die_is_declaration (die
, cu
))
15634 TYPE_STUB (type
) = 1;
15635 else if (attr
== NULL
&& die
->child
== NULL
15636 && producer_is_realview (cu
->producer
))
15637 /* RealView does not output the required DW_AT_declaration
15638 on incomplete types. */
15639 TYPE_STUB (type
) = 1;
15641 /* We need to add the type field to the die immediately so we don't
15642 infinitely recurse when dealing with pointers to the structure
15643 type within the structure itself. */
15644 set_die_type (die
, type
, cu
);
15646 /* set_die_type should be already done. */
15647 set_descriptive_type (type
, die
, cu
);
15652 static void handle_struct_member_die
15653 (struct die_info
*child_die
,
15655 struct field_info
*fi
,
15656 std::vector
<struct symbol
*> *template_args
,
15657 struct dwarf2_cu
*cu
);
15659 /* A helper for handle_struct_member_die that handles
15660 DW_TAG_variant_part. */
15663 handle_variant_part (struct die_info
*die
, struct type
*type
,
15664 struct field_info
*fi
,
15665 std::vector
<struct symbol
*> *template_args
,
15666 struct dwarf2_cu
*cu
)
15668 variant_part_builder
*new_part
;
15669 if (fi
->current_variant_part
== nullptr)
15671 fi
->variant_parts
.emplace_back ();
15672 new_part
= &fi
->variant_parts
.back ();
15674 else if (!fi
->current_variant_part
->processing_variant
)
15676 complaint (_("nested DW_TAG_variant_part seen "
15677 "- DIE at %s [in module %s]"),
15678 sect_offset_str (die
->sect_off
),
15679 objfile_name (cu
->per_objfile
->objfile
));
15684 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15685 current
.variant_parts
.emplace_back ();
15686 new_part
= ¤t
.variant_parts
.back ();
15689 /* When we recurse, we want callees to add to this new variant
15691 scoped_restore save_current_variant_part
15692 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15694 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15697 /* It's a univariant form, an extension we support. */
15699 else if (discr
->form_is_ref ())
15701 struct dwarf2_cu
*target_cu
= cu
;
15702 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15704 new_part
->discriminant_offset
= target_die
->sect_off
;
15708 complaint (_("DW_AT_discr does not have DIE reference form"
15709 " - DIE at %s [in module %s]"),
15710 sect_offset_str (die
->sect_off
),
15711 objfile_name (cu
->per_objfile
->objfile
));
15714 for (die_info
*child_die
= die
->child
;
15716 child_die
= child_die
->sibling
)
15717 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15720 /* A helper for handle_struct_member_die that handles
15724 handle_variant (struct die_info
*die
, struct type
*type
,
15725 struct field_info
*fi
,
15726 std::vector
<struct symbol
*> *template_args
,
15727 struct dwarf2_cu
*cu
)
15729 if (fi
->current_variant_part
== nullptr)
15731 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15732 "- DIE at %s [in module %s]"),
15733 sect_offset_str (die
->sect_off
),
15734 objfile_name (cu
->per_objfile
->objfile
));
15737 if (fi
->current_variant_part
->processing_variant
)
15739 complaint (_("nested DW_TAG_variant seen "
15740 "- DIE at %s [in module %s]"),
15741 sect_offset_str (die
->sect_off
),
15742 objfile_name (cu
->per_objfile
->objfile
));
15746 scoped_restore save_processing_variant
15747 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15750 fi
->current_variant_part
->variants
.emplace_back ();
15751 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15752 variant
.first_field
= fi
->fields
.size ();
15754 /* In a variant we want to get the discriminant and also add a
15755 field for our sole member child. */
15756 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15757 if (discr
== nullptr)
15759 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15760 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15761 variant
.default_branch
= true;
15763 variant
.discr_list_data
= DW_BLOCK (discr
);
15766 variant
.discriminant_value
= DW_UNSND (discr
);
15768 for (die_info
*variant_child
= die
->child
;
15769 variant_child
!= NULL
;
15770 variant_child
= variant_child
->sibling
)
15771 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15773 variant
.last_field
= fi
->fields
.size ();
15776 /* A helper for process_structure_scope that handles a single member
15780 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15781 struct field_info
*fi
,
15782 std::vector
<struct symbol
*> *template_args
,
15783 struct dwarf2_cu
*cu
)
15785 if (child_die
->tag
== DW_TAG_member
15786 || child_die
->tag
== DW_TAG_variable
)
15788 /* NOTE: carlton/2002-11-05: A C++ static data member
15789 should be a DW_TAG_member that is a declaration, but
15790 all versions of G++ as of this writing (so through at
15791 least 3.2.1) incorrectly generate DW_TAG_variable
15792 tags for them instead. */
15793 dwarf2_add_field (fi
, child_die
, cu
);
15795 else if (child_die
->tag
== DW_TAG_subprogram
)
15797 /* Rust doesn't have member functions in the C++ sense.
15798 However, it does emit ordinary functions as children
15799 of a struct DIE. */
15800 if (cu
->language
== language_rust
)
15801 read_func_scope (child_die
, cu
);
15804 /* C++ member function. */
15805 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15808 else if (child_die
->tag
== DW_TAG_inheritance
)
15810 /* C++ base class field. */
15811 dwarf2_add_field (fi
, child_die
, cu
);
15813 else if (type_can_define_types (child_die
))
15814 dwarf2_add_type_defn (fi
, child_die
, cu
);
15815 else if (child_die
->tag
== DW_TAG_template_type_param
15816 || child_die
->tag
== DW_TAG_template_value_param
)
15818 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15821 template_args
->push_back (arg
);
15823 else if (child_die
->tag
== DW_TAG_variant_part
)
15824 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15825 else if (child_die
->tag
== DW_TAG_variant
)
15826 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15829 /* Finish creating a structure or union type, including filling in
15830 its members and creating a symbol for it. */
15833 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15835 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15836 struct die_info
*child_die
;
15839 type
= get_die_type (die
, cu
);
15841 type
= read_structure_type (die
, cu
);
15843 bool has_template_parameters
= false;
15844 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15846 struct field_info fi
;
15847 std::vector
<struct symbol
*> template_args
;
15849 child_die
= die
->child
;
15851 while (child_die
&& child_die
->tag
)
15853 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15854 child_die
= child_die
->sibling
;
15857 /* Attach template arguments to type. */
15858 if (!template_args
.empty ())
15860 has_template_parameters
= true;
15861 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15862 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15863 TYPE_TEMPLATE_ARGUMENTS (type
)
15864 = XOBNEWVEC (&objfile
->objfile_obstack
,
15866 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15867 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15868 template_args
.data (),
15869 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15870 * sizeof (struct symbol
*)));
15873 /* Attach fields and member functions to the type. */
15874 if (fi
.nfields () > 0)
15875 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15876 if (!fi
.fnfieldlists
.empty ())
15878 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15880 /* Get the type which refers to the base class (possibly this
15881 class itself) which contains the vtable pointer for the current
15882 class from the DW_AT_containing_type attribute. This use of
15883 DW_AT_containing_type is a GNU extension. */
15885 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15887 struct type
*t
= die_containing_type (die
, cu
);
15889 set_type_vptr_basetype (type
, t
);
15894 /* Our own class provides vtbl ptr. */
15895 for (i
= t
->num_fields () - 1;
15896 i
>= TYPE_N_BASECLASSES (t
);
15899 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15901 if (is_vtable_name (fieldname
, cu
))
15903 set_type_vptr_fieldno (type
, i
);
15908 /* Complain if virtual function table field not found. */
15909 if (i
< TYPE_N_BASECLASSES (t
))
15910 complaint (_("virtual function table pointer "
15911 "not found when defining class '%s'"),
15912 type
->name () ? type
->name () : "");
15916 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15919 else if (cu
->producer
15920 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15922 /* The IBM XLC compiler does not provide direct indication
15923 of the containing type, but the vtable pointer is
15924 always named __vfp. */
15928 for (i
= type
->num_fields () - 1;
15929 i
>= TYPE_N_BASECLASSES (type
);
15932 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15934 set_type_vptr_fieldno (type
, i
);
15935 set_type_vptr_basetype (type
, type
);
15942 /* Copy fi.typedef_field_list linked list elements content into the
15943 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15944 if (!fi
.typedef_field_list
.empty ())
15946 int count
= fi
.typedef_field_list
.size ();
15948 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15949 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15950 = ((struct decl_field
*)
15952 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15953 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15955 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15956 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15959 /* Copy fi.nested_types_list linked list elements content into the
15960 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15961 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15963 int count
= fi
.nested_types_list
.size ();
15965 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15966 TYPE_NESTED_TYPES_ARRAY (type
)
15967 = ((struct decl_field
*)
15968 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15969 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15971 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15972 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15976 quirk_gcc_member_function_pointer (type
, objfile
);
15977 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15978 cu
->rust_unions
.push_back (type
);
15980 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15981 snapshots) has been known to create a die giving a declaration
15982 for a class that has, as a child, a die giving a definition for a
15983 nested class. So we have to process our children even if the
15984 current die is a declaration. Normally, of course, a declaration
15985 won't have any children at all. */
15987 child_die
= die
->child
;
15989 while (child_die
!= NULL
&& child_die
->tag
)
15991 if (child_die
->tag
== DW_TAG_member
15992 || child_die
->tag
== DW_TAG_variable
15993 || child_die
->tag
== DW_TAG_inheritance
15994 || child_die
->tag
== DW_TAG_template_value_param
15995 || child_die
->tag
== DW_TAG_template_type_param
)
16000 process_die (child_die
, cu
);
16002 child_die
= child_die
->sibling
;
16005 /* Do not consider external references. According to the DWARF standard,
16006 these DIEs are identified by the fact that they have no byte_size
16007 attribute, and a declaration attribute. */
16008 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16009 || !die_is_declaration (die
, cu
)
16010 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16012 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16014 if (has_template_parameters
)
16016 struct symtab
*symtab
;
16017 if (sym
!= nullptr)
16018 symtab
= symbol_symtab (sym
);
16019 else if (cu
->line_header
!= nullptr)
16021 /* Any related symtab will do. */
16023 = cu
->line_header
->file_names ()[0].symtab
;
16028 complaint (_("could not find suitable "
16029 "symtab for template parameter"
16030 " - DIE at %s [in module %s]"),
16031 sect_offset_str (die
->sect_off
),
16032 objfile_name (objfile
));
16035 if (symtab
!= nullptr)
16037 /* Make sure that the symtab is set on the new symbols.
16038 Even though they don't appear in this symtab directly,
16039 other parts of gdb assume that symbols do, and this is
16040 reasonably true. */
16041 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16042 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16048 /* Assuming DIE is an enumeration type, and TYPE is its associated
16049 type, update TYPE using some information only available in DIE's
16050 children. In particular, the fields are computed. */
16053 update_enumeration_type_from_children (struct die_info
*die
,
16055 struct dwarf2_cu
*cu
)
16057 struct die_info
*child_die
;
16058 int unsigned_enum
= 1;
16061 auto_obstack obstack
;
16062 std::vector
<struct field
> fields
;
16064 for (child_die
= die
->child
;
16065 child_die
!= NULL
&& child_die
->tag
;
16066 child_die
= child_die
->sibling
)
16068 struct attribute
*attr
;
16070 const gdb_byte
*bytes
;
16071 struct dwarf2_locexpr_baton
*baton
;
16074 if (child_die
->tag
!= DW_TAG_enumerator
)
16077 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16081 name
= dwarf2_name (child_die
, cu
);
16083 name
= "<anonymous enumerator>";
16085 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16086 &value
, &bytes
, &baton
);
16094 if (count_one_bits_ll (value
) >= 2)
16098 fields
.emplace_back ();
16099 struct field
&field
= fields
.back ();
16100 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16101 SET_FIELD_ENUMVAL (field
, value
);
16104 if (!fields
.empty ())
16106 type
->set_num_fields (fields
.size ());
16109 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16110 memcpy (type
->fields (), fields
.data (),
16111 sizeof (struct field
) * fields
.size ());
16115 TYPE_UNSIGNED (type
) = 1;
16117 TYPE_FLAG_ENUM (type
) = 1;
16120 /* Given a DW_AT_enumeration_type die, set its type. We do not
16121 complete the type's fields yet, or create any symbols. */
16123 static struct type
*
16124 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16126 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16128 struct attribute
*attr
;
16131 /* If the definition of this type lives in .debug_types, read that type.
16132 Don't follow DW_AT_specification though, that will take us back up
16133 the chain and we want to go down. */
16134 attr
= die
->attr (DW_AT_signature
);
16135 if (attr
!= nullptr)
16137 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16139 /* The type's CU may not be the same as CU.
16140 Ensure TYPE is recorded with CU in die_type_hash. */
16141 return set_die_type (die
, type
, cu
);
16144 type
= alloc_type (objfile
);
16146 type
->set_code (TYPE_CODE_ENUM
);
16147 name
= dwarf2_full_name (NULL
, die
, cu
);
16149 type
->set_name (name
);
16151 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16154 struct type
*underlying_type
= die_type (die
, cu
);
16156 TYPE_TARGET_TYPE (type
) = underlying_type
;
16159 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16160 if (attr
!= nullptr)
16162 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16166 TYPE_LENGTH (type
) = 0;
16169 maybe_set_alignment (cu
, die
, type
);
16171 /* The enumeration DIE can be incomplete. In Ada, any type can be
16172 declared as private in the package spec, and then defined only
16173 inside the package body. Such types are known as Taft Amendment
16174 Types. When another package uses such a type, an incomplete DIE
16175 may be generated by the compiler. */
16176 if (die_is_declaration (die
, cu
))
16177 TYPE_STUB (type
) = 1;
16179 /* If this type has an underlying type that is not a stub, then we
16180 may use its attributes. We always use the "unsigned" attribute
16181 in this situation, because ordinarily we guess whether the type
16182 is unsigned -- but the guess can be wrong and the underlying type
16183 can tell us the reality. However, we defer to a local size
16184 attribute if one exists, because this lets the compiler override
16185 the underlying type if needed. */
16186 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16188 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16189 underlying_type
= check_typedef (underlying_type
);
16190 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16191 if (TYPE_LENGTH (type
) == 0)
16192 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16193 if (TYPE_RAW_ALIGN (type
) == 0
16194 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16195 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16198 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16200 set_die_type (die
, type
, cu
);
16202 /* Finish the creation of this type by using the enum's children.
16203 Note that, as usual, this must come after set_die_type to avoid
16204 infinite recursion when trying to compute the names of the
16206 update_enumeration_type_from_children (die
, type
, cu
);
16211 /* Given a pointer to a die which begins an enumeration, process all
16212 the dies that define the members of the enumeration, and create the
16213 symbol for the enumeration type.
16215 NOTE: We reverse the order of the element list. */
16218 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16220 struct type
*this_type
;
16222 this_type
= get_die_type (die
, cu
);
16223 if (this_type
== NULL
)
16224 this_type
= read_enumeration_type (die
, cu
);
16226 if (die
->child
!= NULL
)
16228 struct die_info
*child_die
;
16231 child_die
= die
->child
;
16232 while (child_die
&& child_die
->tag
)
16234 if (child_die
->tag
!= DW_TAG_enumerator
)
16236 process_die (child_die
, cu
);
16240 name
= dwarf2_name (child_die
, cu
);
16242 new_symbol (child_die
, this_type
, cu
);
16245 child_die
= child_die
->sibling
;
16249 /* If we are reading an enum from a .debug_types unit, and the enum
16250 is a declaration, and the enum is not the signatured type in the
16251 unit, then we do not want to add a symbol for it. Adding a
16252 symbol would in some cases obscure the true definition of the
16253 enum, giving users an incomplete type when the definition is
16254 actually available. Note that we do not want to do this for all
16255 enums which are just declarations, because C++0x allows forward
16256 enum declarations. */
16257 if (cu
->per_cu
->is_debug_types
16258 && die_is_declaration (die
, cu
))
16260 struct signatured_type
*sig_type
;
16262 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16263 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16264 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16268 new_symbol (die
, this_type
, cu
);
16271 /* Extract all information from a DW_TAG_array_type DIE and put it in
16272 the DIE's type field. For now, this only handles one dimensional
16275 static struct type
*
16276 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16278 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16279 struct die_info
*child_die
;
16281 struct type
*element_type
, *range_type
, *index_type
;
16282 struct attribute
*attr
;
16284 struct dynamic_prop
*byte_stride_prop
= NULL
;
16285 unsigned int bit_stride
= 0;
16287 element_type
= die_type (die
, cu
);
16289 /* The die_type call above may have already set the type for this DIE. */
16290 type
= get_die_type (die
, cu
);
16294 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16298 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16301 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16302 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16306 complaint (_("unable to read array DW_AT_byte_stride "
16307 " - DIE at %s [in module %s]"),
16308 sect_offset_str (die
->sect_off
),
16309 objfile_name (cu
->per_objfile
->objfile
));
16310 /* Ignore this attribute. We will likely not be able to print
16311 arrays of this type correctly, but there is little we can do
16312 to help if we cannot read the attribute's value. */
16313 byte_stride_prop
= NULL
;
16317 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16319 bit_stride
= DW_UNSND (attr
);
16321 /* Irix 6.2 native cc creates array types without children for
16322 arrays with unspecified length. */
16323 if (die
->child
== NULL
)
16325 index_type
= objfile_type (objfile
)->builtin_int
;
16326 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16327 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16328 byte_stride_prop
, bit_stride
);
16329 return set_die_type (die
, type
, cu
);
16332 std::vector
<struct type
*> range_types
;
16333 child_die
= die
->child
;
16334 while (child_die
&& child_die
->tag
)
16336 if (child_die
->tag
== DW_TAG_subrange_type
)
16338 struct type
*child_type
= read_type_die (child_die
, cu
);
16340 if (child_type
!= NULL
)
16342 /* The range type was succesfully read. Save it for the
16343 array type creation. */
16344 range_types
.push_back (child_type
);
16347 child_die
= child_die
->sibling
;
16350 /* Dwarf2 dimensions are output from left to right, create the
16351 necessary array types in backwards order. */
16353 type
= element_type
;
16355 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16359 while (i
< range_types
.size ())
16360 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16361 byte_stride_prop
, bit_stride
);
16365 size_t ndim
= range_types
.size ();
16367 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16368 byte_stride_prop
, bit_stride
);
16371 /* Understand Dwarf2 support for vector types (like they occur on
16372 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16373 array type. This is not part of the Dwarf2/3 standard yet, but a
16374 custom vendor extension. The main difference between a regular
16375 array and the vector variant is that vectors are passed by value
16377 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16378 if (attr
!= nullptr)
16379 make_vector_type (type
);
16381 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16382 implementation may choose to implement triple vectors using this
16384 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16385 if (attr
!= nullptr)
16387 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16388 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16390 complaint (_("DW_AT_byte_size for array type smaller "
16391 "than the total size of elements"));
16394 name
= dwarf2_name (die
, cu
);
16396 type
->set_name (name
);
16398 maybe_set_alignment (cu
, die
, type
);
16400 /* Install the type in the die. */
16401 set_die_type (die
, type
, cu
);
16403 /* set_die_type should be already done. */
16404 set_descriptive_type (type
, die
, cu
);
16409 static enum dwarf_array_dim_ordering
16410 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16412 struct attribute
*attr
;
16414 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16416 if (attr
!= nullptr)
16417 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16419 /* GNU F77 is a special case, as at 08/2004 array type info is the
16420 opposite order to the dwarf2 specification, but data is still
16421 laid out as per normal fortran.
16423 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16424 version checking. */
16426 if (cu
->language
== language_fortran
16427 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16429 return DW_ORD_row_major
;
16432 switch (cu
->language_defn
->la_array_ordering
)
16434 case array_column_major
:
16435 return DW_ORD_col_major
;
16436 case array_row_major
:
16438 return DW_ORD_row_major
;
16442 /* Extract all information from a DW_TAG_set_type DIE and put it in
16443 the DIE's type field. */
16445 static struct type
*
16446 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16448 struct type
*domain_type
, *set_type
;
16449 struct attribute
*attr
;
16451 domain_type
= die_type (die
, cu
);
16453 /* The die_type call above may have already set the type for this DIE. */
16454 set_type
= get_die_type (die
, cu
);
16458 set_type
= create_set_type (NULL
, domain_type
);
16460 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16461 if (attr
!= nullptr)
16462 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16464 maybe_set_alignment (cu
, die
, set_type
);
16466 return set_die_type (die
, set_type
, cu
);
16469 /* A helper for read_common_block that creates a locexpr baton.
16470 SYM is the symbol which we are marking as computed.
16471 COMMON_DIE is the DIE for the common block.
16472 COMMON_LOC is the location expression attribute for the common
16474 MEMBER_LOC is the location expression attribute for the particular
16475 member of the common block that we are processing.
16476 CU is the CU from which the above come. */
16479 mark_common_block_symbol_computed (struct symbol
*sym
,
16480 struct die_info
*common_die
,
16481 struct attribute
*common_loc
,
16482 struct attribute
*member_loc
,
16483 struct dwarf2_cu
*cu
)
16485 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16486 struct objfile
*objfile
= per_objfile
->objfile
;
16487 struct dwarf2_locexpr_baton
*baton
;
16489 unsigned int cu_off
;
16490 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16491 LONGEST offset
= 0;
16493 gdb_assert (common_loc
&& member_loc
);
16494 gdb_assert (common_loc
->form_is_block ());
16495 gdb_assert (member_loc
->form_is_block ()
16496 || member_loc
->form_is_constant ());
16498 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16499 baton
->per_objfile
= per_objfile
;
16500 baton
->per_cu
= cu
->per_cu
;
16501 gdb_assert (baton
->per_cu
);
16503 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16505 if (member_loc
->form_is_constant ())
16507 offset
= member_loc
->constant_value (0);
16508 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16511 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16513 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16516 *ptr
++ = DW_OP_call4
;
16517 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16518 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16521 if (member_loc
->form_is_constant ())
16523 *ptr
++ = DW_OP_addr
;
16524 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16525 ptr
+= cu
->header
.addr_size
;
16529 /* We have to copy the data here, because DW_OP_call4 will only
16530 use a DW_AT_location attribute. */
16531 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16532 ptr
+= DW_BLOCK (member_loc
)->size
;
16535 *ptr
++ = DW_OP_plus
;
16536 gdb_assert (ptr
- baton
->data
== baton
->size
);
16538 SYMBOL_LOCATION_BATON (sym
) = baton
;
16539 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16542 /* Create appropriate locally-scoped variables for all the
16543 DW_TAG_common_block entries. Also create a struct common_block
16544 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16545 is used to separate the common blocks name namespace from regular
16549 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16551 struct attribute
*attr
;
16553 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16554 if (attr
!= nullptr)
16556 /* Support the .debug_loc offsets. */
16557 if (attr
->form_is_block ())
16561 else if (attr
->form_is_section_offset ())
16563 dwarf2_complex_location_expr_complaint ();
16568 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16569 "common block member");
16574 if (die
->child
!= NULL
)
16576 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16577 struct die_info
*child_die
;
16578 size_t n_entries
= 0, size
;
16579 struct common_block
*common_block
;
16580 struct symbol
*sym
;
16582 for (child_die
= die
->child
;
16583 child_die
&& child_die
->tag
;
16584 child_die
= child_die
->sibling
)
16587 size
= (sizeof (struct common_block
)
16588 + (n_entries
- 1) * sizeof (struct symbol
*));
16590 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16592 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16593 common_block
->n_entries
= 0;
16595 for (child_die
= die
->child
;
16596 child_die
&& child_die
->tag
;
16597 child_die
= child_die
->sibling
)
16599 /* Create the symbol in the DW_TAG_common_block block in the current
16601 sym
= new_symbol (child_die
, NULL
, cu
);
16604 struct attribute
*member_loc
;
16606 common_block
->contents
[common_block
->n_entries
++] = sym
;
16608 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16612 /* GDB has handled this for a long time, but it is
16613 not specified by DWARF. It seems to have been
16614 emitted by gfortran at least as recently as:
16615 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16616 complaint (_("Variable in common block has "
16617 "DW_AT_data_member_location "
16618 "- DIE at %s [in module %s]"),
16619 sect_offset_str (child_die
->sect_off
),
16620 objfile_name (objfile
));
16622 if (member_loc
->form_is_section_offset ())
16623 dwarf2_complex_location_expr_complaint ();
16624 else if (member_loc
->form_is_constant ()
16625 || member_loc
->form_is_block ())
16627 if (attr
!= nullptr)
16628 mark_common_block_symbol_computed (sym
, die
, attr
,
16632 dwarf2_complex_location_expr_complaint ();
16637 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16638 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16642 /* Create a type for a C++ namespace. */
16644 static struct type
*
16645 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16647 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16648 const char *previous_prefix
, *name
;
16652 /* For extensions, reuse the type of the original namespace. */
16653 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16655 struct die_info
*ext_die
;
16656 struct dwarf2_cu
*ext_cu
= cu
;
16658 ext_die
= dwarf2_extension (die
, &ext_cu
);
16659 type
= read_type_die (ext_die
, ext_cu
);
16661 /* EXT_CU may not be the same as CU.
16662 Ensure TYPE is recorded with CU in die_type_hash. */
16663 return set_die_type (die
, type
, cu
);
16666 name
= namespace_name (die
, &is_anonymous
, cu
);
16668 /* Now build the name of the current namespace. */
16670 previous_prefix
= determine_prefix (die
, cu
);
16671 if (previous_prefix
[0] != '\0')
16672 name
= typename_concat (&objfile
->objfile_obstack
,
16673 previous_prefix
, name
, 0, cu
);
16675 /* Create the type. */
16676 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16678 return set_die_type (die
, type
, cu
);
16681 /* Read a namespace scope. */
16684 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16686 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16689 /* Add a symbol associated to this if we haven't seen the namespace
16690 before. Also, add a using directive if it's an anonymous
16693 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16697 type
= read_type_die (die
, cu
);
16698 new_symbol (die
, type
, cu
);
16700 namespace_name (die
, &is_anonymous
, cu
);
16703 const char *previous_prefix
= determine_prefix (die
, cu
);
16705 std::vector
<const char *> excludes
;
16706 add_using_directive (using_directives (cu
),
16707 previous_prefix
, type
->name (), NULL
,
16708 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16712 if (die
->child
!= NULL
)
16714 struct die_info
*child_die
= die
->child
;
16716 while (child_die
&& child_die
->tag
)
16718 process_die (child_die
, cu
);
16719 child_die
= child_die
->sibling
;
16724 /* Read a Fortran module as type. This DIE can be only a declaration used for
16725 imported module. Still we need that type as local Fortran "use ... only"
16726 declaration imports depend on the created type in determine_prefix. */
16728 static struct type
*
16729 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16731 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16732 const char *module_name
;
16735 module_name
= dwarf2_name (die
, cu
);
16736 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16738 return set_die_type (die
, type
, cu
);
16741 /* Read a Fortran module. */
16744 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16746 struct die_info
*child_die
= die
->child
;
16749 type
= read_type_die (die
, cu
);
16750 new_symbol (die
, type
, cu
);
16752 while (child_die
&& child_die
->tag
)
16754 process_die (child_die
, cu
);
16755 child_die
= child_die
->sibling
;
16759 /* Return the name of the namespace represented by DIE. Set
16760 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16763 static const char *
16764 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16766 struct die_info
*current_die
;
16767 const char *name
= NULL
;
16769 /* Loop through the extensions until we find a name. */
16771 for (current_die
= die
;
16772 current_die
!= NULL
;
16773 current_die
= dwarf2_extension (die
, &cu
))
16775 /* We don't use dwarf2_name here so that we can detect the absence
16776 of a name -> anonymous namespace. */
16777 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16783 /* Is it an anonymous namespace? */
16785 *is_anonymous
= (name
== NULL
);
16787 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16792 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16793 the user defined type vector. */
16795 static struct type
*
16796 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16798 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16799 struct comp_unit_head
*cu_header
= &cu
->header
;
16801 struct attribute
*attr_byte_size
;
16802 struct attribute
*attr_address_class
;
16803 int byte_size
, addr_class
;
16804 struct type
*target_type
;
16806 target_type
= die_type (die
, cu
);
16808 /* The die_type call above may have already set the type for this DIE. */
16809 type
= get_die_type (die
, cu
);
16813 type
= lookup_pointer_type (target_type
);
16815 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16816 if (attr_byte_size
)
16817 byte_size
= DW_UNSND (attr_byte_size
);
16819 byte_size
= cu_header
->addr_size
;
16821 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16822 if (attr_address_class
)
16823 addr_class
= DW_UNSND (attr_address_class
);
16825 addr_class
= DW_ADDR_none
;
16827 ULONGEST alignment
= get_alignment (cu
, die
);
16829 /* If the pointer size, alignment, or address class is different
16830 than the default, create a type variant marked as such and set
16831 the length accordingly. */
16832 if (TYPE_LENGTH (type
) != byte_size
16833 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16834 && alignment
!= TYPE_RAW_ALIGN (type
))
16835 || addr_class
!= DW_ADDR_none
)
16837 if (gdbarch_address_class_type_flags_p (gdbarch
))
16841 type_flags
= gdbarch_address_class_type_flags
16842 (gdbarch
, byte_size
, addr_class
);
16843 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16845 type
= make_type_with_address_space (type
, type_flags
);
16847 else if (TYPE_LENGTH (type
) != byte_size
)
16849 complaint (_("invalid pointer size %d"), byte_size
);
16851 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16853 complaint (_("Invalid DW_AT_alignment"
16854 " - DIE at %s [in module %s]"),
16855 sect_offset_str (die
->sect_off
),
16856 objfile_name (cu
->per_objfile
->objfile
));
16860 /* Should we also complain about unhandled address classes? */
16864 TYPE_LENGTH (type
) = byte_size
;
16865 set_type_align (type
, alignment
);
16866 return set_die_type (die
, type
, cu
);
16869 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16870 the user defined type vector. */
16872 static struct type
*
16873 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16876 struct type
*to_type
;
16877 struct type
*domain
;
16879 to_type
= die_type (die
, cu
);
16880 domain
= die_containing_type (die
, cu
);
16882 /* The calls above may have already set the type for this DIE. */
16883 type
= get_die_type (die
, cu
);
16887 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16888 type
= lookup_methodptr_type (to_type
);
16889 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16891 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16893 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16894 to_type
->fields (), to_type
->num_fields (),
16895 TYPE_VARARGS (to_type
));
16896 type
= lookup_methodptr_type (new_type
);
16899 type
= lookup_memberptr_type (to_type
, domain
);
16901 return set_die_type (die
, type
, cu
);
16904 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16905 the user defined type vector. */
16907 static struct type
*
16908 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16909 enum type_code refcode
)
16911 struct comp_unit_head
*cu_header
= &cu
->header
;
16912 struct type
*type
, *target_type
;
16913 struct attribute
*attr
;
16915 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16917 target_type
= die_type (die
, cu
);
16919 /* The die_type call above may have already set the type for this DIE. */
16920 type
= get_die_type (die
, cu
);
16924 type
= lookup_reference_type (target_type
, refcode
);
16925 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16926 if (attr
!= nullptr)
16928 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16932 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16934 maybe_set_alignment (cu
, die
, type
);
16935 return set_die_type (die
, type
, cu
);
16938 /* Add the given cv-qualifiers to the element type of the array. GCC
16939 outputs DWARF type qualifiers that apply to an array, not the
16940 element type. But GDB relies on the array element type to carry
16941 the cv-qualifiers. This mimics section 6.7.3 of the C99
16944 static struct type
*
16945 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16946 struct type
*base_type
, int cnst
, int voltl
)
16948 struct type
*el_type
, *inner_array
;
16950 base_type
= copy_type (base_type
);
16951 inner_array
= base_type
;
16953 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16955 TYPE_TARGET_TYPE (inner_array
) =
16956 copy_type (TYPE_TARGET_TYPE (inner_array
));
16957 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16960 el_type
= TYPE_TARGET_TYPE (inner_array
);
16961 cnst
|= TYPE_CONST (el_type
);
16962 voltl
|= TYPE_VOLATILE (el_type
);
16963 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16965 return set_die_type (die
, base_type
, cu
);
16968 static struct type
*
16969 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16971 struct type
*base_type
, *cv_type
;
16973 base_type
= die_type (die
, cu
);
16975 /* The die_type call above may have already set the type for this DIE. */
16976 cv_type
= get_die_type (die
, cu
);
16980 /* In case the const qualifier is applied to an array type, the element type
16981 is so qualified, not the array type (section 6.7.3 of C99). */
16982 if (base_type
->code () == TYPE_CODE_ARRAY
)
16983 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16985 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16986 return set_die_type (die
, cv_type
, cu
);
16989 static struct type
*
16990 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16992 struct type
*base_type
, *cv_type
;
16994 base_type
= die_type (die
, cu
);
16996 /* The die_type call above may have already set the type for this DIE. */
16997 cv_type
= get_die_type (die
, cu
);
17001 /* In case the volatile qualifier is applied to an array type, the
17002 element type is so qualified, not the array type (section 6.7.3
17004 if (base_type
->code () == TYPE_CODE_ARRAY
)
17005 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17007 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17008 return set_die_type (die
, cv_type
, cu
);
17011 /* Handle DW_TAG_restrict_type. */
17013 static struct type
*
17014 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17016 struct type
*base_type
, *cv_type
;
17018 base_type
= die_type (die
, cu
);
17020 /* The die_type call above may have already set the type for this DIE. */
17021 cv_type
= get_die_type (die
, cu
);
17025 cv_type
= make_restrict_type (base_type
);
17026 return set_die_type (die
, cv_type
, cu
);
17029 /* Handle DW_TAG_atomic_type. */
17031 static struct type
*
17032 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17034 struct type
*base_type
, *cv_type
;
17036 base_type
= die_type (die
, cu
);
17038 /* The die_type call above may have already set the type for this DIE. */
17039 cv_type
= get_die_type (die
, cu
);
17043 cv_type
= make_atomic_type (base_type
);
17044 return set_die_type (die
, cv_type
, cu
);
17047 /* Extract all information from a DW_TAG_string_type DIE and add to
17048 the user defined type vector. It isn't really a user defined type,
17049 but it behaves like one, with other DIE's using an AT_user_def_type
17050 attribute to reference it. */
17052 static struct type
*
17053 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17055 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17056 struct gdbarch
*gdbarch
= objfile
->arch ();
17057 struct type
*type
, *range_type
, *index_type
, *char_type
;
17058 struct attribute
*attr
;
17059 struct dynamic_prop prop
;
17060 bool length_is_constant
= true;
17063 /* There are a couple of places where bit sizes might be made use of
17064 when parsing a DW_TAG_string_type, however, no producer that we know
17065 of make use of these. Handling bit sizes that are a multiple of the
17066 byte size is easy enough, but what about other bit sizes? Lets deal
17067 with that problem when we have to. Warn about these attributes being
17068 unsupported, then parse the type and ignore them like we always
17070 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17071 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17073 static bool warning_printed
= false;
17074 if (!warning_printed
)
17076 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17077 "currently supported on DW_TAG_string_type."));
17078 warning_printed
= true;
17082 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17083 if (attr
!= nullptr && !attr
->form_is_constant ())
17085 /* The string length describes the location at which the length of
17086 the string can be found. The size of the length field can be
17087 specified with one of the attributes below. */
17088 struct type
*prop_type
;
17089 struct attribute
*len
17090 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17091 if (len
== nullptr)
17092 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17093 if (len
!= nullptr && len
->form_is_constant ())
17095 /* Pass 0 as the default as we know this attribute is constant
17096 and the default value will not be returned. */
17097 LONGEST sz
= len
->constant_value (0);
17098 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17102 /* If the size is not specified then we assume it is the size of
17103 an address on this target. */
17104 prop_type
= cu
->addr_sized_int_type (true);
17107 /* Convert the attribute into a dynamic property. */
17108 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17111 length_is_constant
= false;
17113 else if (attr
!= nullptr)
17115 /* This DW_AT_string_length just contains the length with no
17116 indirection. There's no need to create a dynamic property in this
17117 case. Pass 0 for the default value as we know it will not be
17118 returned in this case. */
17119 length
= attr
->constant_value (0);
17121 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17123 /* We don't currently support non-constant byte sizes for strings. */
17124 length
= attr
->constant_value (1);
17128 /* Use 1 as a fallback length if we have nothing else. */
17132 index_type
= objfile_type (objfile
)->builtin_int
;
17133 if (length_is_constant
)
17134 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17137 struct dynamic_prop low_bound
;
17139 low_bound
.set_const_val (1);
17140 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17142 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17143 type
= create_string_type (NULL
, char_type
, range_type
);
17145 return set_die_type (die
, type
, cu
);
17148 /* Assuming that DIE corresponds to a function, returns nonzero
17149 if the function is prototyped. */
17152 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17154 struct attribute
*attr
;
17156 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17157 if (attr
&& (DW_UNSND (attr
) != 0))
17160 /* The DWARF standard implies that the DW_AT_prototyped attribute
17161 is only meaningful for C, but the concept also extends to other
17162 languages that allow unprototyped functions (Eg: Objective C).
17163 For all other languages, assume that functions are always
17165 if (cu
->language
!= language_c
17166 && cu
->language
!= language_objc
17167 && cu
->language
!= language_opencl
)
17170 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17171 prototyped and unprototyped functions; default to prototyped,
17172 since that is more common in modern code (and RealView warns
17173 about unprototyped functions). */
17174 if (producer_is_realview (cu
->producer
))
17180 /* Handle DIES due to C code like:
17184 int (*funcp)(int a, long l);
17188 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17190 static struct type
*
17191 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17193 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17194 struct type
*type
; /* Type that this function returns. */
17195 struct type
*ftype
; /* Function that returns above type. */
17196 struct attribute
*attr
;
17198 type
= die_type (die
, cu
);
17200 /* The die_type call above may have already set the type for this DIE. */
17201 ftype
= get_die_type (die
, cu
);
17205 ftype
= lookup_function_type (type
);
17207 if (prototyped_function_p (die
, cu
))
17208 TYPE_PROTOTYPED (ftype
) = 1;
17210 /* Store the calling convention in the type if it's available in
17211 the subroutine die. Otherwise set the calling convention to
17212 the default value DW_CC_normal. */
17213 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17214 if (attr
!= nullptr
17215 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17216 TYPE_CALLING_CONVENTION (ftype
)
17217 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17218 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17219 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17221 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17223 /* Record whether the function returns normally to its caller or not
17224 if the DWARF producer set that information. */
17225 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17226 if (attr
&& (DW_UNSND (attr
) != 0))
17227 TYPE_NO_RETURN (ftype
) = 1;
17229 /* We need to add the subroutine type to the die immediately so
17230 we don't infinitely recurse when dealing with parameters
17231 declared as the same subroutine type. */
17232 set_die_type (die
, ftype
, cu
);
17234 if (die
->child
!= NULL
)
17236 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17237 struct die_info
*child_die
;
17238 int nparams
, iparams
;
17240 /* Count the number of parameters.
17241 FIXME: GDB currently ignores vararg functions, but knows about
17242 vararg member functions. */
17244 child_die
= die
->child
;
17245 while (child_die
&& child_die
->tag
)
17247 if (child_die
->tag
== DW_TAG_formal_parameter
)
17249 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17250 TYPE_VARARGS (ftype
) = 1;
17251 child_die
= child_die
->sibling
;
17254 /* Allocate storage for parameters and fill them in. */
17255 ftype
->set_num_fields (nparams
);
17257 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17259 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17260 even if we error out during the parameters reading below. */
17261 for (iparams
= 0; iparams
< nparams
; iparams
++)
17262 ftype
->field (iparams
).set_type (void_type
);
17265 child_die
= die
->child
;
17266 while (child_die
&& child_die
->tag
)
17268 if (child_die
->tag
== DW_TAG_formal_parameter
)
17270 struct type
*arg_type
;
17272 /* DWARF version 2 has no clean way to discern C++
17273 static and non-static member functions. G++ helps
17274 GDB by marking the first parameter for non-static
17275 member functions (which is the this pointer) as
17276 artificial. We pass this information to
17277 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17279 DWARF version 3 added DW_AT_object_pointer, which GCC
17280 4.5 does not yet generate. */
17281 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17282 if (attr
!= nullptr)
17283 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17285 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17286 arg_type
= die_type (child_die
, cu
);
17288 /* RealView does not mark THIS as const, which the testsuite
17289 expects. GCC marks THIS as const in method definitions,
17290 but not in the class specifications (GCC PR 43053). */
17291 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17292 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17295 struct dwarf2_cu
*arg_cu
= cu
;
17296 const char *name
= dwarf2_name (child_die
, cu
);
17298 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17299 if (attr
!= nullptr)
17301 /* If the compiler emits this, use it. */
17302 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17305 else if (name
&& strcmp (name
, "this") == 0)
17306 /* Function definitions will have the argument names. */
17308 else if (name
== NULL
&& iparams
== 0)
17309 /* Declarations may not have the names, so like
17310 elsewhere in GDB, assume an artificial first
17311 argument is "this". */
17315 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17319 ftype
->field (iparams
).set_type (arg_type
);
17322 child_die
= child_die
->sibling
;
17329 static struct type
*
17330 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17332 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17333 const char *name
= NULL
;
17334 struct type
*this_type
, *target_type
;
17336 name
= dwarf2_full_name (NULL
, die
, cu
);
17337 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17338 TYPE_TARGET_STUB (this_type
) = 1;
17339 set_die_type (die
, this_type
, cu
);
17340 target_type
= die_type (die
, cu
);
17341 if (target_type
!= this_type
)
17342 TYPE_TARGET_TYPE (this_type
) = target_type
;
17345 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17346 spec and cause infinite loops in GDB. */
17347 complaint (_("Self-referential DW_TAG_typedef "
17348 "- DIE at %s [in module %s]"),
17349 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17350 TYPE_TARGET_TYPE (this_type
) = NULL
;
17354 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17355 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17356 Handle these by just returning the target type, rather than
17357 constructing an anonymous typedef type and trying to handle this
17359 set_die_type (die
, target_type
, cu
);
17360 return target_type
;
17365 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17366 (which may be different from NAME) to the architecture back-end to allow
17367 it to guess the correct format if necessary. */
17369 static struct type
*
17370 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17371 const char *name_hint
, enum bfd_endian byte_order
)
17373 struct gdbarch
*gdbarch
= objfile
->arch ();
17374 const struct floatformat
**format
;
17377 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17379 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17381 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17386 /* Allocate an integer type of size BITS and name NAME. */
17388 static struct type
*
17389 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17390 int bits
, int unsigned_p
, const char *name
)
17394 /* Versions of Intel's C Compiler generate an integer type called "void"
17395 instead of using DW_TAG_unspecified_type. This has been seen on
17396 at least versions 14, 17, and 18. */
17397 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17398 && strcmp (name
, "void") == 0)
17399 type
= objfile_type (objfile
)->builtin_void
;
17401 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17406 /* Initialise and return a floating point type of size BITS suitable for
17407 use as a component of a complex number. The NAME_HINT is passed through
17408 when initialising the floating point type and is the name of the complex
17411 As DWARF doesn't currently provide an explicit name for the components
17412 of a complex number, but it can be helpful to have these components
17413 named, we try to select a suitable name based on the size of the
17415 static struct type
*
17416 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17417 struct objfile
*objfile
,
17418 int bits
, const char *name_hint
,
17419 enum bfd_endian byte_order
)
17421 gdbarch
*gdbarch
= objfile
->arch ();
17422 struct type
*tt
= nullptr;
17424 /* Try to find a suitable floating point builtin type of size BITS.
17425 We're going to use the name of this type as the name for the complex
17426 target type that we are about to create. */
17427 switch (cu
->language
)
17429 case language_fortran
:
17433 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17436 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17438 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17440 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17448 tt
= builtin_type (gdbarch
)->builtin_float
;
17451 tt
= builtin_type (gdbarch
)->builtin_double
;
17453 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17455 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17461 /* If the type we found doesn't match the size we were looking for, then
17462 pretend we didn't find a type at all, the complex target type we
17463 create will then be nameless. */
17464 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17467 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17468 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17471 /* Find a representation of a given base type and install
17472 it in the TYPE field of the die. */
17474 static struct type
*
17475 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17477 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17479 struct attribute
*attr
;
17480 int encoding
= 0, bits
= 0;
17484 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17485 if (attr
!= nullptr)
17486 encoding
= DW_UNSND (attr
);
17487 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17488 if (attr
!= nullptr)
17489 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17490 name
= dwarf2_name (die
, cu
);
17492 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17494 arch
= objfile
->arch ();
17495 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17497 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17500 int endianity
= DW_UNSND (attr
);
17505 byte_order
= BFD_ENDIAN_BIG
;
17507 case DW_END_little
:
17508 byte_order
= BFD_ENDIAN_LITTLE
;
17511 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17518 case DW_ATE_address
:
17519 /* Turn DW_ATE_address into a void * pointer. */
17520 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17521 type
= init_pointer_type (objfile
, bits
, name
, type
);
17523 case DW_ATE_boolean
:
17524 type
= init_boolean_type (objfile
, bits
, 1, name
);
17526 case DW_ATE_complex_float
:
17527 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17529 if (type
->code () == TYPE_CODE_ERROR
)
17531 if (name
== nullptr)
17533 struct obstack
*obstack
17534 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17535 name
= obconcat (obstack
, "_Complex ", type
->name (),
17538 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17541 type
= init_complex_type (name
, type
);
17543 case DW_ATE_decimal_float
:
17544 type
= init_decfloat_type (objfile
, bits
, name
);
17547 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17549 case DW_ATE_signed
:
17550 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17552 case DW_ATE_unsigned
:
17553 if (cu
->language
== language_fortran
17555 && startswith (name
, "character("))
17556 type
= init_character_type (objfile
, bits
, 1, name
);
17558 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17560 case DW_ATE_signed_char
:
17561 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17562 || cu
->language
== language_pascal
17563 || cu
->language
== language_fortran
)
17564 type
= init_character_type (objfile
, bits
, 0, name
);
17566 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17568 case DW_ATE_unsigned_char
:
17569 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17570 || cu
->language
== language_pascal
17571 || cu
->language
== language_fortran
17572 || cu
->language
== language_rust
)
17573 type
= init_character_type (objfile
, bits
, 1, name
);
17575 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17580 type
= builtin_type (arch
)->builtin_char16
;
17581 else if (bits
== 32)
17582 type
= builtin_type (arch
)->builtin_char32
;
17585 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17587 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17589 return set_die_type (die
, type
, cu
);
17594 complaint (_("unsupported DW_AT_encoding: '%s'"),
17595 dwarf_type_encoding_name (encoding
));
17596 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17600 if (name
&& strcmp (name
, "char") == 0)
17601 TYPE_NOSIGN (type
) = 1;
17603 maybe_set_alignment (cu
, die
, type
);
17605 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17607 return set_die_type (die
, type
, cu
);
17610 /* Parse dwarf attribute if it's a block, reference or constant and put the
17611 resulting value of the attribute into struct bound_prop.
17612 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17615 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17616 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17617 struct type
*default_type
)
17619 struct dwarf2_property_baton
*baton
;
17620 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17621 struct objfile
*objfile
= per_objfile
->objfile
;
17622 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17624 gdb_assert (default_type
!= NULL
);
17626 if (attr
== NULL
|| prop
== NULL
)
17629 if (attr
->form_is_block ())
17631 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17632 baton
->property_type
= default_type
;
17633 baton
->locexpr
.per_cu
= cu
->per_cu
;
17634 baton
->locexpr
.per_objfile
= per_objfile
;
17635 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17636 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17637 switch (attr
->name
)
17639 case DW_AT_string_length
:
17640 baton
->locexpr
.is_reference
= true;
17643 baton
->locexpr
.is_reference
= false;
17647 prop
->set_locexpr (baton
);
17648 gdb_assert (prop
->baton () != NULL
);
17650 else if (attr
->form_is_ref ())
17652 struct dwarf2_cu
*target_cu
= cu
;
17653 struct die_info
*target_die
;
17654 struct attribute
*target_attr
;
17656 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17657 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17658 if (target_attr
== NULL
)
17659 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17661 if (target_attr
== NULL
)
17664 switch (target_attr
->name
)
17666 case DW_AT_location
:
17667 if (target_attr
->form_is_section_offset ())
17669 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17670 baton
->property_type
= die_type (target_die
, target_cu
);
17671 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17672 prop
->set_loclist (baton
);
17673 gdb_assert (prop
->baton () != NULL
);
17675 else if (target_attr
->form_is_block ())
17677 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17678 baton
->property_type
= die_type (target_die
, target_cu
);
17679 baton
->locexpr
.per_cu
= cu
->per_cu
;
17680 baton
->locexpr
.per_objfile
= per_objfile
;
17681 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17682 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17683 baton
->locexpr
.is_reference
= true;
17684 prop
->set_locexpr (baton
);
17685 gdb_assert (prop
->baton () != NULL
);
17689 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17690 "dynamic property");
17694 case DW_AT_data_member_location
:
17698 if (!handle_data_member_location (target_die
, target_cu
,
17702 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17703 baton
->property_type
= read_type_die (target_die
->parent
,
17705 baton
->offset_info
.offset
= offset
;
17706 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17707 prop
->set_addr_offset (baton
);
17712 else if (attr
->form_is_constant ())
17713 prop
->set_const_val (attr
->constant_value (0));
17716 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17717 dwarf2_name (die
, cu
));
17727 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17729 struct type
*int_type
;
17731 /* Helper macro to examine the various builtin types. */
17732 #define TRY_TYPE(F) \
17733 int_type = (unsigned_p \
17734 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17735 : objfile_type (objfile)->builtin_ ## F); \
17736 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17743 TRY_TYPE (long_long
);
17747 gdb_assert_not_reached ("unable to find suitable integer type");
17753 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17755 int addr_size
= this->per_cu
->addr_size ();
17756 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17759 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17760 present (which is valid) then compute the default type based on the
17761 compilation units address size. */
17763 static struct type
*
17764 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17766 struct type
*index_type
= die_type (die
, cu
);
17768 /* Dwarf-2 specifications explicitly allows to create subrange types
17769 without specifying a base type.
17770 In that case, the base type must be set to the type of
17771 the lower bound, upper bound or count, in that order, if any of these
17772 three attributes references an object that has a type.
17773 If no base type is found, the Dwarf-2 specifications say that
17774 a signed integer type of size equal to the size of an address should
17776 For the following C code: `extern char gdb_int [];'
17777 GCC produces an empty range DIE.
17778 FIXME: muller/2010-05-28: Possible references to object for low bound,
17779 high bound or count are not yet handled by this code. */
17780 if (index_type
->code () == TYPE_CODE_VOID
)
17781 index_type
= cu
->addr_sized_int_type (false);
17786 /* Read the given DW_AT_subrange DIE. */
17788 static struct type
*
17789 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17791 struct type
*base_type
, *orig_base_type
;
17792 struct type
*range_type
;
17793 struct attribute
*attr
;
17794 struct dynamic_prop low
, high
;
17795 int low_default_is_valid
;
17796 int high_bound_is_count
= 0;
17798 ULONGEST negative_mask
;
17800 orig_base_type
= read_subrange_index_type (die
, cu
);
17802 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17803 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17804 creating the range type, but we use the result of check_typedef
17805 when examining properties of the type. */
17806 base_type
= check_typedef (orig_base_type
);
17808 /* The die_type call above may have already set the type for this DIE. */
17809 range_type
= get_die_type (die
, cu
);
17813 high
.set_const_val (0);
17815 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17816 omitting DW_AT_lower_bound. */
17817 switch (cu
->language
)
17820 case language_cplus
:
17821 low
.set_const_val (0);
17822 low_default_is_valid
= 1;
17824 case language_fortran
:
17825 low
.set_const_val (1);
17826 low_default_is_valid
= 1;
17829 case language_objc
:
17830 case language_rust
:
17831 low
.set_const_val (0);
17832 low_default_is_valid
= (cu
->header
.version
>= 4);
17836 case language_pascal
:
17837 low
.set_const_val (1);
17838 low_default_is_valid
= (cu
->header
.version
>= 4);
17841 low
.set_const_val (0);
17842 low_default_is_valid
= 0;
17846 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17847 if (attr
!= nullptr)
17848 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17849 else if (!low_default_is_valid
)
17850 complaint (_("Missing DW_AT_lower_bound "
17851 "- DIE at %s [in module %s]"),
17852 sect_offset_str (die
->sect_off
),
17853 objfile_name (cu
->per_objfile
->objfile
));
17855 struct attribute
*attr_ub
, *attr_count
;
17856 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17857 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17859 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17860 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17862 /* If bounds are constant do the final calculation here. */
17863 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
17864 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
17866 high_bound_is_count
= 1;
17870 if (attr_ub
!= NULL
)
17871 complaint (_("Unresolved DW_AT_upper_bound "
17872 "- DIE at %s [in module %s]"),
17873 sect_offset_str (die
->sect_off
),
17874 objfile_name (cu
->per_objfile
->objfile
));
17875 if (attr_count
!= NULL
)
17876 complaint (_("Unresolved DW_AT_count "
17877 "- DIE at %s [in module %s]"),
17878 sect_offset_str (die
->sect_off
),
17879 objfile_name (cu
->per_objfile
->objfile
));
17884 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17885 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17886 bias
= bias_attr
->constant_value (0);
17888 /* Normally, the DWARF producers are expected to use a signed
17889 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17890 But this is unfortunately not always the case, as witnessed
17891 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17892 is used instead. To work around that ambiguity, we treat
17893 the bounds as signed, and thus sign-extend their values, when
17894 the base type is signed. */
17896 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17897 if (low
.kind () == PROP_CONST
17898 && !TYPE_UNSIGNED (base_type
) && (low
.const_val () & negative_mask
))
17899 low
.set_const_val (low
.const_val () | negative_mask
);
17900 if (high
.kind () == PROP_CONST
17901 && !TYPE_UNSIGNED (base_type
) && (high
.const_val () & negative_mask
))
17902 high
.set_const_val (high
.const_val () | negative_mask
);
17904 /* Check for bit and byte strides. */
17905 struct dynamic_prop byte_stride_prop
;
17906 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17907 if (attr_byte_stride
!= nullptr)
17909 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17910 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17914 struct dynamic_prop bit_stride_prop
;
17915 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17916 if (attr_bit_stride
!= nullptr)
17918 /* It only makes sense to have either a bit or byte stride. */
17919 if (attr_byte_stride
!= nullptr)
17921 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17922 "- DIE at %s [in module %s]"),
17923 sect_offset_str (die
->sect_off
),
17924 objfile_name (cu
->per_objfile
->objfile
));
17925 attr_bit_stride
= nullptr;
17929 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17930 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17935 if (attr_byte_stride
!= nullptr
17936 || attr_bit_stride
!= nullptr)
17938 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17939 struct dynamic_prop
*stride
17940 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17943 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17944 &high
, bias
, stride
, byte_stride_p
);
17947 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17949 if (high_bound_is_count
)
17950 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
17952 /* Ada expects an empty array on no boundary attributes. */
17953 if (attr
== NULL
&& cu
->language
!= language_ada
)
17954 range_type
->bounds ()->high
.set_undefined ();
17956 name
= dwarf2_name (die
, cu
);
17958 range_type
->set_name (name
);
17960 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17961 if (attr
!= nullptr)
17962 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17964 maybe_set_alignment (cu
, die
, range_type
);
17966 set_die_type (die
, range_type
, cu
);
17968 /* set_die_type should be already done. */
17969 set_descriptive_type (range_type
, die
, cu
);
17974 static struct type
*
17975 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17979 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17980 type
->set_name (dwarf2_name (die
, cu
));
17982 /* In Ada, an unspecified type is typically used when the description
17983 of the type is deferred to a different unit. When encountering
17984 such a type, we treat it as a stub, and try to resolve it later on,
17986 if (cu
->language
== language_ada
)
17987 TYPE_STUB (type
) = 1;
17989 return set_die_type (die
, type
, cu
);
17992 /* Read a single die and all its descendents. Set the die's sibling
17993 field to NULL; set other fields in the die correctly, and set all
17994 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17995 location of the info_ptr after reading all of those dies. PARENT
17996 is the parent of the die in question. */
17998 static struct die_info
*
17999 read_die_and_children (const struct die_reader_specs
*reader
,
18000 const gdb_byte
*info_ptr
,
18001 const gdb_byte
**new_info_ptr
,
18002 struct die_info
*parent
)
18004 struct die_info
*die
;
18005 const gdb_byte
*cur_ptr
;
18007 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18010 *new_info_ptr
= cur_ptr
;
18013 store_in_ref_table (die
, reader
->cu
);
18015 if (die
->has_children
)
18016 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18020 *new_info_ptr
= cur_ptr
;
18023 die
->sibling
= NULL
;
18024 die
->parent
= parent
;
18028 /* Read a die, all of its descendents, and all of its siblings; set
18029 all of the fields of all of the dies correctly. Arguments are as
18030 in read_die_and_children. */
18032 static struct die_info
*
18033 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18034 const gdb_byte
*info_ptr
,
18035 const gdb_byte
**new_info_ptr
,
18036 struct die_info
*parent
)
18038 struct die_info
*first_die
, *last_sibling
;
18039 const gdb_byte
*cur_ptr
;
18041 cur_ptr
= info_ptr
;
18042 first_die
= last_sibling
= NULL
;
18046 struct die_info
*die
18047 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18051 *new_info_ptr
= cur_ptr
;
18058 last_sibling
->sibling
= die
;
18060 last_sibling
= die
;
18064 /* Read a die, all of its descendents, and all of its siblings; set
18065 all of the fields of all of the dies correctly. Arguments are as
18066 in read_die_and_children.
18067 This the main entry point for reading a DIE and all its children. */
18069 static struct die_info
*
18070 read_die_and_siblings (const struct die_reader_specs
*reader
,
18071 const gdb_byte
*info_ptr
,
18072 const gdb_byte
**new_info_ptr
,
18073 struct die_info
*parent
)
18075 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18076 new_info_ptr
, parent
);
18078 if (dwarf_die_debug
)
18080 fprintf_unfiltered (gdb_stdlog
,
18081 "Read die from %s@0x%x of %s:\n",
18082 reader
->die_section
->get_name (),
18083 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18084 bfd_get_filename (reader
->abfd
));
18085 dump_die (die
, dwarf_die_debug
);
18091 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18093 The caller is responsible for filling in the extra attributes
18094 and updating (*DIEP)->num_attrs.
18095 Set DIEP to point to a newly allocated die with its information,
18096 except for its child, sibling, and parent fields. */
18098 static const gdb_byte
*
18099 read_full_die_1 (const struct die_reader_specs
*reader
,
18100 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18101 int num_extra_attrs
)
18103 unsigned int abbrev_number
, bytes_read
, i
;
18104 struct abbrev_info
*abbrev
;
18105 struct die_info
*die
;
18106 struct dwarf2_cu
*cu
= reader
->cu
;
18107 bfd
*abfd
= reader
->abfd
;
18109 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18110 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18111 info_ptr
+= bytes_read
;
18112 if (!abbrev_number
)
18118 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18120 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18122 bfd_get_filename (abfd
));
18124 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18125 die
->sect_off
= sect_off
;
18126 die
->tag
= abbrev
->tag
;
18127 die
->abbrev
= abbrev_number
;
18128 die
->has_children
= abbrev
->has_children
;
18130 /* Make the result usable.
18131 The caller needs to update num_attrs after adding the extra
18133 die
->num_attrs
= abbrev
->num_attrs
;
18135 std::vector
<int> indexes_that_need_reprocess
;
18136 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18138 bool need_reprocess
;
18140 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18141 info_ptr
, &need_reprocess
);
18142 if (need_reprocess
)
18143 indexes_that_need_reprocess
.push_back (i
);
18146 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18147 if (attr
!= nullptr)
18148 cu
->str_offsets_base
= DW_UNSND (attr
);
18150 attr
= die
->attr (DW_AT_loclists_base
);
18151 if (attr
!= nullptr)
18152 cu
->loclist_base
= DW_UNSND (attr
);
18154 auto maybe_addr_base
= die
->addr_base ();
18155 if (maybe_addr_base
.has_value ())
18156 cu
->addr_base
= *maybe_addr_base
;
18157 for (int index
: indexes_that_need_reprocess
)
18158 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18163 /* Read a die and all its attributes.
18164 Set DIEP to point to a newly allocated die with its information,
18165 except for its child, sibling, and parent fields. */
18167 static const gdb_byte
*
18168 read_full_die (const struct die_reader_specs
*reader
,
18169 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18171 const gdb_byte
*result
;
18173 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18175 if (dwarf_die_debug
)
18177 fprintf_unfiltered (gdb_stdlog
,
18178 "Read die from %s@0x%x of %s:\n",
18179 reader
->die_section
->get_name (),
18180 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18181 bfd_get_filename (reader
->abfd
));
18182 dump_die (*diep
, dwarf_die_debug
);
18189 /* Returns nonzero if TAG represents a type that we might generate a partial
18193 is_type_tag_for_partial (int tag
)
18198 /* Some types that would be reasonable to generate partial symbols for,
18199 that we don't at present. */
18200 case DW_TAG_array_type
:
18201 case DW_TAG_file_type
:
18202 case DW_TAG_ptr_to_member_type
:
18203 case DW_TAG_set_type
:
18204 case DW_TAG_string_type
:
18205 case DW_TAG_subroutine_type
:
18207 case DW_TAG_base_type
:
18208 case DW_TAG_class_type
:
18209 case DW_TAG_interface_type
:
18210 case DW_TAG_enumeration_type
:
18211 case DW_TAG_structure_type
:
18212 case DW_TAG_subrange_type
:
18213 case DW_TAG_typedef
:
18214 case DW_TAG_union_type
:
18221 /* Load all DIEs that are interesting for partial symbols into memory. */
18223 static struct partial_die_info
*
18224 load_partial_dies (const struct die_reader_specs
*reader
,
18225 const gdb_byte
*info_ptr
, int building_psymtab
)
18227 struct dwarf2_cu
*cu
= reader
->cu
;
18228 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18229 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18230 unsigned int bytes_read
;
18231 unsigned int load_all
= 0;
18232 int nesting_level
= 1;
18237 gdb_assert (cu
->per_cu
!= NULL
);
18238 if (cu
->per_cu
->load_all_dies
)
18242 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18246 &cu
->comp_unit_obstack
,
18247 hashtab_obstack_allocate
,
18248 dummy_obstack_deallocate
);
18252 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18254 /* A NULL abbrev means the end of a series of children. */
18255 if (abbrev
== NULL
)
18257 if (--nesting_level
== 0)
18260 info_ptr
+= bytes_read
;
18261 last_die
= parent_die
;
18262 parent_die
= parent_die
->die_parent
;
18266 /* Check for template arguments. We never save these; if
18267 they're seen, we just mark the parent, and go on our way. */
18268 if (parent_die
!= NULL
18269 && cu
->language
== language_cplus
18270 && (abbrev
->tag
== DW_TAG_template_type_param
18271 || abbrev
->tag
== DW_TAG_template_value_param
))
18273 parent_die
->has_template_arguments
= 1;
18277 /* We don't need a partial DIE for the template argument. */
18278 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18283 /* We only recurse into c++ subprograms looking for template arguments.
18284 Skip their other children. */
18286 && cu
->language
== language_cplus
18287 && parent_die
!= NULL
18288 && parent_die
->tag
== DW_TAG_subprogram
18289 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18291 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18295 /* Check whether this DIE is interesting enough to save. Normally
18296 we would not be interested in members here, but there may be
18297 later variables referencing them via DW_AT_specification (for
18298 static members). */
18300 && !is_type_tag_for_partial (abbrev
->tag
)
18301 && abbrev
->tag
!= DW_TAG_constant
18302 && abbrev
->tag
!= DW_TAG_enumerator
18303 && abbrev
->tag
!= DW_TAG_subprogram
18304 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18305 && abbrev
->tag
!= DW_TAG_lexical_block
18306 && abbrev
->tag
!= DW_TAG_variable
18307 && abbrev
->tag
!= DW_TAG_namespace
18308 && abbrev
->tag
!= DW_TAG_module
18309 && abbrev
->tag
!= DW_TAG_member
18310 && abbrev
->tag
!= DW_TAG_imported_unit
18311 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18313 /* Otherwise we skip to the next sibling, if any. */
18314 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18318 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18321 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18323 /* This two-pass algorithm for processing partial symbols has a
18324 high cost in cache pressure. Thus, handle some simple cases
18325 here which cover the majority of C partial symbols. DIEs
18326 which neither have specification tags in them, nor could have
18327 specification tags elsewhere pointing at them, can simply be
18328 processed and discarded.
18330 This segment is also optional; scan_partial_symbols and
18331 add_partial_symbol will handle these DIEs if we chain
18332 them in normally. When compilers which do not emit large
18333 quantities of duplicate debug information are more common,
18334 this code can probably be removed. */
18336 /* Any complete simple types at the top level (pretty much all
18337 of them, for a language without namespaces), can be processed
18339 if (parent_die
== NULL
18340 && pdi
.has_specification
== 0
18341 && pdi
.is_declaration
== 0
18342 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18343 || pdi
.tag
== DW_TAG_base_type
18344 || pdi
.tag
== DW_TAG_subrange_type
))
18346 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18347 add_partial_symbol (&pdi
, cu
);
18349 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18353 /* The exception for DW_TAG_typedef with has_children above is
18354 a workaround of GCC PR debug/47510. In the case of this complaint
18355 type_name_or_error will error on such types later.
18357 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18358 it could not find the child DIEs referenced later, this is checked
18359 above. In correct DWARF DW_TAG_typedef should have no children. */
18361 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18362 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18363 "- DIE at %s [in module %s]"),
18364 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18366 /* If we're at the second level, and we're an enumerator, and
18367 our parent has no specification (meaning possibly lives in a
18368 namespace elsewhere), then we can add the partial symbol now
18369 instead of queueing it. */
18370 if (pdi
.tag
== DW_TAG_enumerator
18371 && parent_die
!= NULL
18372 && parent_die
->die_parent
== NULL
18373 && parent_die
->tag
== DW_TAG_enumeration_type
18374 && parent_die
->has_specification
== 0)
18376 if (pdi
.raw_name
== NULL
)
18377 complaint (_("malformed enumerator DIE ignored"));
18378 else if (building_psymtab
)
18379 add_partial_symbol (&pdi
, cu
);
18381 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18385 struct partial_die_info
*part_die
18386 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18388 /* We'll save this DIE so link it in. */
18389 part_die
->die_parent
= parent_die
;
18390 part_die
->die_sibling
= NULL
;
18391 part_die
->die_child
= NULL
;
18393 if (last_die
&& last_die
== parent_die
)
18394 last_die
->die_child
= part_die
;
18396 last_die
->die_sibling
= part_die
;
18398 last_die
= part_die
;
18400 if (first_die
== NULL
)
18401 first_die
= part_die
;
18403 /* Maybe add the DIE to the hash table. Not all DIEs that we
18404 find interesting need to be in the hash table, because we
18405 also have the parent/sibling/child chains; only those that we
18406 might refer to by offset later during partial symbol reading.
18408 For now this means things that might have be the target of a
18409 DW_AT_specification, DW_AT_abstract_origin, or
18410 DW_AT_extension. DW_AT_extension will refer only to
18411 namespaces; DW_AT_abstract_origin refers to functions (and
18412 many things under the function DIE, but we do not recurse
18413 into function DIEs during partial symbol reading) and
18414 possibly variables as well; DW_AT_specification refers to
18415 declarations. Declarations ought to have the DW_AT_declaration
18416 flag. It happens that GCC forgets to put it in sometimes, but
18417 only for functions, not for types.
18419 Adding more things than necessary to the hash table is harmless
18420 except for the performance cost. Adding too few will result in
18421 wasted time in find_partial_die, when we reread the compilation
18422 unit with load_all_dies set. */
18425 || abbrev
->tag
== DW_TAG_constant
18426 || abbrev
->tag
== DW_TAG_subprogram
18427 || abbrev
->tag
== DW_TAG_variable
18428 || abbrev
->tag
== DW_TAG_namespace
18429 || part_die
->is_declaration
)
18433 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18434 to_underlying (part_die
->sect_off
),
18439 /* For some DIEs we want to follow their children (if any). For C
18440 we have no reason to follow the children of structures; for other
18441 languages we have to, so that we can get at method physnames
18442 to infer fully qualified class names, for DW_AT_specification,
18443 and for C++ template arguments. For C++, we also look one level
18444 inside functions to find template arguments (if the name of the
18445 function does not already contain the template arguments).
18447 For Ada and Fortran, we need to scan the children of subprograms
18448 and lexical blocks as well because these languages allow the
18449 definition of nested entities that could be interesting for the
18450 debugger, such as nested subprograms for instance. */
18451 if (last_die
->has_children
18453 || last_die
->tag
== DW_TAG_namespace
18454 || last_die
->tag
== DW_TAG_module
18455 || last_die
->tag
== DW_TAG_enumeration_type
18456 || (cu
->language
== language_cplus
18457 && last_die
->tag
== DW_TAG_subprogram
18458 && (last_die
->raw_name
== NULL
18459 || strchr (last_die
->raw_name
, '<') == NULL
))
18460 || (cu
->language
!= language_c
18461 && (last_die
->tag
== DW_TAG_class_type
18462 || last_die
->tag
== DW_TAG_interface_type
18463 || last_die
->tag
== DW_TAG_structure_type
18464 || last_die
->tag
== DW_TAG_union_type
))
18465 || ((cu
->language
== language_ada
18466 || cu
->language
== language_fortran
)
18467 && (last_die
->tag
== DW_TAG_subprogram
18468 || last_die
->tag
== DW_TAG_lexical_block
))))
18471 parent_die
= last_die
;
18475 /* Otherwise we skip to the next sibling, if any. */
18476 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18478 /* Back to the top, do it again. */
18482 partial_die_info::partial_die_info (sect_offset sect_off_
,
18483 struct abbrev_info
*abbrev
)
18484 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18488 /* See class definition. */
18491 partial_die_info::name (dwarf2_cu
*cu
)
18493 if (!canonical_name
&& raw_name
!= nullptr)
18495 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18496 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18497 canonical_name
= 1;
18503 /* Read a minimal amount of information into the minimal die structure.
18504 INFO_PTR should point just after the initial uleb128 of a DIE. */
18507 partial_die_info::read (const struct die_reader_specs
*reader
,
18508 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18510 struct dwarf2_cu
*cu
= reader
->cu
;
18511 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18513 int has_low_pc_attr
= 0;
18514 int has_high_pc_attr
= 0;
18515 int high_pc_relative
= 0;
18517 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18520 bool need_reprocess
;
18521 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18522 info_ptr
, &need_reprocess
);
18523 /* String and address offsets that need to do the reprocessing have
18524 already been read at this point, so there is no need to wait until
18525 the loop terminates to do the reprocessing. */
18526 if (need_reprocess
)
18527 read_attribute_reprocess (reader
, &attr
);
18528 /* Store the data if it is of an attribute we want to keep in a
18529 partial symbol table. */
18535 case DW_TAG_compile_unit
:
18536 case DW_TAG_partial_unit
:
18537 case DW_TAG_type_unit
:
18538 /* Compilation units have a DW_AT_name that is a filename, not
18539 a source language identifier. */
18540 case DW_TAG_enumeration_type
:
18541 case DW_TAG_enumerator
:
18542 /* These tags always have simple identifiers already; no need
18543 to canonicalize them. */
18544 canonical_name
= 1;
18545 raw_name
= DW_STRING (&attr
);
18548 canonical_name
= 0;
18549 raw_name
= DW_STRING (&attr
);
18553 case DW_AT_linkage_name
:
18554 case DW_AT_MIPS_linkage_name
:
18555 /* Note that both forms of linkage name might appear. We
18556 assume they will be the same, and we only store the last
18558 linkage_name
= attr
.value_as_string ();
18559 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18560 See https://github.com/rust-lang/rust/issues/32925. */
18561 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18562 && strchr (linkage_name
, '{') != NULL
)
18563 linkage_name
= NULL
;
18566 has_low_pc_attr
= 1;
18567 lowpc
= attr
.value_as_address ();
18569 case DW_AT_high_pc
:
18570 has_high_pc_attr
= 1;
18571 highpc
= attr
.value_as_address ();
18572 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18573 high_pc_relative
= 1;
18575 case DW_AT_location
:
18576 /* Support the .debug_loc offsets. */
18577 if (attr
.form_is_block ())
18579 d
.locdesc
= DW_BLOCK (&attr
);
18581 else if (attr
.form_is_section_offset ())
18583 dwarf2_complex_location_expr_complaint ();
18587 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18588 "partial symbol information");
18591 case DW_AT_external
:
18592 is_external
= DW_UNSND (&attr
);
18594 case DW_AT_declaration
:
18595 is_declaration
= DW_UNSND (&attr
);
18600 case DW_AT_abstract_origin
:
18601 case DW_AT_specification
:
18602 case DW_AT_extension
:
18603 has_specification
= 1;
18604 spec_offset
= attr
.get_ref_die_offset ();
18605 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18606 || cu
->per_cu
->is_dwz
);
18608 case DW_AT_sibling
:
18609 /* Ignore absolute siblings, they might point outside of
18610 the current compile unit. */
18611 if (attr
.form
== DW_FORM_ref_addr
)
18612 complaint (_("ignoring absolute DW_AT_sibling"));
18615 const gdb_byte
*buffer
= reader
->buffer
;
18616 sect_offset off
= attr
.get_ref_die_offset ();
18617 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18619 if (sibling_ptr
< info_ptr
)
18620 complaint (_("DW_AT_sibling points backwards"));
18621 else if (sibling_ptr
> reader
->buffer_end
)
18622 reader
->die_section
->overflow_complaint ();
18624 sibling
= sibling_ptr
;
18627 case DW_AT_byte_size
:
18630 case DW_AT_const_value
:
18631 has_const_value
= 1;
18633 case DW_AT_calling_convention
:
18634 /* DWARF doesn't provide a way to identify a program's source-level
18635 entry point. DW_AT_calling_convention attributes are only meant
18636 to describe functions' calling conventions.
18638 However, because it's a necessary piece of information in
18639 Fortran, and before DWARF 4 DW_CC_program was the only
18640 piece of debugging information whose definition refers to
18641 a 'main program' at all, several compilers marked Fortran
18642 main programs with DW_CC_program --- even when those
18643 functions use the standard calling conventions.
18645 Although DWARF now specifies a way to provide this
18646 information, we support this practice for backward
18648 if (DW_UNSND (&attr
) == DW_CC_program
18649 && cu
->language
== language_fortran
)
18650 main_subprogram
= 1;
18653 if (DW_UNSND (&attr
) == DW_INL_inlined
18654 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18655 may_be_inlined
= 1;
18659 if (tag
== DW_TAG_imported_unit
)
18661 d
.sect_off
= attr
.get_ref_die_offset ();
18662 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18663 || cu
->per_cu
->is_dwz
);
18667 case DW_AT_main_subprogram
:
18668 main_subprogram
= DW_UNSND (&attr
);
18673 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18674 but that requires a full DIE, so instead we just
18676 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18677 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18678 + (need_ranges_base
18682 /* Value of the DW_AT_ranges attribute is the offset in the
18683 .debug_ranges section. */
18684 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18695 /* For Ada, if both the name and the linkage name appear, we prefer
18696 the latter. This lets "catch exception" work better, regardless
18697 of the order in which the name and linkage name were emitted.
18698 Really, though, this is just a workaround for the fact that gdb
18699 doesn't store both the name and the linkage name. */
18700 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18701 raw_name
= linkage_name
;
18703 if (high_pc_relative
)
18706 if (has_low_pc_attr
&& has_high_pc_attr
)
18708 /* When using the GNU linker, .gnu.linkonce. sections are used to
18709 eliminate duplicate copies of functions and vtables and such.
18710 The linker will arbitrarily choose one and discard the others.
18711 The AT_*_pc values for such functions refer to local labels in
18712 these sections. If the section from that file was discarded, the
18713 labels are not in the output, so the relocs get a value of 0.
18714 If this is a discarded function, mark the pc bounds as invalid,
18715 so that GDB will ignore it. */
18716 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
18718 struct objfile
*objfile
= per_objfile
->objfile
;
18719 struct gdbarch
*gdbarch
= objfile
->arch ();
18721 complaint (_("DW_AT_low_pc %s is zero "
18722 "for DIE at %s [in module %s]"),
18723 paddress (gdbarch
, lowpc
),
18724 sect_offset_str (sect_off
),
18725 objfile_name (objfile
));
18727 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18728 else if (lowpc
>= highpc
)
18730 struct objfile
*objfile
= per_objfile
->objfile
;
18731 struct gdbarch
*gdbarch
= objfile
->arch ();
18733 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18734 "for DIE at %s [in module %s]"),
18735 paddress (gdbarch
, lowpc
),
18736 paddress (gdbarch
, highpc
),
18737 sect_offset_str (sect_off
),
18738 objfile_name (objfile
));
18747 /* Find a cached partial DIE at OFFSET in CU. */
18749 struct partial_die_info
*
18750 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18752 struct partial_die_info
*lookup_die
= NULL
;
18753 struct partial_die_info
part_die (sect_off
);
18755 lookup_die
= ((struct partial_die_info
*)
18756 htab_find_with_hash (partial_dies
, &part_die
,
18757 to_underlying (sect_off
)));
18762 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18763 except in the case of .debug_types DIEs which do not reference
18764 outside their CU (they do however referencing other types via
18765 DW_FORM_ref_sig8). */
18767 static const struct cu_partial_die_info
18768 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18770 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18771 struct objfile
*objfile
= per_objfile
->objfile
;
18772 struct partial_die_info
*pd
= NULL
;
18774 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18775 && cu
->header
.offset_in_cu_p (sect_off
))
18777 pd
= cu
->find_partial_die (sect_off
);
18780 /* We missed recording what we needed.
18781 Load all dies and try again. */
18785 /* TUs don't reference other CUs/TUs (except via type signatures). */
18786 if (cu
->per_cu
->is_debug_types
)
18788 error (_("Dwarf Error: Type Unit at offset %s contains"
18789 " external reference to offset %s [in module %s].\n"),
18790 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18791 bfd_get_filename (objfile
->obfd
));
18793 dwarf2_per_cu_data
*per_cu
18794 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18797 cu
= per_objfile
->get_cu (per_cu
);
18798 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18799 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
18801 cu
= per_objfile
->get_cu (per_cu
);
18804 pd
= cu
->find_partial_die (sect_off
);
18807 /* If we didn't find it, and not all dies have been loaded,
18808 load them all and try again. */
18810 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18812 cu
->per_cu
->load_all_dies
= 1;
18814 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18815 THIS_CU->cu may already be in use. So we can't just free it and
18816 replace its DIEs with the ones we read in. Instead, we leave those
18817 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18818 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18820 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
18822 pd
= cu
->find_partial_die (sect_off
);
18826 internal_error (__FILE__
, __LINE__
,
18827 _("could not find partial DIE %s "
18828 "in cache [from module %s]\n"),
18829 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18833 /* See if we can figure out if the class lives in a namespace. We do
18834 this by looking for a member function; its demangled name will
18835 contain namespace info, if there is any. */
18838 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18839 struct dwarf2_cu
*cu
)
18841 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18842 what template types look like, because the demangler
18843 frequently doesn't give the same name as the debug info. We
18844 could fix this by only using the demangled name to get the
18845 prefix (but see comment in read_structure_type). */
18847 struct partial_die_info
*real_pdi
;
18848 struct partial_die_info
*child_pdi
;
18850 /* If this DIE (this DIE's specification, if any) has a parent, then
18851 we should not do this. We'll prepend the parent's fully qualified
18852 name when we create the partial symbol. */
18854 real_pdi
= struct_pdi
;
18855 while (real_pdi
->has_specification
)
18857 auto res
= find_partial_die (real_pdi
->spec_offset
,
18858 real_pdi
->spec_is_dwz
, cu
);
18859 real_pdi
= res
.pdi
;
18863 if (real_pdi
->die_parent
!= NULL
)
18866 for (child_pdi
= struct_pdi
->die_child
;
18868 child_pdi
= child_pdi
->die_sibling
)
18870 if (child_pdi
->tag
== DW_TAG_subprogram
18871 && child_pdi
->linkage_name
!= NULL
)
18873 gdb::unique_xmalloc_ptr
<char> actual_class_name
18874 (cu
->language_defn
->class_name_from_physname
18875 (child_pdi
->linkage_name
));
18876 if (actual_class_name
!= NULL
)
18878 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18879 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
18880 struct_pdi
->canonical_name
= 1;
18887 /* Return true if a DIE with TAG may have the DW_AT_const_value
18891 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18895 case DW_TAG_constant
:
18896 case DW_TAG_enumerator
:
18897 case DW_TAG_formal_parameter
:
18898 case DW_TAG_template_value_param
:
18899 case DW_TAG_variable
:
18907 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18909 /* Once we've fixed up a die, there's no point in doing so again.
18910 This also avoids a memory leak if we were to call
18911 guess_partial_die_structure_name multiple times. */
18915 /* If we found a reference attribute and the DIE has no name, try
18916 to find a name in the referred to DIE. */
18918 if (raw_name
== NULL
&& has_specification
)
18920 struct partial_die_info
*spec_die
;
18922 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18923 spec_die
= res
.pdi
;
18926 spec_die
->fixup (cu
);
18928 if (spec_die
->raw_name
)
18930 raw_name
= spec_die
->raw_name
;
18931 canonical_name
= spec_die
->canonical_name
;
18933 /* Copy DW_AT_external attribute if it is set. */
18934 if (spec_die
->is_external
)
18935 is_external
= spec_die
->is_external
;
18939 if (!has_const_value
&& has_specification
18940 && can_have_DW_AT_const_value_p (tag
))
18942 struct partial_die_info
*spec_die
;
18944 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18945 spec_die
= res
.pdi
;
18948 spec_die
->fixup (cu
);
18950 if (spec_die
->has_const_value
)
18952 /* Copy DW_AT_const_value attribute if it is set. */
18953 has_const_value
= spec_die
->has_const_value
;
18957 /* Set default names for some unnamed DIEs. */
18959 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
18961 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
18962 canonical_name
= 1;
18965 /* If there is no parent die to provide a namespace, and there are
18966 children, see if we can determine the namespace from their linkage
18968 if (cu
->language
== language_cplus
18969 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18970 && die_parent
== NULL
18972 && (tag
== DW_TAG_class_type
18973 || tag
== DW_TAG_structure_type
18974 || tag
== DW_TAG_union_type
))
18975 guess_partial_die_structure_name (this, cu
);
18977 /* GCC might emit a nameless struct or union that has a linkage
18978 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18979 if (raw_name
== NULL
18980 && (tag
== DW_TAG_class_type
18981 || tag
== DW_TAG_interface_type
18982 || tag
== DW_TAG_structure_type
18983 || tag
== DW_TAG_union_type
)
18984 && linkage_name
!= NULL
)
18986 gdb::unique_xmalloc_ptr
<char> demangled
18987 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18988 if (demangled
!= nullptr)
18992 /* Strip any leading namespaces/classes, keep only the base name.
18993 DW_AT_name for named DIEs does not contain the prefixes. */
18994 base
= strrchr (demangled
.get (), ':');
18995 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18998 base
= demangled
.get ();
19000 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19001 raw_name
= objfile
->intern (base
);
19002 canonical_name
= 1;
19009 /* Read the .debug_loclists header contents from the given SECTION in the
19012 read_loclist_header (struct loclist_header
*header
,
19013 struct dwarf2_section_info
*section
)
19015 unsigned int bytes_read
;
19016 bfd
*abfd
= section
->get_bfd_owner ();
19017 const gdb_byte
*info_ptr
= section
->buffer
;
19018 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19019 info_ptr
+= bytes_read
;
19020 header
->version
= read_2_bytes (abfd
, info_ptr
);
19022 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19024 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19026 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19029 /* Return the DW_AT_loclists_base value for the CU. */
19031 lookup_loclist_base (struct dwarf2_cu
*cu
)
19033 /* For the .dwo unit, the loclist_base points to the first offset following
19034 the header. The header consists of the following entities-
19035 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19037 2. version (2 bytes)
19038 3. address size (1 byte)
19039 4. segment selector size (1 byte)
19040 5. offset entry count (4 bytes)
19041 These sizes are derived as per the DWARFv5 standard. */
19042 if (cu
->dwo_unit
!= nullptr)
19044 if (cu
->header
.initial_length_size
== 4)
19045 return LOCLIST_HEADER_SIZE32
;
19046 return LOCLIST_HEADER_SIZE64
;
19048 return cu
->loclist_base
;
19051 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19052 array of offsets in the .debug_loclists section. */
19054 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19056 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19057 struct objfile
*objfile
= per_objfile
->objfile
;
19058 bfd
*abfd
= objfile
->obfd
;
19059 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19060 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19062 section
->read (objfile
);
19063 if (section
->buffer
== NULL
)
19064 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19065 "section [in module %s]"), objfile_name (objfile
));
19066 struct loclist_header header
;
19067 read_loclist_header (&header
, section
);
19068 if (loclist_index
>= header
.offset_entry_count
)
19069 complaint (_("DW_FORM_loclistx pointing outside of "
19070 ".debug_loclists offset array [in module %s]"),
19071 objfile_name (objfile
));
19072 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19074 complaint (_("DW_FORM_loclistx pointing outside of "
19075 ".debug_loclists section [in module %s]"),
19076 objfile_name (objfile
));
19077 const gdb_byte
*info_ptr
19078 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19080 if (cu
->header
.offset_size
== 4)
19081 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19083 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19086 /* Process the attributes that had to be skipped in the first round. These
19087 attributes are the ones that need str_offsets_base or addr_base attributes.
19088 They could not have been processed in the first round, because at the time
19089 the values of str_offsets_base or addr_base may not have been known. */
19091 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19092 struct attribute
*attr
)
19094 struct dwarf2_cu
*cu
= reader
->cu
;
19095 switch (attr
->form
)
19097 case DW_FORM_addrx
:
19098 case DW_FORM_GNU_addr_index
:
19099 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19101 case DW_FORM_loclistx
:
19102 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19105 case DW_FORM_strx1
:
19106 case DW_FORM_strx2
:
19107 case DW_FORM_strx3
:
19108 case DW_FORM_strx4
:
19109 case DW_FORM_GNU_str_index
:
19111 unsigned int str_index
= DW_UNSND (attr
);
19112 if (reader
->dwo_file
!= NULL
)
19114 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19115 DW_STRING_IS_CANONICAL (attr
) = 0;
19119 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19120 DW_STRING_IS_CANONICAL (attr
) = 0;
19125 gdb_assert_not_reached (_("Unexpected DWARF form."));
19129 /* Read an attribute value described by an attribute form. */
19131 static const gdb_byte
*
19132 read_attribute_value (const struct die_reader_specs
*reader
,
19133 struct attribute
*attr
, unsigned form
,
19134 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19135 bool *need_reprocess
)
19137 struct dwarf2_cu
*cu
= reader
->cu
;
19138 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19139 struct objfile
*objfile
= per_objfile
->objfile
;
19140 bfd
*abfd
= reader
->abfd
;
19141 struct comp_unit_head
*cu_header
= &cu
->header
;
19142 unsigned int bytes_read
;
19143 struct dwarf_block
*blk
;
19144 *need_reprocess
= false;
19146 attr
->form
= (enum dwarf_form
) form
;
19149 case DW_FORM_ref_addr
:
19150 if (cu
->header
.version
== 2)
19151 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19154 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19156 info_ptr
+= bytes_read
;
19158 case DW_FORM_GNU_ref_alt
:
19159 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19160 info_ptr
+= bytes_read
;
19164 struct gdbarch
*gdbarch
= objfile
->arch ();
19165 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19166 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19167 info_ptr
+= bytes_read
;
19170 case DW_FORM_block2
:
19171 blk
= dwarf_alloc_block (cu
);
19172 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19174 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19175 info_ptr
+= blk
->size
;
19176 DW_BLOCK (attr
) = blk
;
19178 case DW_FORM_block4
:
19179 blk
= dwarf_alloc_block (cu
);
19180 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19182 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19183 info_ptr
+= blk
->size
;
19184 DW_BLOCK (attr
) = blk
;
19186 case DW_FORM_data2
:
19187 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19190 case DW_FORM_data4
:
19191 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19194 case DW_FORM_data8
:
19195 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19198 case DW_FORM_data16
:
19199 blk
= dwarf_alloc_block (cu
);
19201 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19203 DW_BLOCK (attr
) = blk
;
19205 case DW_FORM_sec_offset
:
19206 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19207 info_ptr
+= bytes_read
;
19209 case DW_FORM_loclistx
:
19211 *need_reprocess
= true;
19212 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19213 info_ptr
+= bytes_read
;
19216 case DW_FORM_string
:
19217 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19218 DW_STRING_IS_CANONICAL (attr
) = 0;
19219 info_ptr
+= bytes_read
;
19222 if (!cu
->per_cu
->is_dwz
)
19224 DW_STRING (attr
) = read_indirect_string (per_objfile
,
19225 abfd
, info_ptr
, cu_header
,
19227 DW_STRING_IS_CANONICAL (attr
) = 0;
19228 info_ptr
+= bytes_read
;
19232 case DW_FORM_line_strp
:
19233 if (!cu
->per_cu
->is_dwz
)
19235 DW_STRING (attr
) = per_objfile
->read_line_string (info_ptr
, cu_header
,
19237 DW_STRING_IS_CANONICAL (attr
) = 0;
19238 info_ptr
+= bytes_read
;
19242 case DW_FORM_GNU_strp_alt
:
19244 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19245 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19248 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19249 DW_STRING_IS_CANONICAL (attr
) = 0;
19250 info_ptr
+= bytes_read
;
19253 case DW_FORM_exprloc
:
19254 case DW_FORM_block
:
19255 blk
= dwarf_alloc_block (cu
);
19256 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19257 info_ptr
+= bytes_read
;
19258 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19259 info_ptr
+= blk
->size
;
19260 DW_BLOCK (attr
) = blk
;
19262 case DW_FORM_block1
:
19263 blk
= dwarf_alloc_block (cu
);
19264 blk
->size
= read_1_byte (abfd
, info_ptr
);
19266 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19267 info_ptr
+= blk
->size
;
19268 DW_BLOCK (attr
) = blk
;
19270 case DW_FORM_data1
:
19271 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19275 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19278 case DW_FORM_flag_present
:
19279 DW_UNSND (attr
) = 1;
19281 case DW_FORM_sdata
:
19282 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19283 info_ptr
+= bytes_read
;
19285 case DW_FORM_udata
:
19286 case DW_FORM_rnglistx
:
19287 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19288 info_ptr
+= bytes_read
;
19291 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19292 + read_1_byte (abfd
, info_ptr
));
19296 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19297 + read_2_bytes (abfd
, info_ptr
));
19301 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19302 + read_4_bytes (abfd
, info_ptr
));
19306 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19307 + read_8_bytes (abfd
, info_ptr
));
19310 case DW_FORM_ref_sig8
:
19311 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19314 case DW_FORM_ref_udata
:
19315 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19316 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19317 info_ptr
+= bytes_read
;
19319 case DW_FORM_indirect
:
19320 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19321 info_ptr
+= bytes_read
;
19322 if (form
== DW_FORM_implicit_const
)
19324 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19325 info_ptr
+= bytes_read
;
19327 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19328 info_ptr
, need_reprocess
);
19330 case DW_FORM_implicit_const
:
19331 DW_SND (attr
) = implicit_const
;
19333 case DW_FORM_addrx
:
19334 case DW_FORM_GNU_addr_index
:
19335 *need_reprocess
= true;
19336 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19337 info_ptr
+= bytes_read
;
19340 case DW_FORM_strx1
:
19341 case DW_FORM_strx2
:
19342 case DW_FORM_strx3
:
19343 case DW_FORM_strx4
:
19344 case DW_FORM_GNU_str_index
:
19346 ULONGEST str_index
;
19347 if (form
== DW_FORM_strx1
)
19349 str_index
= read_1_byte (abfd
, info_ptr
);
19352 else if (form
== DW_FORM_strx2
)
19354 str_index
= read_2_bytes (abfd
, info_ptr
);
19357 else if (form
== DW_FORM_strx3
)
19359 str_index
= read_3_bytes (abfd
, info_ptr
);
19362 else if (form
== DW_FORM_strx4
)
19364 str_index
= read_4_bytes (abfd
, info_ptr
);
19369 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19370 info_ptr
+= bytes_read
;
19372 *need_reprocess
= true;
19373 DW_UNSND (attr
) = str_index
;
19377 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19378 dwarf_form_name (form
),
19379 bfd_get_filename (abfd
));
19383 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19384 attr
->form
= DW_FORM_GNU_ref_alt
;
19386 /* We have seen instances where the compiler tried to emit a byte
19387 size attribute of -1 which ended up being encoded as an unsigned
19388 0xffffffff. Although 0xffffffff is technically a valid size value,
19389 an object of this size seems pretty unlikely so we can relatively
19390 safely treat these cases as if the size attribute was invalid and
19391 treat them as zero by default. */
19392 if (attr
->name
== DW_AT_byte_size
19393 && form
== DW_FORM_data4
19394 && DW_UNSND (attr
) >= 0xffffffff)
19397 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19398 hex_string (DW_UNSND (attr
)));
19399 DW_UNSND (attr
) = 0;
19405 /* Read an attribute described by an abbreviated attribute. */
19407 static const gdb_byte
*
19408 read_attribute (const struct die_reader_specs
*reader
,
19409 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19410 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19412 attr
->name
= abbrev
->name
;
19413 return read_attribute_value (reader
, attr
, abbrev
->form
,
19414 abbrev
->implicit_const
, info_ptr
,
19418 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19420 static const char *
19421 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19422 LONGEST str_offset
)
19424 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19425 str_offset
, "DW_FORM_strp");
19428 /* Return pointer to string at .debug_str offset as read from BUF.
19429 BUF is assumed to be in a compilation unit described by CU_HEADER.
19430 Return *BYTES_READ_PTR count of bytes read from BUF. */
19432 static const char *
19433 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19434 const gdb_byte
*buf
,
19435 const struct comp_unit_head
*cu_header
,
19436 unsigned int *bytes_read_ptr
)
19438 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19440 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19446 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19447 const struct comp_unit_head
*cu_header
,
19448 unsigned int *bytes_read_ptr
)
19450 bfd
*abfd
= objfile
->obfd
;
19451 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19453 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19456 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19457 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19458 ADDR_SIZE is the size of addresses from the CU header. */
19461 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
19462 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
19464 struct objfile
*objfile
= per_objfile
->objfile
;
19465 bfd
*abfd
= objfile
->obfd
;
19466 const gdb_byte
*info_ptr
;
19467 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19469 per_objfile
->per_bfd
->addr
.read (objfile
);
19470 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19471 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19472 objfile_name (objfile
));
19473 if (addr_base_or_zero
+ addr_index
* addr_size
19474 >= per_objfile
->per_bfd
->addr
.size
)
19475 error (_("DW_FORM_addr_index pointing outside of "
19476 ".debug_addr section [in module %s]"),
19477 objfile_name (objfile
));
19478 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
19479 + addr_index
* addr_size
);
19480 if (addr_size
== 4)
19481 return bfd_get_32 (abfd
, info_ptr
);
19483 return bfd_get_64 (abfd
, info_ptr
);
19486 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19489 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19491 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19492 cu
->addr_base
, cu
->header
.addr_size
);
19495 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19498 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19499 unsigned int *bytes_read
)
19501 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19502 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19504 return read_addr_index (cu
, addr_index
);
19510 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19511 dwarf2_per_objfile
*per_objfile
,
19512 unsigned int addr_index
)
19514 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
19515 gdb::optional
<ULONGEST
> addr_base
;
19518 /* We need addr_base and addr_size.
19519 If we don't have PER_CU->cu, we have to get it.
19520 Nasty, but the alternative is storing the needed info in PER_CU,
19521 which at this point doesn't seem justified: it's not clear how frequently
19522 it would get used and it would increase the size of every PER_CU.
19523 Entry points like dwarf2_per_cu_addr_size do a similar thing
19524 so we're not in uncharted territory here.
19525 Alas we need to be a bit more complicated as addr_base is contained
19528 We don't need to read the entire CU(/TU).
19529 We just need the header and top level die.
19531 IWBN to use the aging mechanism to let us lazily later discard the CU.
19532 For now we skip this optimization. */
19536 addr_base
= cu
->addr_base
;
19537 addr_size
= cu
->header
.addr_size
;
19541 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
19542 addr_base
= reader
.cu
->addr_base
;
19543 addr_size
= reader
.cu
->header
.addr_size
;
19546 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
19549 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19550 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19553 static const char *
19554 read_str_index (struct dwarf2_cu
*cu
,
19555 struct dwarf2_section_info
*str_section
,
19556 struct dwarf2_section_info
*str_offsets_section
,
19557 ULONGEST str_offsets_base
, ULONGEST str_index
)
19559 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19560 struct objfile
*objfile
= per_objfile
->objfile
;
19561 const char *objf_name
= objfile_name (objfile
);
19562 bfd
*abfd
= objfile
->obfd
;
19563 const gdb_byte
*info_ptr
;
19564 ULONGEST str_offset
;
19565 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19567 str_section
->read (objfile
);
19568 str_offsets_section
->read (objfile
);
19569 if (str_section
->buffer
== NULL
)
19570 error (_("%s used without %s section"
19571 " in CU at offset %s [in module %s]"),
19572 form_name
, str_section
->get_name (),
19573 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19574 if (str_offsets_section
->buffer
== NULL
)
19575 error (_("%s used without %s section"
19576 " in CU at offset %s [in module %s]"),
19577 form_name
, str_section
->get_name (),
19578 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19579 info_ptr
= (str_offsets_section
->buffer
19581 + str_index
* cu
->header
.offset_size
);
19582 if (cu
->header
.offset_size
== 4)
19583 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19585 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19586 if (str_offset
>= str_section
->size
)
19587 error (_("Offset from %s pointing outside of"
19588 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19589 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19590 return (const char *) (str_section
->buffer
+ str_offset
);
19593 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19595 static const char *
19596 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19598 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19599 ? reader
->cu
->header
.addr_size
: 0;
19600 return read_str_index (reader
->cu
,
19601 &reader
->dwo_file
->sections
.str
,
19602 &reader
->dwo_file
->sections
.str_offsets
,
19603 str_offsets_base
, str_index
);
19606 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19608 static const char *
19609 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19611 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19612 const char *objf_name
= objfile_name (objfile
);
19613 static const char form_name
[] = "DW_FORM_GNU_str_index";
19614 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19616 if (!cu
->str_offsets_base
.has_value ())
19617 error (_("%s used in Fission stub without %s"
19618 " in CU at offset 0x%lx [in module %s]"),
19619 form_name
, str_offsets_attr_name
,
19620 (long) cu
->header
.offset_size
, objf_name
);
19622 return read_str_index (cu
,
19623 &cu
->per_objfile
->per_bfd
->str
,
19624 &cu
->per_objfile
->per_bfd
->str_offsets
,
19625 *cu
->str_offsets_base
, str_index
);
19628 /* Return the length of an LEB128 number in BUF. */
19631 leb128_size (const gdb_byte
*buf
)
19633 const gdb_byte
*begin
= buf
;
19639 if ((byte
& 128) == 0)
19640 return buf
- begin
;
19645 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19654 cu
->language
= language_c
;
19657 case DW_LANG_C_plus_plus
:
19658 case DW_LANG_C_plus_plus_11
:
19659 case DW_LANG_C_plus_plus_14
:
19660 cu
->language
= language_cplus
;
19663 cu
->language
= language_d
;
19665 case DW_LANG_Fortran77
:
19666 case DW_LANG_Fortran90
:
19667 case DW_LANG_Fortran95
:
19668 case DW_LANG_Fortran03
:
19669 case DW_LANG_Fortran08
:
19670 cu
->language
= language_fortran
;
19673 cu
->language
= language_go
;
19675 case DW_LANG_Mips_Assembler
:
19676 cu
->language
= language_asm
;
19678 case DW_LANG_Ada83
:
19679 case DW_LANG_Ada95
:
19680 cu
->language
= language_ada
;
19682 case DW_LANG_Modula2
:
19683 cu
->language
= language_m2
;
19685 case DW_LANG_Pascal83
:
19686 cu
->language
= language_pascal
;
19689 cu
->language
= language_objc
;
19692 case DW_LANG_Rust_old
:
19693 cu
->language
= language_rust
;
19695 case DW_LANG_Cobol74
:
19696 case DW_LANG_Cobol85
:
19698 cu
->language
= language_minimal
;
19701 cu
->language_defn
= language_def (cu
->language
);
19704 /* Return the named attribute or NULL if not there. */
19706 static struct attribute
*
19707 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19712 struct attribute
*spec
= NULL
;
19714 for (i
= 0; i
< die
->num_attrs
; ++i
)
19716 if (die
->attrs
[i
].name
== name
)
19717 return &die
->attrs
[i
];
19718 if (die
->attrs
[i
].name
== DW_AT_specification
19719 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19720 spec
= &die
->attrs
[i
];
19726 die
= follow_die_ref (die
, spec
, &cu
);
19732 /* Return the string associated with a string-typed attribute, or NULL if it
19733 is either not found or is of an incorrect type. */
19735 static const char *
19736 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19738 struct attribute
*attr
;
19739 const char *str
= NULL
;
19741 attr
= dwarf2_attr (die
, name
, cu
);
19745 str
= attr
->value_as_string ();
19746 if (str
== nullptr)
19747 complaint (_("string type expected for attribute %s for "
19748 "DIE at %s in module %s"),
19749 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19750 objfile_name (cu
->per_objfile
->objfile
));
19756 /* Return the dwo name or NULL if not present. If present, it is in either
19757 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19758 static const char *
19759 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19761 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19762 if (dwo_name
== nullptr)
19763 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19767 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19768 and holds a non-zero value. This function should only be used for
19769 DW_FORM_flag or DW_FORM_flag_present attributes. */
19772 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19774 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19776 return (attr
&& DW_UNSND (attr
));
19780 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19782 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19783 which value is non-zero. However, we have to be careful with
19784 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19785 (via dwarf2_flag_true_p) follows this attribute. So we may
19786 end up accidently finding a declaration attribute that belongs
19787 to a different DIE referenced by the specification attribute,
19788 even though the given DIE does not have a declaration attribute. */
19789 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19790 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19793 /* Return the die giving the specification for DIE, if there is
19794 one. *SPEC_CU is the CU containing DIE on input, and the CU
19795 containing the return value on output. If there is no
19796 specification, but there is an abstract origin, that is
19799 static struct die_info
*
19800 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19802 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19805 if (spec_attr
== NULL
)
19806 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19808 if (spec_attr
== NULL
)
19811 return follow_die_ref (die
, spec_attr
, spec_cu
);
19814 /* Stub for free_line_header to match void * callback types. */
19817 free_line_header_voidp (void *arg
)
19819 struct line_header
*lh
= (struct line_header
*) arg
;
19824 /* A convenience function to find the proper .debug_line section for a CU. */
19826 static struct dwarf2_section_info
*
19827 get_debug_line_section (struct dwarf2_cu
*cu
)
19829 struct dwarf2_section_info
*section
;
19830 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19832 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19834 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19835 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19836 else if (cu
->per_cu
->is_dwz
)
19838 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19840 section
= &dwz
->line
;
19843 section
= &per_objfile
->per_bfd
->line
;
19848 /* Read the statement program header starting at OFFSET in
19849 .debug_line, or .debug_line.dwo. Return a pointer
19850 to a struct line_header, allocated using xmalloc.
19851 Returns NULL if there is a problem reading the header, e.g., if it
19852 has a version we don't understand.
19854 NOTE: the strings in the include directory and file name tables of
19855 the returned object point into the dwarf line section buffer,
19856 and must not be freed. */
19858 static line_header_up
19859 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19861 struct dwarf2_section_info
*section
;
19862 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19864 section
= get_debug_line_section (cu
);
19865 section
->read (per_objfile
->objfile
);
19866 if (section
->buffer
== NULL
)
19868 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19869 complaint (_("missing .debug_line.dwo section"));
19871 complaint (_("missing .debug_line section"));
19875 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19876 per_objfile
, section
, &cu
->header
);
19879 /* Subroutine of dwarf_decode_lines to simplify it.
19880 Return the file name of the psymtab for the given file_entry.
19881 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19882 If space for the result is malloc'd, *NAME_HOLDER will be set.
19883 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19885 static const char *
19886 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19887 const dwarf2_psymtab
*pst
,
19888 const char *comp_dir
,
19889 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19891 const char *include_name
= fe
.name
;
19892 const char *include_name_to_compare
= include_name
;
19893 const char *pst_filename
;
19896 const char *dir_name
= fe
.include_dir (lh
);
19898 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19899 if (!IS_ABSOLUTE_PATH (include_name
)
19900 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19902 /* Avoid creating a duplicate psymtab for PST.
19903 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19904 Before we do the comparison, however, we need to account
19905 for DIR_NAME and COMP_DIR.
19906 First prepend dir_name (if non-NULL). If we still don't
19907 have an absolute path prepend comp_dir (if non-NULL).
19908 However, the directory we record in the include-file's
19909 psymtab does not contain COMP_DIR (to match the
19910 corresponding symtab(s)).
19915 bash$ gcc -g ./hello.c
19916 include_name = "hello.c"
19918 DW_AT_comp_dir = comp_dir = "/tmp"
19919 DW_AT_name = "./hello.c"
19923 if (dir_name
!= NULL
)
19925 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19926 include_name
, (char *) NULL
));
19927 include_name
= name_holder
->get ();
19928 include_name_to_compare
= include_name
;
19930 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19932 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19933 include_name
, (char *) NULL
));
19934 include_name_to_compare
= hold_compare
.get ();
19938 pst_filename
= pst
->filename
;
19939 gdb::unique_xmalloc_ptr
<char> copied_name
;
19940 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19942 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19943 pst_filename
, (char *) NULL
));
19944 pst_filename
= copied_name
.get ();
19947 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19951 return include_name
;
19954 /* State machine to track the state of the line number program. */
19956 class lnp_state_machine
19959 /* Initialize a machine state for the start of a line number
19961 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19962 bool record_lines_p
);
19964 file_entry
*current_file ()
19966 /* lh->file_names is 0-based, but the file name numbers in the
19967 statement program are 1-based. */
19968 return m_line_header
->file_name_at (m_file
);
19971 /* Record the line in the state machine. END_SEQUENCE is true if
19972 we're processing the end of a sequence. */
19973 void record_line (bool end_sequence
);
19975 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
19976 nop-out rest of the lines in this sequence. */
19977 void check_line_address (struct dwarf2_cu
*cu
,
19978 const gdb_byte
*line_ptr
,
19979 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19981 void handle_set_discriminator (unsigned int discriminator
)
19983 m_discriminator
= discriminator
;
19984 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19987 /* Handle DW_LNE_set_address. */
19988 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19991 address
+= baseaddr
;
19992 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19995 /* Handle DW_LNS_advance_pc. */
19996 void handle_advance_pc (CORE_ADDR adjust
);
19998 /* Handle a special opcode. */
19999 void handle_special_opcode (unsigned char op_code
);
20001 /* Handle DW_LNS_advance_line. */
20002 void handle_advance_line (int line_delta
)
20004 advance_line (line_delta
);
20007 /* Handle DW_LNS_set_file. */
20008 void handle_set_file (file_name_index file
);
20010 /* Handle DW_LNS_negate_stmt. */
20011 void handle_negate_stmt ()
20013 m_is_stmt
= !m_is_stmt
;
20016 /* Handle DW_LNS_const_add_pc. */
20017 void handle_const_add_pc ();
20019 /* Handle DW_LNS_fixed_advance_pc. */
20020 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20022 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20026 /* Handle DW_LNS_copy. */
20027 void handle_copy ()
20029 record_line (false);
20030 m_discriminator
= 0;
20033 /* Handle DW_LNE_end_sequence. */
20034 void handle_end_sequence ()
20036 m_currently_recording_lines
= true;
20040 /* Advance the line by LINE_DELTA. */
20041 void advance_line (int line_delta
)
20043 m_line
+= line_delta
;
20045 if (line_delta
!= 0)
20046 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20049 struct dwarf2_cu
*m_cu
;
20051 gdbarch
*m_gdbarch
;
20053 /* True if we're recording lines.
20054 Otherwise we're building partial symtabs and are just interested in
20055 finding include files mentioned by the line number program. */
20056 bool m_record_lines_p
;
20058 /* The line number header. */
20059 line_header
*m_line_header
;
20061 /* These are part of the standard DWARF line number state machine,
20062 and initialized according to the DWARF spec. */
20064 unsigned char m_op_index
= 0;
20065 /* The line table index of the current file. */
20066 file_name_index m_file
= 1;
20067 unsigned int m_line
= 1;
20069 /* These are initialized in the constructor. */
20071 CORE_ADDR m_address
;
20073 unsigned int m_discriminator
;
20075 /* Additional bits of state we need to track. */
20077 /* The last file that we called dwarf2_start_subfile for.
20078 This is only used for TLLs. */
20079 unsigned int m_last_file
= 0;
20080 /* The last file a line number was recorded for. */
20081 struct subfile
*m_last_subfile
= NULL
;
20083 /* The address of the last line entry. */
20084 CORE_ADDR m_last_address
;
20086 /* Set to true when a previous line at the same address (using
20087 m_last_address) had m_is_stmt true. This is reset to false when a
20088 line entry at a new address (m_address different to m_last_address) is
20090 bool m_stmt_at_address
= false;
20092 /* When true, record the lines we decode. */
20093 bool m_currently_recording_lines
= false;
20095 /* The last line number that was recorded, used to coalesce
20096 consecutive entries for the same line. This can happen, for
20097 example, when discriminators are present. PR 17276. */
20098 unsigned int m_last_line
= 0;
20099 bool m_line_has_non_zero_discriminator
= false;
20103 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20105 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20106 / m_line_header
->maximum_ops_per_instruction
)
20107 * m_line_header
->minimum_instruction_length
);
20108 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20109 m_op_index
= ((m_op_index
+ adjust
)
20110 % m_line_header
->maximum_ops_per_instruction
);
20114 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20116 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20117 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20118 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20119 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20120 / m_line_header
->maximum_ops_per_instruction
)
20121 * m_line_header
->minimum_instruction_length
);
20122 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20123 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20124 % m_line_header
->maximum_ops_per_instruction
);
20126 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20127 advance_line (line_delta
);
20128 record_line (false);
20129 m_discriminator
= 0;
20133 lnp_state_machine::handle_set_file (file_name_index file
)
20137 const file_entry
*fe
= current_file ();
20139 dwarf2_debug_line_missing_file_complaint ();
20140 else if (m_record_lines_p
)
20142 const char *dir
= fe
->include_dir (m_line_header
);
20144 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20145 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20146 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20151 lnp_state_machine::handle_const_add_pc ()
20154 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20157 = (((m_op_index
+ adjust
)
20158 / m_line_header
->maximum_ops_per_instruction
)
20159 * m_line_header
->minimum_instruction_length
);
20161 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20162 m_op_index
= ((m_op_index
+ adjust
)
20163 % m_line_header
->maximum_ops_per_instruction
);
20166 /* Return non-zero if we should add LINE to the line number table.
20167 LINE is the line to add, LAST_LINE is the last line that was added,
20168 LAST_SUBFILE is the subfile for LAST_LINE.
20169 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20170 had a non-zero discriminator.
20172 We have to be careful in the presence of discriminators.
20173 E.g., for this line:
20175 for (i = 0; i < 100000; i++);
20177 clang can emit four line number entries for that one line,
20178 each with a different discriminator.
20179 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20181 However, we want gdb to coalesce all four entries into one.
20182 Otherwise the user could stepi into the middle of the line and
20183 gdb would get confused about whether the pc really was in the
20184 middle of the line.
20186 Things are further complicated by the fact that two consecutive
20187 line number entries for the same line is a heuristic used by gcc
20188 to denote the end of the prologue. So we can't just discard duplicate
20189 entries, we have to be selective about it. The heuristic we use is
20190 that we only collapse consecutive entries for the same line if at least
20191 one of those entries has a non-zero discriminator. PR 17276.
20193 Note: Addresses in the line number state machine can never go backwards
20194 within one sequence, thus this coalescing is ok. */
20197 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20198 unsigned int line
, unsigned int last_line
,
20199 int line_has_non_zero_discriminator
,
20200 struct subfile
*last_subfile
)
20202 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20204 if (line
!= last_line
)
20206 /* Same line for the same file that we've seen already.
20207 As a last check, for pr 17276, only record the line if the line
20208 has never had a non-zero discriminator. */
20209 if (!line_has_non_zero_discriminator
)
20214 /* Use the CU's builder to record line number LINE beginning at
20215 address ADDRESS in the line table of subfile SUBFILE. */
20218 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20219 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20220 struct dwarf2_cu
*cu
)
20222 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20224 if (dwarf_line_debug
)
20226 fprintf_unfiltered (gdb_stdlog
,
20227 "Recording line %u, file %s, address %s\n",
20228 line
, lbasename (subfile
->name
),
20229 paddress (gdbarch
, address
));
20233 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20236 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20237 Mark the end of a set of line number records.
20238 The arguments are the same as for dwarf_record_line_1.
20239 If SUBFILE is NULL the request is ignored. */
20242 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20243 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20245 if (subfile
== NULL
)
20248 if (dwarf_line_debug
)
20250 fprintf_unfiltered (gdb_stdlog
,
20251 "Finishing current line, file %s, address %s\n",
20252 lbasename (subfile
->name
),
20253 paddress (gdbarch
, address
));
20256 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20260 lnp_state_machine::record_line (bool end_sequence
)
20262 if (dwarf_line_debug
)
20264 fprintf_unfiltered (gdb_stdlog
,
20265 "Processing actual line %u: file %u,"
20266 " address %s, is_stmt %u, discrim %u%s\n",
20268 paddress (m_gdbarch
, m_address
),
20269 m_is_stmt
, m_discriminator
,
20270 (end_sequence
? "\t(end sequence)" : ""));
20273 file_entry
*fe
= current_file ();
20276 dwarf2_debug_line_missing_file_complaint ();
20277 /* For now we ignore lines not starting on an instruction boundary.
20278 But not when processing end_sequence for compatibility with the
20279 previous version of the code. */
20280 else if (m_op_index
== 0 || end_sequence
)
20282 fe
->included_p
= 1;
20283 if (m_record_lines_p
)
20285 /* When we switch files we insert an end maker in the first file,
20286 switch to the second file and add a new line entry. The
20287 problem is that the end marker inserted in the first file will
20288 discard any previous line entries at the same address. If the
20289 line entries in the first file are marked as is-stmt, while
20290 the new line in the second file is non-stmt, then this means
20291 the end marker will discard is-stmt lines so we can have a
20292 non-stmt line. This means that there are less addresses at
20293 which the user can insert a breakpoint.
20295 To improve this we track the last address in m_last_address,
20296 and whether we have seen an is-stmt at this address. Then
20297 when switching files, if we have seen a stmt at the current
20298 address, and we are switching to create a non-stmt line, then
20299 discard the new line. */
20301 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20302 bool ignore_this_line
20303 = (file_changed
&& !end_sequence
&& m_last_address
== m_address
20304 && !m_is_stmt
&& m_stmt_at_address
);
20306 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20308 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20309 m_currently_recording_lines
? m_cu
: nullptr);
20312 if (!end_sequence
&& !ignore_this_line
)
20314 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20316 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20317 m_line_has_non_zero_discriminator
,
20320 buildsym_compunit
*builder
= m_cu
->get_builder ();
20321 dwarf_record_line_1 (m_gdbarch
,
20322 builder
->get_current_subfile (),
20323 m_line
, m_address
, is_stmt
,
20324 m_currently_recording_lines
? m_cu
: nullptr);
20326 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20327 m_last_line
= m_line
;
20332 /* Track whether we have seen any m_is_stmt true at m_address in case we
20333 have multiple line table entries all at m_address. */
20334 if (m_last_address
!= m_address
)
20336 m_stmt_at_address
= false;
20337 m_last_address
= m_address
;
20339 m_stmt_at_address
|= m_is_stmt
;
20342 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20343 line_header
*lh
, bool record_lines_p
)
20347 m_record_lines_p
= record_lines_p
;
20348 m_line_header
= lh
;
20350 m_currently_recording_lines
= true;
20352 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20353 was a line entry for it so that the backend has a chance to adjust it
20354 and also record it in case it needs it. This is currently used by MIPS
20355 code, cf. `mips_adjust_dwarf2_line'. */
20356 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20357 m_is_stmt
= lh
->default_is_stmt
;
20358 m_discriminator
= 0;
20360 m_last_address
= m_address
;
20361 m_stmt_at_address
= false;
20365 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20366 const gdb_byte
*line_ptr
,
20367 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20369 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
20370 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
20371 located at 0x0. In this case, additionally check that if
20372 ADDRESS < UNRELOCATED_LOWPC. */
20374 if ((address
== 0 && address
< unrelocated_lowpc
)
20375 || address
== (CORE_ADDR
) -1)
20377 /* This line table is for a function which has been
20378 GCd by the linker. Ignore it. PR gdb/12528 */
20380 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20381 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20383 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20384 line_offset
, objfile_name (objfile
));
20385 m_currently_recording_lines
= false;
20386 /* Note: m_currently_recording_lines is left as false until we see
20387 DW_LNE_end_sequence. */
20391 /* Subroutine of dwarf_decode_lines to simplify it.
20392 Process the line number information in LH.
20393 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20394 program in order to set included_p for every referenced header. */
20397 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20398 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20400 const gdb_byte
*line_ptr
, *extended_end
;
20401 const gdb_byte
*line_end
;
20402 unsigned int bytes_read
, extended_len
;
20403 unsigned char op_code
, extended_op
;
20404 CORE_ADDR baseaddr
;
20405 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20406 bfd
*abfd
= objfile
->obfd
;
20407 struct gdbarch
*gdbarch
= objfile
->arch ();
20408 /* True if we're recording line info (as opposed to building partial
20409 symtabs and just interested in finding include files mentioned by
20410 the line number program). */
20411 bool record_lines_p
= !decode_for_pst_p
;
20413 baseaddr
= objfile
->text_section_offset ();
20415 line_ptr
= lh
->statement_program_start
;
20416 line_end
= lh
->statement_program_end
;
20418 /* Read the statement sequences until there's nothing left. */
20419 while (line_ptr
< line_end
)
20421 /* The DWARF line number program state machine. Reset the state
20422 machine at the start of each sequence. */
20423 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20424 bool end_sequence
= false;
20426 if (record_lines_p
)
20428 /* Start a subfile for the current file of the state
20430 const file_entry
*fe
= state_machine
.current_file ();
20433 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20436 /* Decode the table. */
20437 while (line_ptr
< line_end
&& !end_sequence
)
20439 op_code
= read_1_byte (abfd
, line_ptr
);
20442 if (op_code
>= lh
->opcode_base
)
20444 /* Special opcode. */
20445 state_machine
.handle_special_opcode (op_code
);
20447 else switch (op_code
)
20449 case DW_LNS_extended_op
:
20450 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20452 line_ptr
+= bytes_read
;
20453 extended_end
= line_ptr
+ extended_len
;
20454 extended_op
= read_1_byte (abfd
, line_ptr
);
20456 switch (extended_op
)
20458 case DW_LNE_end_sequence
:
20459 state_machine
.handle_end_sequence ();
20460 end_sequence
= true;
20462 case DW_LNE_set_address
:
20465 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20466 line_ptr
+= bytes_read
;
20468 state_machine
.check_line_address (cu
, line_ptr
,
20469 lowpc
- baseaddr
, address
);
20470 state_machine
.handle_set_address (baseaddr
, address
);
20473 case DW_LNE_define_file
:
20475 const char *cur_file
;
20476 unsigned int mod_time
, length
;
20479 cur_file
= read_direct_string (abfd
, line_ptr
,
20481 line_ptr
+= bytes_read
;
20482 dindex
= (dir_index
)
20483 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20484 line_ptr
+= bytes_read
;
20486 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20487 line_ptr
+= bytes_read
;
20489 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20490 line_ptr
+= bytes_read
;
20491 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20494 case DW_LNE_set_discriminator
:
20496 /* The discriminator is not interesting to the
20497 debugger; just ignore it. We still need to
20498 check its value though:
20499 if there are consecutive entries for the same
20500 (non-prologue) line we want to coalesce them.
20503 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20504 line_ptr
+= bytes_read
;
20506 state_machine
.handle_set_discriminator (discr
);
20510 complaint (_("mangled .debug_line section"));
20513 /* Make sure that we parsed the extended op correctly. If e.g.
20514 we expected a different address size than the producer used,
20515 we may have read the wrong number of bytes. */
20516 if (line_ptr
!= extended_end
)
20518 complaint (_("mangled .debug_line section"));
20523 state_machine
.handle_copy ();
20525 case DW_LNS_advance_pc
:
20528 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20529 line_ptr
+= bytes_read
;
20531 state_machine
.handle_advance_pc (adjust
);
20534 case DW_LNS_advance_line
:
20537 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20538 line_ptr
+= bytes_read
;
20540 state_machine
.handle_advance_line (line_delta
);
20543 case DW_LNS_set_file
:
20545 file_name_index file
20546 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20548 line_ptr
+= bytes_read
;
20550 state_machine
.handle_set_file (file
);
20553 case DW_LNS_set_column
:
20554 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20555 line_ptr
+= bytes_read
;
20557 case DW_LNS_negate_stmt
:
20558 state_machine
.handle_negate_stmt ();
20560 case DW_LNS_set_basic_block
:
20562 /* Add to the address register of the state machine the
20563 address increment value corresponding to special opcode
20564 255. I.e., this value is scaled by the minimum
20565 instruction length since special opcode 255 would have
20566 scaled the increment. */
20567 case DW_LNS_const_add_pc
:
20568 state_machine
.handle_const_add_pc ();
20570 case DW_LNS_fixed_advance_pc
:
20572 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20575 state_machine
.handle_fixed_advance_pc (addr_adj
);
20580 /* Unknown standard opcode, ignore it. */
20583 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20585 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20586 line_ptr
+= bytes_read
;
20593 dwarf2_debug_line_missing_end_sequence_complaint ();
20595 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20596 in which case we still finish recording the last line). */
20597 state_machine
.record_line (true);
20601 /* Decode the Line Number Program (LNP) for the given line_header
20602 structure and CU. The actual information extracted and the type
20603 of structures created from the LNP depends on the value of PST.
20605 1. If PST is NULL, then this procedure uses the data from the program
20606 to create all necessary symbol tables, and their linetables.
20608 2. If PST is not NULL, this procedure reads the program to determine
20609 the list of files included by the unit represented by PST, and
20610 builds all the associated partial symbol tables.
20612 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20613 It is used for relative paths in the line table.
20614 NOTE: When processing partial symtabs (pst != NULL),
20615 comp_dir == pst->dirname.
20617 NOTE: It is important that psymtabs have the same file name (via strcmp)
20618 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20619 symtab we don't use it in the name of the psymtabs we create.
20620 E.g. expand_line_sal requires this when finding psymtabs to expand.
20621 A good testcase for this is mb-inline.exp.
20623 LOWPC is the lowest address in CU (or 0 if not known).
20625 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20626 for its PC<->lines mapping information. Otherwise only the filename
20627 table is read in. */
20630 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20631 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20632 CORE_ADDR lowpc
, int decode_mapping
)
20634 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20635 const int decode_for_pst_p
= (pst
!= NULL
);
20637 if (decode_mapping
)
20638 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20640 if (decode_for_pst_p
)
20642 /* Now that we're done scanning the Line Header Program, we can
20643 create the psymtab of each included file. */
20644 for (auto &file_entry
: lh
->file_names ())
20645 if (file_entry
.included_p
== 1)
20647 gdb::unique_xmalloc_ptr
<char> name_holder
;
20648 const char *include_name
=
20649 psymtab_include_file_name (lh
, file_entry
, pst
,
20650 comp_dir
, &name_holder
);
20651 if (include_name
!= NULL
)
20652 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20657 /* Make sure a symtab is created for every file, even files
20658 which contain only variables (i.e. no code with associated
20660 buildsym_compunit
*builder
= cu
->get_builder ();
20661 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20663 for (auto &fe
: lh
->file_names ())
20665 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20666 if (builder
->get_current_subfile ()->symtab
== NULL
)
20668 builder
->get_current_subfile ()->symtab
20669 = allocate_symtab (cust
,
20670 builder
->get_current_subfile ()->name
);
20672 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20677 /* Start a subfile for DWARF. FILENAME is the name of the file and
20678 DIRNAME the name of the source directory which contains FILENAME
20679 or NULL if not known.
20680 This routine tries to keep line numbers from identical absolute and
20681 relative file names in a common subfile.
20683 Using the `list' example from the GDB testsuite, which resides in
20684 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20685 of /srcdir/list0.c yields the following debugging information for list0.c:
20687 DW_AT_name: /srcdir/list0.c
20688 DW_AT_comp_dir: /compdir
20689 files.files[0].name: list0.h
20690 files.files[0].dir: /srcdir
20691 files.files[1].name: list0.c
20692 files.files[1].dir: /srcdir
20694 The line number information for list0.c has to end up in a single
20695 subfile, so that `break /srcdir/list0.c:1' works as expected.
20696 start_subfile will ensure that this happens provided that we pass the
20697 concatenation of files.files[1].dir and files.files[1].name as the
20701 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20702 const char *dirname
)
20704 gdb::unique_xmalloc_ptr
<char> copy
;
20706 /* In order not to lose the line information directory,
20707 we concatenate it to the filename when it makes sense.
20708 Note that the Dwarf3 standard says (speaking of filenames in line
20709 information): ``The directory index is ignored for file names
20710 that represent full path names''. Thus ignoring dirname in the
20711 `else' branch below isn't an issue. */
20713 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20715 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20716 filename
= copy
.get ();
20719 cu
->get_builder ()->start_subfile (filename
);
20722 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20723 buildsym_compunit constructor. */
20725 struct compunit_symtab
*
20726 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20729 gdb_assert (m_builder
== nullptr);
20731 m_builder
.reset (new struct buildsym_compunit
20732 (this->per_objfile
->objfile
,
20733 name
, comp_dir
, language
, low_pc
));
20735 list_in_scope
= get_builder ()->get_file_symbols ();
20737 get_builder ()->record_debugformat ("DWARF 2");
20738 get_builder ()->record_producer (producer
);
20740 processing_has_namespace_info
= false;
20742 return get_builder ()->get_compunit_symtab ();
20746 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20747 struct dwarf2_cu
*cu
)
20749 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20750 struct comp_unit_head
*cu_header
= &cu
->header
;
20752 /* NOTE drow/2003-01-30: There used to be a comment and some special
20753 code here to turn a symbol with DW_AT_external and a
20754 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20755 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20756 with some versions of binutils) where shared libraries could have
20757 relocations against symbols in their debug information - the
20758 minimal symbol would have the right address, but the debug info
20759 would not. It's no longer necessary, because we will explicitly
20760 apply relocations when we read in the debug information now. */
20762 /* A DW_AT_location attribute with no contents indicates that a
20763 variable has been optimized away. */
20764 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20766 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20770 /* Handle one degenerate form of location expression specially, to
20771 preserve GDB's previous behavior when section offsets are
20772 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20773 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20775 if (attr
->form_is_block ()
20776 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20777 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20778 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20779 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20780 && (DW_BLOCK (attr
)->size
20781 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20783 unsigned int dummy
;
20785 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20786 SET_SYMBOL_VALUE_ADDRESS
20787 (sym
, cu
->header
.read_address (objfile
->obfd
,
20788 DW_BLOCK (attr
)->data
+ 1,
20791 SET_SYMBOL_VALUE_ADDRESS
20792 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20794 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20795 fixup_symbol_section (sym
, objfile
);
20796 SET_SYMBOL_VALUE_ADDRESS
20798 SYMBOL_VALUE_ADDRESS (sym
)
20799 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20803 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20804 expression evaluator, and use LOC_COMPUTED only when necessary
20805 (i.e. when the value of a register or memory location is
20806 referenced, or a thread-local block, etc.). Then again, it might
20807 not be worthwhile. I'm assuming that it isn't unless performance
20808 or memory numbers show me otherwise. */
20810 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20812 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20813 cu
->has_loclist
= true;
20816 /* Given a pointer to a DWARF information entry, figure out if we need
20817 to make a symbol table entry for it, and if so, create a new entry
20818 and return a pointer to it.
20819 If TYPE is NULL, determine symbol type from the die, otherwise
20820 used the passed type.
20821 If SPACE is not NULL, use it to hold the new symbol. If it is
20822 NULL, allocate a new symbol on the objfile's obstack. */
20824 static struct symbol
*
20825 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20826 struct symbol
*space
)
20828 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20829 struct objfile
*objfile
= per_objfile
->objfile
;
20830 struct gdbarch
*gdbarch
= objfile
->arch ();
20831 struct symbol
*sym
= NULL
;
20833 struct attribute
*attr
= NULL
;
20834 struct attribute
*attr2
= NULL
;
20835 CORE_ADDR baseaddr
;
20836 struct pending
**list_to_add
= NULL
;
20838 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20840 baseaddr
= objfile
->text_section_offset ();
20842 name
= dwarf2_name (die
, cu
);
20845 int suppress_add
= 0;
20850 sym
= new (&objfile
->objfile_obstack
) symbol
;
20851 OBJSTAT (objfile
, n_syms
++);
20853 /* Cache this symbol's name and the name's demangled form (if any). */
20854 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20855 /* Fortran does not have mangling standard and the mangling does differ
20856 between gfortran, iFort etc. */
20857 const char *physname
20858 = (cu
->language
== language_fortran
20859 ? dwarf2_full_name (name
, die
, cu
)
20860 : dwarf2_physname (name
, die
, cu
));
20861 const char *linkagename
= dw2_linkage_name (die
, cu
);
20863 if (linkagename
== nullptr || cu
->language
== language_ada
)
20864 sym
->set_linkage_name (physname
);
20867 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20868 sym
->set_linkage_name (linkagename
);
20871 /* Default assumptions.
20872 Use the passed type or decode it from the die. */
20873 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20874 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20876 SYMBOL_TYPE (sym
) = type
;
20878 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20879 attr
= dwarf2_attr (die
,
20880 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20882 if (attr
!= nullptr)
20884 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20887 attr
= dwarf2_attr (die
,
20888 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20890 if (attr
!= nullptr)
20892 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20893 struct file_entry
*fe
;
20895 if (cu
->line_header
!= NULL
)
20896 fe
= cu
->line_header
->file_name_at (file_index
);
20901 complaint (_("file index out of range"));
20903 symbol_set_symtab (sym
, fe
->symtab
);
20909 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20910 if (attr
!= nullptr)
20914 addr
= attr
->value_as_address ();
20915 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20916 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20918 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20919 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20920 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20921 add_symbol_to_list (sym
, cu
->list_in_scope
);
20923 case DW_TAG_subprogram
:
20924 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20926 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20927 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20928 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20929 || cu
->language
== language_ada
20930 || cu
->language
== language_fortran
)
20932 /* Subprograms marked external are stored as a global symbol.
20933 Ada and Fortran subprograms, whether marked external or
20934 not, are always stored as a global symbol, because we want
20935 to be able to access them globally. For instance, we want
20936 to be able to break on a nested subprogram without having
20937 to specify the context. */
20938 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20942 list_to_add
= cu
->list_in_scope
;
20945 case DW_TAG_inlined_subroutine
:
20946 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20948 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20949 SYMBOL_INLINED (sym
) = 1;
20950 list_to_add
= cu
->list_in_scope
;
20952 case DW_TAG_template_value_param
:
20954 /* Fall through. */
20955 case DW_TAG_constant
:
20956 case DW_TAG_variable
:
20957 case DW_TAG_member
:
20958 /* Compilation with minimal debug info may result in
20959 variables with missing type entries. Change the
20960 misleading `void' type to something sensible. */
20961 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20962 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20964 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20965 /* In the case of DW_TAG_member, we should only be called for
20966 static const members. */
20967 if (die
->tag
== DW_TAG_member
)
20969 /* dwarf2_add_field uses die_is_declaration,
20970 so we do the same. */
20971 gdb_assert (die_is_declaration (die
, cu
));
20974 if (attr
!= nullptr)
20976 dwarf2_const_value (attr
, sym
, cu
);
20977 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20980 if (attr2
&& (DW_UNSND (attr2
) != 0))
20981 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20983 list_to_add
= cu
->list_in_scope
;
20987 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20988 if (attr
!= nullptr)
20990 var_decode_location (attr
, sym
, cu
);
20991 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20993 /* Fortran explicitly imports any global symbols to the local
20994 scope by DW_TAG_common_block. */
20995 if (cu
->language
== language_fortran
&& die
->parent
20996 && die
->parent
->tag
== DW_TAG_common_block
)
20999 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21000 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21001 && !per_objfile
->per_bfd
->has_section_at_zero
)
21003 /* When a static variable is eliminated by the linker,
21004 the corresponding debug information is not stripped
21005 out, but the variable address is set to null;
21006 do not add such variables into symbol table. */
21008 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21010 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21011 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21012 && per_objfile
->per_bfd
->can_copy
)
21014 /* A global static variable might be subject to
21015 copy relocation. We first check for a local
21016 minsym, though, because maybe the symbol was
21017 marked hidden, in which case this would not
21019 bound_minimal_symbol found
21020 = (lookup_minimal_symbol_linkage
21021 (sym
->linkage_name (), objfile
));
21022 if (found
.minsym
!= nullptr)
21023 sym
->maybe_copied
= 1;
21026 /* A variable with DW_AT_external is never static,
21027 but it may be block-scoped. */
21029 = ((cu
->list_in_scope
21030 == cu
->get_builder ()->get_file_symbols ())
21031 ? cu
->get_builder ()->get_global_symbols ()
21032 : cu
->list_in_scope
);
21035 list_to_add
= cu
->list_in_scope
;
21039 /* We do not know the address of this symbol.
21040 If it is an external symbol and we have type information
21041 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21042 The address of the variable will then be determined from
21043 the minimal symbol table whenever the variable is
21045 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21047 /* Fortran explicitly imports any global symbols to the local
21048 scope by DW_TAG_common_block. */
21049 if (cu
->language
== language_fortran
&& die
->parent
21050 && die
->parent
->tag
== DW_TAG_common_block
)
21052 /* SYMBOL_CLASS doesn't matter here because
21053 read_common_block is going to reset it. */
21055 list_to_add
= cu
->list_in_scope
;
21057 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21058 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21060 /* A variable with DW_AT_external is never static, but it
21061 may be block-scoped. */
21063 = ((cu
->list_in_scope
21064 == cu
->get_builder ()->get_file_symbols ())
21065 ? cu
->get_builder ()->get_global_symbols ()
21066 : cu
->list_in_scope
);
21068 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21070 else if (!die_is_declaration (die
, cu
))
21072 /* Use the default LOC_OPTIMIZED_OUT class. */
21073 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21075 list_to_add
= cu
->list_in_scope
;
21079 case DW_TAG_formal_parameter
:
21081 /* If we are inside a function, mark this as an argument. If
21082 not, we might be looking at an argument to an inlined function
21083 when we do not have enough information to show inlined frames;
21084 pretend it's a local variable in that case so that the user can
21086 struct context_stack
*curr
21087 = cu
->get_builder ()->get_current_context_stack ();
21088 if (curr
!= nullptr && curr
->name
!= nullptr)
21089 SYMBOL_IS_ARGUMENT (sym
) = 1;
21090 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21091 if (attr
!= nullptr)
21093 var_decode_location (attr
, sym
, cu
);
21095 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21096 if (attr
!= nullptr)
21098 dwarf2_const_value (attr
, sym
, cu
);
21101 list_to_add
= cu
->list_in_scope
;
21104 case DW_TAG_unspecified_parameters
:
21105 /* From varargs functions; gdb doesn't seem to have any
21106 interest in this information, so just ignore it for now.
21109 case DW_TAG_template_type_param
:
21111 /* Fall through. */
21112 case DW_TAG_class_type
:
21113 case DW_TAG_interface_type
:
21114 case DW_TAG_structure_type
:
21115 case DW_TAG_union_type
:
21116 case DW_TAG_set_type
:
21117 case DW_TAG_enumeration_type
:
21118 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21119 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21122 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21123 really ever be static objects: otherwise, if you try
21124 to, say, break of a class's method and you're in a file
21125 which doesn't mention that class, it won't work unless
21126 the check for all static symbols in lookup_symbol_aux
21127 saves you. See the OtherFileClass tests in
21128 gdb.c++/namespace.exp. */
21132 buildsym_compunit
*builder
= cu
->get_builder ();
21134 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21135 && cu
->language
== language_cplus
21136 ? builder
->get_global_symbols ()
21137 : cu
->list_in_scope
);
21139 /* The semantics of C++ state that "struct foo {
21140 ... }" also defines a typedef for "foo". */
21141 if (cu
->language
== language_cplus
21142 || cu
->language
== language_ada
21143 || cu
->language
== language_d
21144 || cu
->language
== language_rust
)
21146 /* The symbol's name is already allocated along
21147 with this objfile, so we don't need to
21148 duplicate it for the type. */
21149 if (SYMBOL_TYPE (sym
)->name () == 0)
21150 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21155 case DW_TAG_typedef
:
21156 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21157 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21158 list_to_add
= cu
->list_in_scope
;
21160 case DW_TAG_base_type
:
21161 case DW_TAG_subrange_type
:
21162 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21163 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21164 list_to_add
= cu
->list_in_scope
;
21166 case DW_TAG_enumerator
:
21167 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21168 if (attr
!= nullptr)
21170 dwarf2_const_value (attr
, sym
, cu
);
21173 /* NOTE: carlton/2003-11-10: See comment above in the
21174 DW_TAG_class_type, etc. block. */
21177 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21178 && cu
->language
== language_cplus
21179 ? cu
->get_builder ()->get_global_symbols ()
21180 : cu
->list_in_scope
);
21183 case DW_TAG_imported_declaration
:
21184 case DW_TAG_namespace
:
21185 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21186 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21188 case DW_TAG_module
:
21189 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21190 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21191 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21193 case DW_TAG_common_block
:
21194 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21195 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21196 add_symbol_to_list (sym
, cu
->list_in_scope
);
21199 /* Not a tag we recognize. Hopefully we aren't processing
21200 trash data, but since we must specifically ignore things
21201 we don't recognize, there is nothing else we should do at
21203 complaint (_("unsupported tag: '%s'"),
21204 dwarf_tag_name (die
->tag
));
21210 sym
->hash_next
= objfile
->template_symbols
;
21211 objfile
->template_symbols
= sym
;
21212 list_to_add
= NULL
;
21215 if (list_to_add
!= NULL
)
21216 add_symbol_to_list (sym
, list_to_add
);
21218 /* For the benefit of old versions of GCC, check for anonymous
21219 namespaces based on the demangled name. */
21220 if (!cu
->processing_has_namespace_info
21221 && cu
->language
== language_cplus
)
21222 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21227 /* Given an attr with a DW_FORM_dataN value in host byte order,
21228 zero-extend it as appropriate for the symbol's type. The DWARF
21229 standard (v4) is not entirely clear about the meaning of using
21230 DW_FORM_dataN for a constant with a signed type, where the type is
21231 wider than the data. The conclusion of a discussion on the DWARF
21232 list was that this is unspecified. We choose to always zero-extend
21233 because that is the interpretation long in use by GCC. */
21236 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21237 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21239 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21240 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21241 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21242 LONGEST l
= DW_UNSND (attr
);
21244 if (bits
< sizeof (*value
) * 8)
21246 l
&= ((LONGEST
) 1 << bits
) - 1;
21249 else if (bits
== sizeof (*value
) * 8)
21253 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21254 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21261 /* Read a constant value from an attribute. Either set *VALUE, or if
21262 the value does not fit in *VALUE, set *BYTES - either already
21263 allocated on the objfile obstack, or newly allocated on OBSTACK,
21264 or, set *BATON, if we translated the constant to a location
21268 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21269 const char *name
, struct obstack
*obstack
,
21270 struct dwarf2_cu
*cu
,
21271 LONGEST
*value
, const gdb_byte
**bytes
,
21272 struct dwarf2_locexpr_baton
**baton
)
21274 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21275 struct objfile
*objfile
= per_objfile
->objfile
;
21276 struct comp_unit_head
*cu_header
= &cu
->header
;
21277 struct dwarf_block
*blk
;
21278 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21279 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21285 switch (attr
->form
)
21288 case DW_FORM_addrx
:
21289 case DW_FORM_GNU_addr_index
:
21293 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21294 dwarf2_const_value_length_mismatch_complaint (name
,
21295 cu_header
->addr_size
,
21296 TYPE_LENGTH (type
));
21297 /* Symbols of this form are reasonably rare, so we just
21298 piggyback on the existing location code rather than writing
21299 a new implementation of symbol_computed_ops. */
21300 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21301 (*baton
)->per_objfile
= per_objfile
;
21302 (*baton
)->per_cu
= cu
->per_cu
;
21303 gdb_assert ((*baton
)->per_cu
);
21305 (*baton
)->size
= 2 + cu_header
->addr_size
;
21306 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21307 (*baton
)->data
= data
;
21309 data
[0] = DW_OP_addr
;
21310 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21311 byte_order
, DW_ADDR (attr
));
21312 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21315 case DW_FORM_string
:
21318 case DW_FORM_GNU_str_index
:
21319 case DW_FORM_GNU_strp_alt
:
21320 /* DW_STRING is already allocated on the objfile obstack, point
21322 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21324 case DW_FORM_block1
:
21325 case DW_FORM_block2
:
21326 case DW_FORM_block4
:
21327 case DW_FORM_block
:
21328 case DW_FORM_exprloc
:
21329 case DW_FORM_data16
:
21330 blk
= DW_BLOCK (attr
);
21331 if (TYPE_LENGTH (type
) != blk
->size
)
21332 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21333 TYPE_LENGTH (type
));
21334 *bytes
= blk
->data
;
21337 /* The DW_AT_const_value attributes are supposed to carry the
21338 symbol's value "represented as it would be on the target
21339 architecture." By the time we get here, it's already been
21340 converted to host endianness, so we just need to sign- or
21341 zero-extend it as appropriate. */
21342 case DW_FORM_data1
:
21343 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21345 case DW_FORM_data2
:
21346 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21348 case DW_FORM_data4
:
21349 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21351 case DW_FORM_data8
:
21352 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21355 case DW_FORM_sdata
:
21356 case DW_FORM_implicit_const
:
21357 *value
= DW_SND (attr
);
21360 case DW_FORM_udata
:
21361 *value
= DW_UNSND (attr
);
21365 complaint (_("unsupported const value attribute form: '%s'"),
21366 dwarf_form_name (attr
->form
));
21373 /* Copy constant value from an attribute to a symbol. */
21376 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21377 struct dwarf2_cu
*cu
)
21379 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21381 const gdb_byte
*bytes
;
21382 struct dwarf2_locexpr_baton
*baton
;
21384 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21385 sym
->print_name (),
21386 &objfile
->objfile_obstack
, cu
,
21387 &value
, &bytes
, &baton
);
21391 SYMBOL_LOCATION_BATON (sym
) = baton
;
21392 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21394 else if (bytes
!= NULL
)
21396 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21397 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21401 SYMBOL_VALUE (sym
) = value
;
21402 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21406 /* Return the type of the die in question using its DW_AT_type attribute. */
21408 static struct type
*
21409 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21411 struct attribute
*type_attr
;
21413 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21416 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21417 /* A missing DW_AT_type represents a void type. */
21418 return objfile_type (objfile
)->builtin_void
;
21421 return lookup_die_type (die
, type_attr
, cu
);
21424 /* True iff CU's producer generates GNAT Ada auxiliary information
21425 that allows to find parallel types through that information instead
21426 of having to do expensive parallel lookups by type name. */
21429 need_gnat_info (struct dwarf2_cu
*cu
)
21431 /* Assume that the Ada compiler was GNAT, which always produces
21432 the auxiliary information. */
21433 return (cu
->language
== language_ada
);
21436 /* Return the auxiliary type of the die in question using its
21437 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21438 attribute is not present. */
21440 static struct type
*
21441 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21443 struct attribute
*type_attr
;
21445 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21449 return lookup_die_type (die
, type_attr
, cu
);
21452 /* If DIE has a descriptive_type attribute, then set the TYPE's
21453 descriptive type accordingly. */
21456 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21457 struct dwarf2_cu
*cu
)
21459 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21461 if (descriptive_type
)
21463 ALLOCATE_GNAT_AUX_TYPE (type
);
21464 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21468 /* Return the containing type of the die in question using its
21469 DW_AT_containing_type attribute. */
21471 static struct type
*
21472 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21474 struct attribute
*type_attr
;
21475 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21477 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21479 error (_("Dwarf Error: Problem turning containing type into gdb type "
21480 "[in module %s]"), objfile_name (objfile
));
21482 return lookup_die_type (die
, type_attr
, cu
);
21485 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21487 static struct type
*
21488 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21490 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21491 struct objfile
*objfile
= per_objfile
->objfile
;
21494 std::string message
21495 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21496 objfile_name (objfile
),
21497 sect_offset_str (cu
->header
.sect_off
),
21498 sect_offset_str (die
->sect_off
));
21499 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21501 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21504 /* Look up the type of DIE in CU using its type attribute ATTR.
21505 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21506 DW_AT_containing_type.
21507 If there is no type substitute an error marker. */
21509 static struct type
*
21510 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21511 struct dwarf2_cu
*cu
)
21513 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21514 struct objfile
*objfile
= per_objfile
->objfile
;
21515 struct type
*this_type
;
21517 gdb_assert (attr
->name
== DW_AT_type
21518 || attr
->name
== DW_AT_GNAT_descriptive_type
21519 || attr
->name
== DW_AT_containing_type
);
21521 /* First see if we have it cached. */
21523 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21525 struct dwarf2_per_cu_data
*per_cu
;
21526 sect_offset sect_off
= attr
->get_ref_die_offset ();
21528 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
21529 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
21531 else if (attr
->form_is_ref ())
21533 sect_offset sect_off
= attr
->get_ref_die_offset ();
21535 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
21537 else if (attr
->form
== DW_FORM_ref_sig8
)
21539 ULONGEST signature
= DW_SIGNATURE (attr
);
21541 return get_signatured_type (die
, signature
, cu
);
21545 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21546 " at %s [in module %s]"),
21547 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21548 objfile_name (objfile
));
21549 return build_error_marker_type (cu
, die
);
21552 /* If not cached we need to read it in. */
21554 if (this_type
== NULL
)
21556 struct die_info
*type_die
= NULL
;
21557 struct dwarf2_cu
*type_cu
= cu
;
21559 if (attr
->form_is_ref ())
21560 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21561 if (type_die
== NULL
)
21562 return build_error_marker_type (cu
, die
);
21563 /* If we find the type now, it's probably because the type came
21564 from an inter-CU reference and the type's CU got expanded before
21566 this_type
= read_type_die (type_die
, type_cu
);
21569 /* If we still don't have a type use an error marker. */
21571 if (this_type
== NULL
)
21572 return build_error_marker_type (cu
, die
);
21577 /* Return the type in DIE, CU.
21578 Returns NULL for invalid types.
21580 This first does a lookup in die_type_hash,
21581 and only reads the die in if necessary.
21583 NOTE: This can be called when reading in partial or full symbols. */
21585 static struct type
*
21586 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21588 struct type
*this_type
;
21590 this_type
= get_die_type (die
, cu
);
21594 return read_type_die_1 (die
, cu
);
21597 /* Read the type in DIE, CU.
21598 Returns NULL for invalid types. */
21600 static struct type
*
21601 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21603 struct type
*this_type
= NULL
;
21607 case DW_TAG_class_type
:
21608 case DW_TAG_interface_type
:
21609 case DW_TAG_structure_type
:
21610 case DW_TAG_union_type
:
21611 this_type
= read_structure_type (die
, cu
);
21613 case DW_TAG_enumeration_type
:
21614 this_type
= read_enumeration_type (die
, cu
);
21616 case DW_TAG_subprogram
:
21617 case DW_TAG_subroutine_type
:
21618 case DW_TAG_inlined_subroutine
:
21619 this_type
= read_subroutine_type (die
, cu
);
21621 case DW_TAG_array_type
:
21622 this_type
= read_array_type (die
, cu
);
21624 case DW_TAG_set_type
:
21625 this_type
= read_set_type (die
, cu
);
21627 case DW_TAG_pointer_type
:
21628 this_type
= read_tag_pointer_type (die
, cu
);
21630 case DW_TAG_ptr_to_member_type
:
21631 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21633 case DW_TAG_reference_type
:
21634 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21636 case DW_TAG_rvalue_reference_type
:
21637 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21639 case DW_TAG_const_type
:
21640 this_type
= read_tag_const_type (die
, cu
);
21642 case DW_TAG_volatile_type
:
21643 this_type
= read_tag_volatile_type (die
, cu
);
21645 case DW_TAG_restrict_type
:
21646 this_type
= read_tag_restrict_type (die
, cu
);
21648 case DW_TAG_string_type
:
21649 this_type
= read_tag_string_type (die
, cu
);
21651 case DW_TAG_typedef
:
21652 this_type
= read_typedef (die
, cu
);
21654 case DW_TAG_subrange_type
:
21655 this_type
= read_subrange_type (die
, cu
);
21657 case DW_TAG_base_type
:
21658 this_type
= read_base_type (die
, cu
);
21660 case DW_TAG_unspecified_type
:
21661 this_type
= read_unspecified_type (die
, cu
);
21663 case DW_TAG_namespace
:
21664 this_type
= read_namespace_type (die
, cu
);
21666 case DW_TAG_module
:
21667 this_type
= read_module_type (die
, cu
);
21669 case DW_TAG_atomic_type
:
21670 this_type
= read_tag_atomic_type (die
, cu
);
21673 complaint (_("unexpected tag in read_type_die: '%s'"),
21674 dwarf_tag_name (die
->tag
));
21681 /* See if we can figure out if the class lives in a namespace. We do
21682 this by looking for a member function; its demangled name will
21683 contain namespace info, if there is any.
21684 Return the computed name or NULL.
21685 Space for the result is allocated on the objfile's obstack.
21686 This is the full-die version of guess_partial_die_structure_name.
21687 In this case we know DIE has no useful parent. */
21689 static const char *
21690 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21692 struct die_info
*spec_die
;
21693 struct dwarf2_cu
*spec_cu
;
21694 struct die_info
*child
;
21695 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21698 spec_die
= die_specification (die
, &spec_cu
);
21699 if (spec_die
!= NULL
)
21705 for (child
= die
->child
;
21707 child
= child
->sibling
)
21709 if (child
->tag
== DW_TAG_subprogram
)
21711 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21713 if (linkage_name
!= NULL
)
21715 gdb::unique_xmalloc_ptr
<char> actual_name
21716 (cu
->language_defn
->class_name_from_physname (linkage_name
));
21717 const char *name
= NULL
;
21719 if (actual_name
!= NULL
)
21721 const char *die_name
= dwarf2_name (die
, cu
);
21723 if (die_name
!= NULL
21724 && strcmp (die_name
, actual_name
.get ()) != 0)
21726 /* Strip off the class name from the full name.
21727 We want the prefix. */
21728 int die_name_len
= strlen (die_name
);
21729 int actual_name_len
= strlen (actual_name
.get ());
21730 const char *ptr
= actual_name
.get ();
21732 /* Test for '::' as a sanity check. */
21733 if (actual_name_len
> die_name_len
+ 2
21734 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21735 name
= obstack_strndup (
21736 &objfile
->per_bfd
->storage_obstack
,
21737 ptr
, actual_name_len
- die_name_len
- 2);
21748 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21749 prefix part in such case. See
21750 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21752 static const char *
21753 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21755 struct attribute
*attr
;
21758 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21759 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21762 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21765 attr
= dw2_linkage_name_attr (die
, cu
);
21766 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21769 /* dwarf2_name had to be already called. */
21770 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21772 /* Strip the base name, keep any leading namespaces/classes. */
21773 base
= strrchr (DW_STRING (attr
), ':');
21774 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21777 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21778 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21780 &base
[-1] - DW_STRING (attr
));
21783 /* Return the name of the namespace/class that DIE is defined within,
21784 or "" if we can't tell. The caller should not xfree the result.
21786 For example, if we're within the method foo() in the following
21796 then determine_prefix on foo's die will return "N::C". */
21798 static const char *
21799 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21801 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21802 struct die_info
*parent
, *spec_die
;
21803 struct dwarf2_cu
*spec_cu
;
21804 struct type
*parent_type
;
21805 const char *retval
;
21807 if (cu
->language
!= language_cplus
21808 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21809 && cu
->language
!= language_rust
)
21812 retval
= anonymous_struct_prefix (die
, cu
);
21816 /* We have to be careful in the presence of DW_AT_specification.
21817 For example, with GCC 3.4, given the code
21821 // Definition of N::foo.
21825 then we'll have a tree of DIEs like this:
21827 1: DW_TAG_compile_unit
21828 2: DW_TAG_namespace // N
21829 3: DW_TAG_subprogram // declaration of N::foo
21830 4: DW_TAG_subprogram // definition of N::foo
21831 DW_AT_specification // refers to die #3
21833 Thus, when processing die #4, we have to pretend that we're in
21834 the context of its DW_AT_specification, namely the contex of die
21837 spec_die
= die_specification (die
, &spec_cu
);
21838 if (spec_die
== NULL
)
21839 parent
= die
->parent
;
21842 parent
= spec_die
->parent
;
21846 if (parent
== NULL
)
21848 else if (parent
->building_fullname
)
21851 const char *parent_name
;
21853 /* It has been seen on RealView 2.2 built binaries,
21854 DW_TAG_template_type_param types actually _defined_ as
21855 children of the parent class:
21858 template class <class Enum> Class{};
21859 Class<enum E> class_e;
21861 1: DW_TAG_class_type (Class)
21862 2: DW_TAG_enumeration_type (E)
21863 3: DW_TAG_enumerator (enum1:0)
21864 3: DW_TAG_enumerator (enum2:1)
21866 2: DW_TAG_template_type_param
21867 DW_AT_type DW_FORM_ref_udata (E)
21869 Besides being broken debug info, it can put GDB into an
21870 infinite loop. Consider:
21872 When we're building the full name for Class<E>, we'll start
21873 at Class, and go look over its template type parameters,
21874 finding E. We'll then try to build the full name of E, and
21875 reach here. We're now trying to build the full name of E,
21876 and look over the parent DIE for containing scope. In the
21877 broken case, if we followed the parent DIE of E, we'd again
21878 find Class, and once again go look at its template type
21879 arguments, etc., etc. Simply don't consider such parent die
21880 as source-level parent of this die (it can't be, the language
21881 doesn't allow it), and break the loop here. */
21882 name
= dwarf2_name (die
, cu
);
21883 parent_name
= dwarf2_name (parent
, cu
);
21884 complaint (_("template param type '%s' defined within parent '%s'"),
21885 name
? name
: "<unknown>",
21886 parent_name
? parent_name
: "<unknown>");
21890 switch (parent
->tag
)
21892 case DW_TAG_namespace
:
21893 parent_type
= read_type_die (parent
, cu
);
21894 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21895 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21896 Work around this problem here. */
21897 if (cu
->language
== language_cplus
21898 && strcmp (parent_type
->name (), "::") == 0)
21900 /* We give a name to even anonymous namespaces. */
21901 return parent_type
->name ();
21902 case DW_TAG_class_type
:
21903 case DW_TAG_interface_type
:
21904 case DW_TAG_structure_type
:
21905 case DW_TAG_union_type
:
21906 case DW_TAG_module
:
21907 parent_type
= read_type_die (parent
, cu
);
21908 if (parent_type
->name () != NULL
)
21909 return parent_type
->name ();
21911 /* An anonymous structure is only allowed non-static data
21912 members; no typedefs, no member functions, et cetera.
21913 So it does not need a prefix. */
21915 case DW_TAG_compile_unit
:
21916 case DW_TAG_partial_unit
:
21917 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21918 if (cu
->language
== language_cplus
21919 && !per_objfile
->per_bfd
->types
.empty ()
21920 && die
->child
!= NULL
21921 && (die
->tag
== DW_TAG_class_type
21922 || die
->tag
== DW_TAG_structure_type
21923 || die
->tag
== DW_TAG_union_type
))
21925 const char *name
= guess_full_die_structure_name (die
, cu
);
21930 case DW_TAG_subprogram
:
21931 /* Nested subroutines in Fortran get a prefix with the name
21932 of the parent's subroutine. */
21933 if (cu
->language
== language_fortran
)
21935 if ((die
->tag
== DW_TAG_subprogram
)
21936 && (dwarf2_name (parent
, cu
) != NULL
))
21937 return dwarf2_name (parent
, cu
);
21939 return determine_prefix (parent
, cu
);
21940 case DW_TAG_enumeration_type
:
21941 parent_type
= read_type_die (parent
, cu
);
21942 if (TYPE_DECLARED_CLASS (parent_type
))
21944 if (parent_type
->name () != NULL
)
21945 return parent_type
->name ();
21948 /* Fall through. */
21950 return determine_prefix (parent
, cu
);
21954 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21955 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21956 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21957 an obconcat, otherwise allocate storage for the result. The CU argument is
21958 used to determine the language and hence, the appropriate separator. */
21960 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21963 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21964 int physname
, struct dwarf2_cu
*cu
)
21966 const char *lead
= "";
21969 if (suffix
== NULL
|| suffix
[0] == '\0'
21970 || prefix
== NULL
|| prefix
[0] == '\0')
21972 else if (cu
->language
== language_d
)
21974 /* For D, the 'main' function could be defined in any module, but it
21975 should never be prefixed. */
21976 if (strcmp (suffix
, "D main") == 0)
21984 else if (cu
->language
== language_fortran
&& physname
)
21986 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21987 DW_AT_MIPS_linkage_name is preferred and used instead. */
21995 if (prefix
== NULL
)
21997 if (suffix
== NULL
)
22004 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22006 strcpy (retval
, lead
);
22007 strcat (retval
, prefix
);
22008 strcat (retval
, sep
);
22009 strcat (retval
, suffix
);
22014 /* We have an obstack. */
22015 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22019 /* Get name of a die, return NULL if not found. */
22021 static const char *
22022 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22023 struct objfile
*objfile
)
22025 if (name
&& cu
->language
== language_cplus
)
22027 gdb::unique_xmalloc_ptr
<char> canon_name
22028 = cp_canonicalize_string (name
);
22030 if (canon_name
!= nullptr)
22031 name
= objfile
->intern (canon_name
.get ());
22037 /* Get name of a die, return NULL if not found.
22038 Anonymous namespaces are converted to their magic string. */
22040 static const char *
22041 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22043 struct attribute
*attr
;
22044 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22046 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22047 if ((!attr
|| !DW_STRING (attr
))
22048 && die
->tag
!= DW_TAG_namespace
22049 && die
->tag
!= DW_TAG_class_type
22050 && die
->tag
!= DW_TAG_interface_type
22051 && die
->tag
!= DW_TAG_structure_type
22052 && die
->tag
!= DW_TAG_union_type
)
22057 case DW_TAG_compile_unit
:
22058 case DW_TAG_partial_unit
:
22059 /* Compilation units have a DW_AT_name that is a filename, not
22060 a source language identifier. */
22061 case DW_TAG_enumeration_type
:
22062 case DW_TAG_enumerator
:
22063 /* These tags always have simple identifiers already; no need
22064 to canonicalize them. */
22065 return DW_STRING (attr
);
22067 case DW_TAG_namespace
:
22068 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22069 return DW_STRING (attr
);
22070 return CP_ANONYMOUS_NAMESPACE_STR
;
22072 case DW_TAG_class_type
:
22073 case DW_TAG_interface_type
:
22074 case DW_TAG_structure_type
:
22075 case DW_TAG_union_type
:
22076 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22077 structures or unions. These were of the form "._%d" in GCC 4.1,
22078 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22079 and GCC 4.4. We work around this problem by ignoring these. */
22080 if (attr
&& DW_STRING (attr
)
22081 && (startswith (DW_STRING (attr
), "._")
22082 || startswith (DW_STRING (attr
), "<anonymous")))
22085 /* GCC might emit a nameless typedef that has a linkage name. See
22086 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22087 if (!attr
|| DW_STRING (attr
) == NULL
)
22089 attr
= dw2_linkage_name_attr (die
, cu
);
22090 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22093 /* Avoid demangling DW_STRING (attr) the second time on a second
22094 call for the same DIE. */
22095 if (!DW_STRING_IS_CANONICAL (attr
))
22097 gdb::unique_xmalloc_ptr
<char> demangled
22098 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22099 if (demangled
== nullptr)
22102 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
22103 DW_STRING_IS_CANONICAL (attr
) = 1;
22106 /* Strip any leading namespaces/classes, keep only the base name.
22107 DW_AT_name for named DIEs does not contain the prefixes. */
22108 const char *base
= strrchr (DW_STRING (attr
), ':');
22109 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22112 return DW_STRING (attr
);
22120 if (!DW_STRING_IS_CANONICAL (attr
))
22122 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22124 DW_STRING_IS_CANONICAL (attr
) = 1;
22126 return DW_STRING (attr
);
22129 /* Return the die that this die in an extension of, or NULL if there
22130 is none. *EXT_CU is the CU containing DIE on input, and the CU
22131 containing the return value on output. */
22133 static struct die_info
*
22134 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22136 struct attribute
*attr
;
22138 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22142 return follow_die_ref (die
, attr
, ext_cu
);
22146 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22150 print_spaces (indent
, f
);
22151 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22152 dwarf_tag_name (die
->tag
), die
->abbrev
,
22153 sect_offset_str (die
->sect_off
));
22155 if (die
->parent
!= NULL
)
22157 print_spaces (indent
, f
);
22158 fprintf_unfiltered (f
, " parent at offset: %s\n",
22159 sect_offset_str (die
->parent
->sect_off
));
22162 print_spaces (indent
, f
);
22163 fprintf_unfiltered (f
, " has children: %s\n",
22164 dwarf_bool_name (die
->child
!= NULL
));
22166 print_spaces (indent
, f
);
22167 fprintf_unfiltered (f
, " attributes:\n");
22169 for (i
= 0; i
< die
->num_attrs
; ++i
)
22171 print_spaces (indent
, f
);
22172 fprintf_unfiltered (f
, " %s (%s) ",
22173 dwarf_attr_name (die
->attrs
[i
].name
),
22174 dwarf_form_name (die
->attrs
[i
].form
));
22176 switch (die
->attrs
[i
].form
)
22179 case DW_FORM_addrx
:
22180 case DW_FORM_GNU_addr_index
:
22181 fprintf_unfiltered (f
, "address: ");
22182 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22184 case DW_FORM_block2
:
22185 case DW_FORM_block4
:
22186 case DW_FORM_block
:
22187 case DW_FORM_block1
:
22188 fprintf_unfiltered (f
, "block: size %s",
22189 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22191 case DW_FORM_exprloc
:
22192 fprintf_unfiltered (f
, "expression: size %s",
22193 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22195 case DW_FORM_data16
:
22196 fprintf_unfiltered (f
, "constant of 16 bytes");
22198 case DW_FORM_ref_addr
:
22199 fprintf_unfiltered (f
, "ref address: ");
22200 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22202 case DW_FORM_GNU_ref_alt
:
22203 fprintf_unfiltered (f
, "alt ref address: ");
22204 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22210 case DW_FORM_ref_udata
:
22211 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22212 (long) (DW_UNSND (&die
->attrs
[i
])));
22214 case DW_FORM_data1
:
22215 case DW_FORM_data2
:
22216 case DW_FORM_data4
:
22217 case DW_FORM_data8
:
22218 case DW_FORM_udata
:
22219 case DW_FORM_sdata
:
22220 fprintf_unfiltered (f
, "constant: %s",
22221 pulongest (DW_UNSND (&die
->attrs
[i
])));
22223 case DW_FORM_sec_offset
:
22224 fprintf_unfiltered (f
, "section offset: %s",
22225 pulongest (DW_UNSND (&die
->attrs
[i
])));
22227 case DW_FORM_ref_sig8
:
22228 fprintf_unfiltered (f
, "signature: %s",
22229 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22231 case DW_FORM_string
:
22233 case DW_FORM_line_strp
:
22235 case DW_FORM_GNU_str_index
:
22236 case DW_FORM_GNU_strp_alt
:
22237 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22238 DW_STRING (&die
->attrs
[i
])
22239 ? DW_STRING (&die
->attrs
[i
]) : "",
22240 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22243 if (DW_UNSND (&die
->attrs
[i
]))
22244 fprintf_unfiltered (f
, "flag: TRUE");
22246 fprintf_unfiltered (f
, "flag: FALSE");
22248 case DW_FORM_flag_present
:
22249 fprintf_unfiltered (f
, "flag: TRUE");
22251 case DW_FORM_indirect
:
22252 /* The reader will have reduced the indirect form to
22253 the "base form" so this form should not occur. */
22254 fprintf_unfiltered (f
,
22255 "unexpected attribute form: DW_FORM_indirect");
22257 case DW_FORM_implicit_const
:
22258 fprintf_unfiltered (f
, "constant: %s",
22259 plongest (DW_SND (&die
->attrs
[i
])));
22262 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22263 die
->attrs
[i
].form
);
22266 fprintf_unfiltered (f
, "\n");
22271 dump_die_for_error (struct die_info
*die
)
22273 dump_die_shallow (gdb_stderr
, 0, die
);
22277 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22279 int indent
= level
* 4;
22281 gdb_assert (die
!= NULL
);
22283 if (level
>= max_level
)
22286 dump_die_shallow (f
, indent
, die
);
22288 if (die
->child
!= NULL
)
22290 print_spaces (indent
, f
);
22291 fprintf_unfiltered (f
, " Children:");
22292 if (level
+ 1 < max_level
)
22294 fprintf_unfiltered (f
, "\n");
22295 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22299 fprintf_unfiltered (f
,
22300 " [not printed, max nesting level reached]\n");
22304 if (die
->sibling
!= NULL
&& level
> 0)
22306 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22310 /* This is called from the pdie macro in gdbinit.in.
22311 It's not static so gcc will keep a copy callable from gdb. */
22314 dump_die (struct die_info
*die
, int max_level
)
22316 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22320 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22324 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22325 to_underlying (die
->sect_off
),
22331 /* Follow reference or signature attribute ATTR of SRC_DIE.
22332 On entry *REF_CU is the CU of SRC_DIE.
22333 On exit *REF_CU is the CU of the result. */
22335 static struct die_info
*
22336 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22337 struct dwarf2_cu
**ref_cu
)
22339 struct die_info
*die
;
22341 if (attr
->form_is_ref ())
22342 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22343 else if (attr
->form
== DW_FORM_ref_sig8
)
22344 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22347 dump_die_for_error (src_die
);
22348 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22349 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22355 /* Follow reference OFFSET.
22356 On entry *REF_CU is the CU of the source die referencing OFFSET.
22357 On exit *REF_CU is the CU of the result.
22358 Returns NULL if OFFSET is invalid. */
22360 static struct die_info
*
22361 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22362 struct dwarf2_cu
**ref_cu
)
22364 struct die_info temp_die
;
22365 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22366 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22368 gdb_assert (cu
->per_cu
!= NULL
);
22372 if (cu
->per_cu
->is_debug_types
)
22374 /* .debug_types CUs cannot reference anything outside their CU.
22375 If they need to, they have to reference a signatured type via
22376 DW_FORM_ref_sig8. */
22377 if (!cu
->header
.offset_in_cu_p (sect_off
))
22380 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22381 || !cu
->header
.offset_in_cu_p (sect_off
))
22383 struct dwarf2_per_cu_data
*per_cu
;
22385 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22388 /* If necessary, add it to the queue and load its DIEs. */
22389 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
22390 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
22392 target_cu
= per_objfile
->get_cu (per_cu
);
22394 else if (cu
->dies
== NULL
)
22396 /* We're loading full DIEs during partial symbol reading. */
22397 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
22398 load_full_comp_unit (cu
->per_cu
, per_objfile
, false, language_minimal
);
22401 *ref_cu
= target_cu
;
22402 temp_die
.sect_off
= sect_off
;
22404 if (target_cu
!= cu
)
22405 target_cu
->ancestor
= cu
;
22407 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22409 to_underlying (sect_off
));
22412 /* Follow reference attribute ATTR of SRC_DIE.
22413 On entry *REF_CU is the CU of SRC_DIE.
22414 On exit *REF_CU is the CU of the result. */
22416 static struct die_info
*
22417 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22418 struct dwarf2_cu
**ref_cu
)
22420 sect_offset sect_off
= attr
->get_ref_die_offset ();
22421 struct dwarf2_cu
*cu
= *ref_cu
;
22422 struct die_info
*die
;
22424 die
= follow_die_offset (sect_off
,
22425 (attr
->form
== DW_FORM_GNU_ref_alt
22426 || cu
->per_cu
->is_dwz
),
22429 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22430 "at %s [in module %s]"),
22431 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22432 objfile_name (cu
->per_objfile
->objfile
));
22439 struct dwarf2_locexpr_baton
22440 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22441 dwarf2_per_cu_data
*per_cu
,
22442 dwarf2_per_objfile
*per_objfile
,
22443 CORE_ADDR (*get_frame_pc
) (void *baton
),
22444 void *baton
, bool resolve_abstract_p
)
22446 struct die_info
*die
;
22447 struct attribute
*attr
;
22448 struct dwarf2_locexpr_baton retval
;
22449 struct objfile
*objfile
= per_objfile
->objfile
;
22451 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22453 cu
= load_cu (per_cu
, per_objfile
, false);
22457 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22458 Instead just throw an error, not much else we can do. */
22459 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22460 sect_offset_str (sect_off
), objfile_name (objfile
));
22463 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22465 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22466 sect_offset_str (sect_off
), objfile_name (objfile
));
22468 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22469 if (!attr
&& resolve_abstract_p
22470 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22471 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22473 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22474 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22475 struct gdbarch
*gdbarch
= objfile
->arch ();
22477 for (const auto &cand_off
22478 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22480 struct dwarf2_cu
*cand_cu
= cu
;
22481 struct die_info
*cand
22482 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22485 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22488 CORE_ADDR pc_low
, pc_high
;
22489 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22490 if (pc_low
== ((CORE_ADDR
) -1))
22492 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22493 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22494 if (!(pc_low
<= pc
&& pc
< pc_high
))
22498 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22505 /* DWARF: "If there is no such attribute, then there is no effect.".
22506 DATA is ignored if SIZE is 0. */
22508 retval
.data
= NULL
;
22511 else if (attr
->form_is_section_offset ())
22513 struct dwarf2_loclist_baton loclist_baton
;
22514 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22517 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22519 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22521 retval
.size
= size
;
22525 if (!attr
->form_is_block ())
22526 error (_("Dwarf Error: DIE at %s referenced in module %s "
22527 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22528 sect_offset_str (sect_off
), objfile_name (objfile
));
22530 retval
.data
= DW_BLOCK (attr
)->data
;
22531 retval
.size
= DW_BLOCK (attr
)->size
;
22533 retval
.per_objfile
= per_objfile
;
22534 retval
.per_cu
= cu
->per_cu
;
22536 per_objfile
->age_comp_units ();
22543 struct dwarf2_locexpr_baton
22544 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22545 dwarf2_per_cu_data
*per_cu
,
22546 dwarf2_per_objfile
*per_objfile
,
22547 CORE_ADDR (*get_frame_pc
) (void *baton
),
22550 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22552 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22553 get_frame_pc
, baton
);
22556 /* Write a constant of a given type as target-ordered bytes into
22559 static const gdb_byte
*
22560 write_constant_as_bytes (struct obstack
*obstack
,
22561 enum bfd_endian byte_order
,
22568 *len
= TYPE_LENGTH (type
);
22569 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22570 store_unsigned_integer (result
, *len
, byte_order
, value
);
22578 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22579 dwarf2_per_cu_data
*per_cu
,
22580 dwarf2_per_objfile
*per_objfile
,
22584 struct die_info
*die
;
22585 struct attribute
*attr
;
22586 const gdb_byte
*result
= NULL
;
22589 enum bfd_endian byte_order
;
22590 struct objfile
*objfile
= per_objfile
->objfile
;
22592 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22594 cu
= load_cu (per_cu
, per_objfile
, false);
22598 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22599 Instead just throw an error, not much else we can do. */
22600 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22601 sect_offset_str (sect_off
), objfile_name (objfile
));
22604 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22606 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22607 sect_offset_str (sect_off
), objfile_name (objfile
));
22609 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22613 byte_order
= (bfd_big_endian (objfile
->obfd
)
22614 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22616 switch (attr
->form
)
22619 case DW_FORM_addrx
:
22620 case DW_FORM_GNU_addr_index
:
22624 *len
= cu
->header
.addr_size
;
22625 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22626 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22630 case DW_FORM_string
:
22633 case DW_FORM_GNU_str_index
:
22634 case DW_FORM_GNU_strp_alt
:
22635 /* DW_STRING is already allocated on the objfile obstack, point
22637 result
= (const gdb_byte
*) DW_STRING (attr
);
22638 *len
= strlen (DW_STRING (attr
));
22640 case DW_FORM_block1
:
22641 case DW_FORM_block2
:
22642 case DW_FORM_block4
:
22643 case DW_FORM_block
:
22644 case DW_FORM_exprloc
:
22645 case DW_FORM_data16
:
22646 result
= DW_BLOCK (attr
)->data
;
22647 *len
= DW_BLOCK (attr
)->size
;
22650 /* The DW_AT_const_value attributes are supposed to carry the
22651 symbol's value "represented as it would be on the target
22652 architecture." By the time we get here, it's already been
22653 converted to host endianness, so we just need to sign- or
22654 zero-extend it as appropriate. */
22655 case DW_FORM_data1
:
22656 type
= die_type (die
, cu
);
22657 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22658 if (result
== NULL
)
22659 result
= write_constant_as_bytes (obstack
, byte_order
,
22662 case DW_FORM_data2
:
22663 type
= die_type (die
, cu
);
22664 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22665 if (result
== NULL
)
22666 result
= write_constant_as_bytes (obstack
, byte_order
,
22669 case DW_FORM_data4
:
22670 type
= die_type (die
, cu
);
22671 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22672 if (result
== NULL
)
22673 result
= write_constant_as_bytes (obstack
, byte_order
,
22676 case DW_FORM_data8
:
22677 type
= die_type (die
, cu
);
22678 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22679 if (result
== NULL
)
22680 result
= write_constant_as_bytes (obstack
, byte_order
,
22684 case DW_FORM_sdata
:
22685 case DW_FORM_implicit_const
:
22686 type
= die_type (die
, cu
);
22687 result
= write_constant_as_bytes (obstack
, byte_order
,
22688 type
, DW_SND (attr
), len
);
22691 case DW_FORM_udata
:
22692 type
= die_type (die
, cu
);
22693 result
= write_constant_as_bytes (obstack
, byte_order
,
22694 type
, DW_UNSND (attr
), len
);
22698 complaint (_("unsupported const value attribute form: '%s'"),
22699 dwarf_form_name (attr
->form
));
22709 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22710 dwarf2_per_cu_data
*per_cu
,
22711 dwarf2_per_objfile
*per_objfile
)
22713 struct die_info
*die
;
22715 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22717 cu
= load_cu (per_cu
, per_objfile
, false);
22722 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22726 return die_type (die
, cu
);
22732 dwarf2_get_die_type (cu_offset die_offset
,
22733 dwarf2_per_cu_data
*per_cu
,
22734 dwarf2_per_objfile
*per_objfile
)
22736 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22737 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22740 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22741 On entry *REF_CU is the CU of SRC_DIE.
22742 On exit *REF_CU is the CU of the result.
22743 Returns NULL if the referenced DIE isn't found. */
22745 static struct die_info
*
22746 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22747 struct dwarf2_cu
**ref_cu
)
22749 struct die_info temp_die
;
22750 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22751 struct die_info
*die
;
22752 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
22755 /* While it might be nice to assert sig_type->type == NULL here,
22756 we can get here for DW_AT_imported_declaration where we need
22757 the DIE not the type. */
22759 /* If necessary, add it to the queue and load its DIEs. */
22761 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
22763 read_signatured_type (sig_type
, per_objfile
);
22765 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
22766 gdb_assert (sig_cu
!= NULL
);
22767 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22768 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22769 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22770 to_underlying (temp_die
.sect_off
));
22773 /* For .gdb_index version 7 keep track of included TUs.
22774 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22775 if (per_objfile
->per_bfd
->index_table
!= NULL
22776 && per_objfile
->per_bfd
->index_table
->version
<= 7)
22778 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22783 sig_cu
->ancestor
= cu
;
22791 /* Follow signatured type referenced by ATTR in SRC_DIE.
22792 On entry *REF_CU is the CU of SRC_DIE.
22793 On exit *REF_CU is the CU of the result.
22794 The result is the DIE of the type.
22795 If the referenced type cannot be found an error is thrown. */
22797 static struct die_info
*
22798 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22799 struct dwarf2_cu
**ref_cu
)
22801 ULONGEST signature
= DW_SIGNATURE (attr
);
22802 struct signatured_type
*sig_type
;
22803 struct die_info
*die
;
22805 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22807 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22808 /* sig_type will be NULL if the signatured type is missing from
22810 if (sig_type
== NULL
)
22812 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22813 " from DIE at %s [in module %s]"),
22814 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22815 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22818 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22821 dump_die_for_error (src_die
);
22822 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22823 " from DIE at %s [in module %s]"),
22824 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22825 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22831 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22832 reading in and processing the type unit if necessary. */
22834 static struct type
*
22835 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22836 struct dwarf2_cu
*cu
)
22838 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22839 struct signatured_type
*sig_type
;
22840 struct dwarf2_cu
*type_cu
;
22841 struct die_info
*type_die
;
22844 sig_type
= lookup_signatured_type (cu
, signature
);
22845 /* sig_type will be NULL if the signatured type is missing from
22847 if (sig_type
== NULL
)
22849 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22850 " from DIE at %s [in module %s]"),
22851 hex_string (signature
), sect_offset_str (die
->sect_off
),
22852 objfile_name (per_objfile
->objfile
));
22853 return build_error_marker_type (cu
, die
);
22856 /* If we already know the type we're done. */
22857 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
22858 if (type
!= nullptr)
22862 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22863 if (type_die
!= NULL
)
22865 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22866 is created. This is important, for example, because for c++ classes
22867 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22868 type
= read_type_die (type_die
, type_cu
);
22871 complaint (_("Dwarf Error: Cannot build signatured type %s"
22872 " referenced from DIE at %s [in module %s]"),
22873 hex_string (signature
), sect_offset_str (die
->sect_off
),
22874 objfile_name (per_objfile
->objfile
));
22875 type
= build_error_marker_type (cu
, die
);
22880 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22881 " from DIE at %s [in module %s]"),
22882 hex_string (signature
), sect_offset_str (die
->sect_off
),
22883 objfile_name (per_objfile
->objfile
));
22884 type
= build_error_marker_type (cu
, die
);
22887 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22892 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22893 reading in and processing the type unit if necessary. */
22895 static struct type
*
22896 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22897 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22899 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22900 if (attr
->form_is_ref ())
22902 struct dwarf2_cu
*type_cu
= cu
;
22903 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22905 return read_type_die (type_die
, type_cu
);
22907 else if (attr
->form
== DW_FORM_ref_sig8
)
22909 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22913 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22915 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22916 " at %s [in module %s]"),
22917 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22918 objfile_name (per_objfile
->objfile
));
22919 return build_error_marker_type (cu
, die
);
22923 /* Load the DIEs associated with type unit PER_CU into memory. */
22926 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22927 dwarf2_per_objfile
*per_objfile
)
22929 struct signatured_type
*sig_type
;
22931 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22932 gdb_assert (! per_cu
->type_unit_group_p ());
22934 /* We have the per_cu, but we need the signatured_type.
22935 Fortunately this is an easy translation. */
22936 gdb_assert (per_cu
->is_debug_types
);
22937 sig_type
= (struct signatured_type
*) per_cu
;
22939 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22941 read_signatured_type (sig_type
, per_objfile
);
22943 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22946 /* Read in a signatured type and build its CU and DIEs.
22947 If the type is a stub for the real type in a DWO file,
22948 read in the real type from the DWO file as well. */
22951 read_signatured_type (signatured_type
*sig_type
,
22952 dwarf2_per_objfile
*per_objfile
)
22954 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22956 gdb_assert (per_cu
->is_debug_types
);
22957 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22959 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22961 if (!reader
.dummy_p
)
22963 struct dwarf2_cu
*cu
= reader
.cu
;
22964 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22966 gdb_assert (cu
->die_hash
== NULL
);
22968 htab_create_alloc_ex (cu
->header
.length
/ 12,
22972 &cu
->comp_unit_obstack
,
22973 hashtab_obstack_allocate
,
22974 dummy_obstack_deallocate
);
22976 if (reader
.comp_unit_die
->has_children
)
22977 reader
.comp_unit_die
->child
22978 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22979 reader
.comp_unit_die
);
22980 cu
->dies
= reader
.comp_unit_die
;
22981 /* comp_unit_die is not stored in die_hash, no need. */
22983 /* We try not to read any attributes in this function, because
22984 not all CUs needed for references have been loaded yet, and
22985 symbol table processing isn't initialized. But we have to
22986 set the CU language, or we won't be able to build types
22987 correctly. Similarly, if we do not read the producer, we can
22988 not apply producer-specific interpretation. */
22989 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22994 sig_type
->per_cu
.tu_read
= 1;
22997 /* Decode simple location descriptions.
22998 Given a pointer to a dwarf block that defines a location, compute
22999 the location and return the value. If COMPUTED is non-null, it is
23000 set to true to indicate that decoding was successful, and false
23001 otherwise. If COMPUTED is null, then this function may emit a
23005 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23007 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23009 size_t size
= blk
->size
;
23010 const gdb_byte
*data
= blk
->data
;
23011 CORE_ADDR stack
[64];
23013 unsigned int bytes_read
, unsnd
;
23016 if (computed
!= nullptr)
23022 stack
[++stacki
] = 0;
23061 stack
[++stacki
] = op
- DW_OP_lit0
;
23096 stack
[++stacki
] = op
- DW_OP_reg0
;
23099 if (computed
== nullptr)
23100 dwarf2_complex_location_expr_complaint ();
23107 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23109 stack
[++stacki
] = unsnd
;
23112 if (computed
== nullptr)
23113 dwarf2_complex_location_expr_complaint ();
23120 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23125 case DW_OP_const1u
:
23126 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23130 case DW_OP_const1s
:
23131 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23135 case DW_OP_const2u
:
23136 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23140 case DW_OP_const2s
:
23141 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23145 case DW_OP_const4u
:
23146 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23150 case DW_OP_const4s
:
23151 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23155 case DW_OP_const8u
:
23156 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23161 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23167 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23172 stack
[stacki
+ 1] = stack
[stacki
];
23177 stack
[stacki
- 1] += stack
[stacki
];
23181 case DW_OP_plus_uconst
:
23182 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23188 stack
[stacki
- 1] -= stack
[stacki
];
23193 /* If we're not the last op, then we definitely can't encode
23194 this using GDB's address_class enum. This is valid for partial
23195 global symbols, although the variable's address will be bogus
23199 if (computed
== nullptr)
23200 dwarf2_complex_location_expr_complaint ();
23206 case DW_OP_GNU_push_tls_address
:
23207 case DW_OP_form_tls_address
:
23208 /* The top of the stack has the offset from the beginning
23209 of the thread control block at which the variable is located. */
23210 /* Nothing should follow this operator, so the top of stack would
23212 /* This is valid for partial global symbols, but the variable's
23213 address will be bogus in the psymtab. Make it always at least
23214 non-zero to not look as a variable garbage collected by linker
23215 which have DW_OP_addr 0. */
23218 if (computed
== nullptr)
23219 dwarf2_complex_location_expr_complaint ();
23226 case DW_OP_GNU_uninit
:
23227 if (computed
!= nullptr)
23232 case DW_OP_GNU_addr_index
:
23233 case DW_OP_GNU_const_index
:
23234 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23240 if (computed
== nullptr)
23242 const char *name
= get_DW_OP_name (op
);
23245 complaint (_("unsupported stack op: '%s'"),
23248 complaint (_("unsupported stack op: '%02x'"),
23252 return (stack
[stacki
]);
23255 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23256 outside of the allocated space. Also enforce minimum>0. */
23257 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23259 if (computed
== nullptr)
23260 complaint (_("location description stack overflow"));
23266 if (computed
== nullptr)
23267 complaint (_("location description stack underflow"));
23272 if (computed
!= nullptr)
23274 return (stack
[stacki
]);
23277 /* memory allocation interface */
23279 static struct dwarf_block
*
23280 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23282 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23285 static struct die_info
*
23286 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23288 struct die_info
*die
;
23289 size_t size
= sizeof (struct die_info
);
23292 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23294 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23295 memset (die
, 0, sizeof (struct die_info
));
23301 /* Macro support. */
23303 /* An overload of dwarf_decode_macros that finds the correct section
23304 and ensures it is read in before calling the other overload. */
23307 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23308 int section_is_gnu
)
23310 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23311 struct objfile
*objfile
= per_objfile
->objfile
;
23312 const struct line_header
*lh
= cu
->line_header
;
23313 unsigned int offset_size
= cu
->header
.offset_size
;
23314 struct dwarf2_section_info
*section
;
23315 const char *section_name
;
23317 if (cu
->dwo_unit
!= nullptr)
23319 if (section_is_gnu
)
23321 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23322 section_name
= ".debug_macro.dwo";
23326 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23327 section_name
= ".debug_macinfo.dwo";
23332 if (section_is_gnu
)
23334 section
= &per_objfile
->per_bfd
->macro
;
23335 section_name
= ".debug_macro";
23339 section
= &per_objfile
->per_bfd
->macinfo
;
23340 section_name
= ".debug_macinfo";
23344 section
->read (objfile
);
23345 if (section
->buffer
== nullptr)
23347 complaint (_("missing %s section"), section_name
);
23351 buildsym_compunit
*builder
= cu
->get_builder ();
23353 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23354 offset_size
, offset
, section_is_gnu
);
23357 /* Return the .debug_loc section to use for CU.
23358 For DWO files use .debug_loc.dwo. */
23360 static struct dwarf2_section_info
*
23361 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23363 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23367 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23369 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23371 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23372 : &per_objfile
->per_bfd
->loc
);
23375 /* A helper function that fills in a dwarf2_loclist_baton. */
23378 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23379 struct dwarf2_loclist_baton
*baton
,
23380 const struct attribute
*attr
)
23382 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23383 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23385 section
->read (per_objfile
->objfile
);
23387 baton
->per_objfile
= per_objfile
;
23388 baton
->per_cu
= cu
->per_cu
;
23389 gdb_assert (baton
->per_cu
);
23390 /* We don't know how long the location list is, but make sure we
23391 don't run off the edge of the section. */
23392 baton
->size
= section
->size
- DW_UNSND (attr
);
23393 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23394 if (cu
->base_address
.has_value ())
23395 baton
->base_address
= *cu
->base_address
;
23397 baton
->base_address
= 0;
23398 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23402 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23403 struct dwarf2_cu
*cu
, int is_block
)
23405 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23406 struct objfile
*objfile
= per_objfile
->objfile
;
23407 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23409 if (attr
->form_is_section_offset ()
23410 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23411 the section. If so, fall through to the complaint in the
23413 && DW_UNSND (attr
) < section
->get_size (objfile
))
23415 struct dwarf2_loclist_baton
*baton
;
23417 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23419 fill_in_loclist_baton (cu
, baton
, attr
);
23421 if (!cu
->base_address
.has_value ())
23422 complaint (_("Location list used without "
23423 "specifying the CU base address."));
23425 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23426 ? dwarf2_loclist_block_index
23427 : dwarf2_loclist_index
);
23428 SYMBOL_LOCATION_BATON (sym
) = baton
;
23432 struct dwarf2_locexpr_baton
*baton
;
23434 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23435 baton
->per_objfile
= per_objfile
;
23436 baton
->per_cu
= cu
->per_cu
;
23437 gdb_assert (baton
->per_cu
);
23439 if (attr
->form_is_block ())
23441 /* Note that we're just copying the block's data pointer
23442 here, not the actual data. We're still pointing into the
23443 info_buffer for SYM's objfile; right now we never release
23444 that buffer, but when we do clean up properly this may
23446 baton
->size
= DW_BLOCK (attr
)->size
;
23447 baton
->data
= DW_BLOCK (attr
)->data
;
23451 dwarf2_invalid_attrib_class_complaint ("location description",
23452 sym
->natural_name ());
23456 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23457 ? dwarf2_locexpr_block_index
23458 : dwarf2_locexpr_index
);
23459 SYMBOL_LOCATION_BATON (sym
) = baton
;
23465 const comp_unit_head
*
23466 dwarf2_per_cu_data::get_header () const
23468 if (!m_header_read_in
)
23470 const gdb_byte
*info_ptr
23471 = this->section
->buffer
+ to_underlying (this->sect_off
);
23473 memset (&m_header
, 0, sizeof (m_header
));
23475 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23476 rcuh_kind::COMPILE
);
23485 dwarf2_per_cu_data::addr_size () const
23487 return this->get_header ()->addr_size
;
23493 dwarf2_per_cu_data::offset_size () const
23495 return this->get_header ()->offset_size
;
23501 dwarf2_per_cu_data::ref_addr_size () const
23503 const comp_unit_head
*header
= this->get_header ();
23505 if (header
->version
== 2)
23506 return header
->addr_size
;
23508 return header
->offset_size
;
23514 dwarf2_cu::addr_type () const
23516 struct objfile
*objfile
= this->per_objfile
->objfile
;
23517 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23518 struct type
*addr_type
= lookup_pointer_type (void_type
);
23519 int addr_size
= this->per_cu
->addr_size ();
23521 if (TYPE_LENGTH (addr_type
) == addr_size
)
23524 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23528 /* A helper function for dwarf2_find_containing_comp_unit that returns
23529 the index of the result, and that searches a vector. It will
23530 return a result even if the offset in question does not actually
23531 occur in any CU. This is separate so that it can be unit
23535 dwarf2_find_containing_comp_unit
23536 (sect_offset sect_off
,
23537 unsigned int offset_in_dwz
,
23538 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23543 high
= all_comp_units
.size () - 1;
23546 struct dwarf2_per_cu_data
*mid_cu
;
23547 int mid
= low
+ (high
- low
) / 2;
23549 mid_cu
= all_comp_units
[mid
];
23550 if (mid_cu
->is_dwz
> offset_in_dwz
23551 || (mid_cu
->is_dwz
== offset_in_dwz
23552 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23557 gdb_assert (low
== high
);
23561 /* Locate the .debug_info compilation unit from CU's objfile which contains
23562 the DIE at OFFSET. Raises an error on failure. */
23564 static struct dwarf2_per_cu_data
*
23565 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23566 unsigned int offset_in_dwz
,
23567 dwarf2_per_objfile
*per_objfile
)
23569 int low
= dwarf2_find_containing_comp_unit
23570 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
23571 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
23573 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23575 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23576 error (_("Dwarf Error: could not find partial DIE containing "
23577 "offset %s [in module %s]"),
23578 sect_offset_str (sect_off
),
23579 bfd_get_filename (per_objfile
->objfile
->obfd
));
23581 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23583 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
23587 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
23588 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23589 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23590 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23597 namespace selftests
{
23598 namespace find_containing_comp_unit
{
23603 struct dwarf2_per_cu_data one
{};
23604 struct dwarf2_per_cu_data two
{};
23605 struct dwarf2_per_cu_data three
{};
23606 struct dwarf2_per_cu_data four
{};
23609 two
.sect_off
= sect_offset (one
.length
);
23614 four
.sect_off
= sect_offset (three
.length
);
23618 std::vector
<dwarf2_per_cu_data
*> units
;
23619 units
.push_back (&one
);
23620 units
.push_back (&two
);
23621 units
.push_back (&three
);
23622 units
.push_back (&four
);
23626 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23627 SELF_CHECK (units
[result
] == &one
);
23628 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23629 SELF_CHECK (units
[result
] == &one
);
23630 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23631 SELF_CHECK (units
[result
] == &two
);
23633 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23634 SELF_CHECK (units
[result
] == &three
);
23635 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23636 SELF_CHECK (units
[result
] == &three
);
23637 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23638 SELF_CHECK (units
[result
] == &four
);
23644 #endif /* GDB_SELF_TEST */
23646 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23648 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23649 dwarf2_per_objfile
*per_objfile
)
23651 per_objfile (per_objfile
),
23653 has_loclist (false),
23654 checked_producer (false),
23655 producer_is_gxx_lt_4_6 (false),
23656 producer_is_gcc_lt_4_3 (false),
23657 producer_is_icc (false),
23658 producer_is_icc_lt_14 (false),
23659 producer_is_codewarrior (false),
23660 processing_has_namespace_info (false)
23664 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23667 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23668 enum language pretend_language
)
23670 struct attribute
*attr
;
23672 /* Set the language we're debugging. */
23673 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23674 if (attr
!= nullptr)
23675 set_cu_language (DW_UNSND (attr
), cu
);
23678 cu
->language
= pretend_language
;
23679 cu
->language_defn
= language_def (cu
->language
);
23682 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23688 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23690 auto it
= m_dwarf2_cus
.find (per_cu
);
23691 if (it
== m_dwarf2_cus
.end ())
23700 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23702 gdb_assert (this->get_cu (per_cu
) == nullptr);
23704 m_dwarf2_cus
[per_cu
] = cu
;
23710 dwarf2_per_objfile::age_comp_units ()
23712 /* Start by clearing all marks. */
23713 for (auto pair
: m_dwarf2_cus
)
23714 pair
.second
->mark
= false;
23716 /* Traverse all CUs, mark them and their dependencies if used recently
23718 for (auto pair
: m_dwarf2_cus
)
23720 dwarf2_cu
*cu
= pair
.second
;
23723 if (cu
->last_used
<= dwarf_max_cache_age
)
23727 /* Delete all CUs still not marked. */
23728 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23730 dwarf2_cu
*cu
= it
->second
;
23735 it
= m_dwarf2_cus
.erase (it
);
23745 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23747 auto it
= m_dwarf2_cus
.find (per_cu
);
23748 if (it
== m_dwarf2_cus
.end ())
23753 m_dwarf2_cus
.erase (it
);
23756 dwarf2_per_objfile::~dwarf2_per_objfile ()
23761 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23762 We store these in a hash table separate from the DIEs, and preserve them
23763 when the DIEs are flushed out of cache.
23765 The CU "per_cu" pointer is needed because offset alone is not enough to
23766 uniquely identify the type. A file may have multiple .debug_types sections,
23767 or the type may come from a DWO file. Furthermore, while it's more logical
23768 to use per_cu->section+offset, with Fission the section with the data is in
23769 the DWO file but we don't know that section at the point we need it.
23770 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23771 because we can enter the lookup routine, get_die_type_at_offset, from
23772 outside this file, and thus won't necessarily have PER_CU->cu.
23773 Fortunately, PER_CU is stable for the life of the objfile. */
23775 struct dwarf2_per_cu_offset_and_type
23777 const struct dwarf2_per_cu_data
*per_cu
;
23778 sect_offset sect_off
;
23782 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23785 per_cu_offset_and_type_hash (const void *item
)
23787 const struct dwarf2_per_cu_offset_and_type
*ofs
23788 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23790 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23793 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23796 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23798 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23799 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23800 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23801 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23803 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23804 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23807 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23808 table if necessary. For convenience, return TYPE.
23810 The DIEs reading must have careful ordering to:
23811 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23812 reading current DIE.
23813 * Not trying to dereference contents of still incompletely read in types
23814 while reading in other DIEs.
23815 * Enable referencing still incompletely read in types just by a pointer to
23816 the type without accessing its fields.
23818 Therefore caller should follow these rules:
23819 * Try to fetch any prerequisite types we may need to build this DIE type
23820 before building the type and calling set_die_type.
23821 * After building type call set_die_type for current DIE as soon as
23822 possible before fetching more types to complete the current type.
23823 * Make the type as complete as possible before fetching more types. */
23825 static struct type
*
23826 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23828 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23829 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23830 struct objfile
*objfile
= per_objfile
->objfile
;
23831 struct attribute
*attr
;
23832 struct dynamic_prop prop
;
23834 /* For Ada types, make sure that the gnat-specific data is always
23835 initialized (if not already set). There are a few types where
23836 we should not be doing so, because the type-specific area is
23837 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23838 where the type-specific area is used to store the floatformat).
23839 But this is not a problem, because the gnat-specific information
23840 is actually not needed for these types. */
23841 if (need_gnat_info (cu
)
23842 && type
->code () != TYPE_CODE_FUNC
23843 && type
->code () != TYPE_CODE_FLT
23844 && type
->code () != TYPE_CODE_METHODPTR
23845 && type
->code () != TYPE_CODE_MEMBERPTR
23846 && type
->code () != TYPE_CODE_METHOD
23847 && !HAVE_GNAT_AUX_INFO (type
))
23848 INIT_GNAT_SPECIFIC (type
);
23850 /* Read DW_AT_allocated and set in type. */
23851 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23854 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23855 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23856 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23859 /* Read DW_AT_associated and set in type. */
23860 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23863 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23864 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23865 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23868 /* Read DW_AT_data_location and set in type. */
23869 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23870 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23871 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23873 if (per_objfile
->die_type_hash
== NULL
)
23874 per_objfile
->die_type_hash
23875 = htab_up (htab_create_alloc (127,
23876 per_cu_offset_and_type_hash
,
23877 per_cu_offset_and_type_eq
,
23878 NULL
, xcalloc
, xfree
));
23880 ofs
.per_cu
= cu
->per_cu
;
23881 ofs
.sect_off
= die
->sect_off
;
23883 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23884 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23886 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23887 sect_offset_str (die
->sect_off
));
23888 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23889 struct dwarf2_per_cu_offset_and_type
);
23894 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23895 or return NULL if the die does not have a saved type. */
23897 static struct type
*
23898 get_die_type_at_offset (sect_offset sect_off
,
23899 dwarf2_per_cu_data
*per_cu
,
23900 dwarf2_per_objfile
*per_objfile
)
23902 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23904 if (per_objfile
->die_type_hash
== NULL
)
23907 ofs
.per_cu
= per_cu
;
23908 ofs
.sect_off
= sect_off
;
23909 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23910 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
23917 /* Look up the type for DIE in CU in die_type_hash,
23918 or return NULL if DIE does not have a saved type. */
23920 static struct type
*
23921 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23923 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23926 /* Add a dependence relationship from CU to REF_PER_CU. */
23929 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23930 struct dwarf2_per_cu_data
*ref_per_cu
)
23934 if (cu
->dependencies
== NULL
)
23936 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23937 NULL
, &cu
->comp_unit_obstack
,
23938 hashtab_obstack_allocate
,
23939 dummy_obstack_deallocate
);
23941 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23943 *slot
= ref_per_cu
;
23946 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23947 Set the mark field in every compilation unit in the
23948 cache that we must keep because we are keeping CU.
23950 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23953 dwarf2_mark_helper (void **slot
, void *data
)
23955 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23956 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23957 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23959 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23960 reading of the chain. As such dependencies remain valid it is not much
23961 useful to track and undo them during QUIT cleanups. */
23970 if (cu
->dependencies
!= nullptr)
23971 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23976 /* Set the mark field in CU and in every other compilation unit in the
23977 cache that we must keep because we are keeping CU. */
23980 dwarf2_mark (struct dwarf2_cu
*cu
)
23987 if (cu
->dependencies
!= nullptr)
23988 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
23991 /* Trivial hash function for partial_die_info: the hash value of a DIE
23992 is its offset in .debug_info for this objfile. */
23995 partial_die_hash (const void *item
)
23997 const struct partial_die_info
*part_die
23998 = (const struct partial_die_info
*) item
;
24000 return to_underlying (part_die
->sect_off
);
24003 /* Trivial comparison function for partial_die_info structures: two DIEs
24004 are equal if they have the same offset. */
24007 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24009 const struct partial_die_info
*part_die_lhs
24010 = (const struct partial_die_info
*) item_lhs
;
24011 const struct partial_die_info
*part_die_rhs
24012 = (const struct partial_die_info
*) item_rhs
;
24014 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24017 struct cmd_list_element
*set_dwarf_cmdlist
;
24018 struct cmd_list_element
*show_dwarf_cmdlist
;
24021 show_check_physname (struct ui_file
*file
, int from_tty
,
24022 struct cmd_list_element
*c
, const char *value
)
24024 fprintf_filtered (file
,
24025 _("Whether to check \"physname\" is %s.\n"),
24029 void _initialize_dwarf2_read ();
24031 _initialize_dwarf2_read ()
24033 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24034 Set DWARF specific variables.\n\
24035 Configure DWARF variables such as the cache size."),
24036 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24037 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24039 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24040 Show DWARF specific variables.\n\
24041 Show DWARF variables such as the cache size."),
24042 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24043 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24045 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24046 &dwarf_max_cache_age
, _("\
24047 Set the upper bound on the age of cached DWARF compilation units."), _("\
24048 Show the upper bound on the age of cached DWARF compilation units."), _("\
24049 A higher limit means that cached compilation units will be stored\n\
24050 in memory longer, and more total memory will be used. Zero disables\n\
24051 caching, which can slow down startup."),
24053 show_dwarf_max_cache_age
,
24054 &set_dwarf_cmdlist
,
24055 &show_dwarf_cmdlist
);
24057 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24058 Set debugging of the DWARF reader."), _("\
24059 Show debugging of the DWARF reader."), _("\
24060 When enabled (non-zero), debugging messages are printed during DWARF\n\
24061 reading and symtab expansion. A value of 1 (one) provides basic\n\
24062 information. A value greater than 1 provides more verbose information."),
24065 &setdebuglist
, &showdebuglist
);
24067 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24068 Set debugging of the DWARF DIE reader."), _("\
24069 Show debugging of the DWARF DIE reader."), _("\
24070 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24071 The value is the maximum depth to print."),
24074 &setdebuglist
, &showdebuglist
);
24076 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24077 Set debugging of the dwarf line reader."), _("\
24078 Show debugging of the dwarf line reader."), _("\
24079 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24080 A value of 1 (one) provides basic information.\n\
24081 A value greater than 1 provides more verbose information."),
24084 &setdebuglist
, &showdebuglist
);
24086 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24087 Set cross-checking of \"physname\" code against demangler."), _("\
24088 Show cross-checking of \"physname\" code against demangler."), _("\
24089 When enabled, GDB's internal \"physname\" code is checked against\n\
24091 NULL
, show_check_physname
,
24092 &setdebuglist
, &showdebuglist
);
24094 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24095 no_class
, &use_deprecated_index_sections
, _("\
24096 Set whether to use deprecated gdb_index sections."), _("\
24097 Show whether to use deprecated gdb_index sections."), _("\
24098 When enabled, deprecated .gdb_index sections are used anyway.\n\
24099 Normally they are ignored either because of a missing feature or\n\
24100 performance issue.\n\
24101 Warning: This option must be enabled before gdb reads the file."),
24104 &setlist
, &showlist
);
24106 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24107 &dwarf2_locexpr_funcs
);
24108 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24109 &dwarf2_loclist_funcs
);
24111 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24112 &dwarf2_block_frame_base_locexpr_funcs
);
24113 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24114 &dwarf2_block_frame_base_loclist_funcs
);
24117 selftests::register_test ("dw2_expand_symtabs_matching",
24118 selftests::dw2_expand_symtabs_matching::run_test
);
24119 selftests::register_test ("dwarf2_find_containing_comp_unit",
24120 selftests::find_containing_comp_unit::run_test
);