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 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
110 /* The "aclass" indices for various kinds of computed DWARF symbols. */
112 static int dwarf2_locexpr_index
;
113 static int dwarf2_loclist_index
;
114 static int dwarf2_locexpr_block_index
;
115 static int dwarf2_loclist_block_index
;
117 /* Size of .debug_loclists section header for 32-bit DWARF format. */
118 #define LOCLIST_HEADER_SIZE32 12
120 /* Size of .debug_loclists section header for 64-bit DWARF format. */
121 #define LOCLIST_HEADER_SIZE64 20
123 /* An index into a (C++) symbol name component in a symbol name as
124 recorded in the mapped_index's symbol table. For each C++ symbol
125 in the symbol table, we record one entry for the start of each
126 component in the symbol in a table of name components, and then
127 sort the table, in order to be able to binary search symbol names,
128 ignoring leading namespaces, both completion and regular look up.
129 For example, for symbol "A::B::C", we'll have an entry that points
130 to "A::B::C", another that points to "B::C", and another for "C".
131 Note that function symbols in GDB index have no parameter
132 information, just the function/method names. You can convert a
133 name_component to a "const char *" using the
134 'mapped_index::symbol_name_at(offset_type)' method. */
136 struct name_component
138 /* Offset in the symbol name where the component starts. Stored as
139 a (32-bit) offset instead of a pointer to save memory and improve
140 locality on 64-bit architectures. */
141 offset_type name_offset
;
143 /* The symbol's index in the symbol and constant pool tables of a
148 /* Base class containing bits shared by both .gdb_index and
149 .debug_name indexes. */
151 struct mapped_index_base
153 mapped_index_base () = default;
154 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
156 /* The name_component table (a sorted vector). See name_component's
157 description above. */
158 std::vector
<name_component
> name_components
;
160 /* How NAME_COMPONENTS is sorted. */
161 enum case_sensitivity name_components_casing
;
163 /* Return the number of names in the symbol table. */
164 virtual size_t symbol_name_count () const = 0;
166 /* Get the name of the symbol at IDX in the symbol table. */
167 virtual const char *symbol_name_at (offset_type idx
) const = 0;
169 /* Return whether the name at IDX in the symbol table should be
171 virtual bool symbol_name_slot_invalid (offset_type idx
) const
176 /* Build the symbol name component sorted vector, if we haven't
178 void build_name_components ();
180 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
181 possible matches for LN_NO_PARAMS in the name component
183 std::pair
<std::vector
<name_component
>::const_iterator
,
184 std::vector
<name_component
>::const_iterator
>
185 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
186 enum language lang
) const;
188 /* Prevent deleting/destroying via a base class pointer. */
190 ~mapped_index_base() = default;
193 /* A description of the mapped index. The file format is described in
194 a comment by the code that writes the index. */
195 struct mapped_index final
: public mapped_index_base
197 /* A slot/bucket in the symbol table hash. */
198 struct symbol_table_slot
200 const offset_type name
;
201 const offset_type vec
;
204 /* Index data format version. */
207 /* The address table data. */
208 gdb::array_view
<const gdb_byte
> address_table
;
210 /* The symbol table, implemented as a hash table. */
211 gdb::array_view
<symbol_table_slot
> symbol_table
;
213 /* A pointer to the constant pool. */
214 const char *constant_pool
= nullptr;
216 bool symbol_name_slot_invalid (offset_type idx
) const override
218 const auto &bucket
= this->symbol_table
[idx
];
219 return bucket
.name
== 0 && bucket
.vec
== 0;
222 /* Convenience method to get at the name of the symbol at IDX in the
224 const char *symbol_name_at (offset_type idx
) const override
225 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
227 size_t symbol_name_count () const override
228 { return this->symbol_table
.size (); }
231 /* A description of the mapped .debug_names.
232 Uninitialized map has CU_COUNT 0. */
233 struct mapped_debug_names final
: public mapped_index_base
235 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
236 : dwarf2_per_objfile (dwarf2_per_objfile_
)
239 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
240 bfd_endian dwarf5_byte_order
;
241 bool dwarf5_is_dwarf64
;
242 bool augmentation_is_gdb
;
244 uint32_t cu_count
= 0;
245 uint32_t tu_count
, bucket_count
, name_count
;
246 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
247 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
248 const gdb_byte
*name_table_string_offs_reordered
;
249 const gdb_byte
*name_table_entry_offs_reordered
;
250 const gdb_byte
*entry_pool
;
257 /* Attribute name DW_IDX_*. */
260 /* Attribute form DW_FORM_*. */
263 /* Value if FORM is DW_FORM_implicit_const. */
264 LONGEST implicit_const
;
266 std::vector
<attr
> attr_vec
;
269 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
271 const char *namei_to_name (uint32_t namei
) const;
273 /* Implementation of the mapped_index_base virtual interface, for
274 the name_components cache. */
276 const char *symbol_name_at (offset_type idx
) const override
277 { return namei_to_name (idx
); }
279 size_t symbol_name_count () const override
280 { return this->name_count
; }
283 /* See dwarf2read.h. */
286 get_dwarf2_per_objfile (struct objfile
*objfile
)
288 return dwarf2_objfile_data_key
.get (objfile
);
291 /* Default names of the debugging sections. */
293 /* Note that if the debugging section has been compressed, it might
294 have a name like .zdebug_info. */
296 static const struct dwarf2_debug_sections dwarf2_elf_names
=
298 { ".debug_info", ".zdebug_info" },
299 { ".debug_abbrev", ".zdebug_abbrev" },
300 { ".debug_line", ".zdebug_line" },
301 { ".debug_loc", ".zdebug_loc" },
302 { ".debug_loclists", ".zdebug_loclists" },
303 { ".debug_macinfo", ".zdebug_macinfo" },
304 { ".debug_macro", ".zdebug_macro" },
305 { ".debug_str", ".zdebug_str" },
306 { ".debug_str_offsets", ".zdebug_str_offsets" },
307 { ".debug_line_str", ".zdebug_line_str" },
308 { ".debug_ranges", ".zdebug_ranges" },
309 { ".debug_rnglists", ".zdebug_rnglists" },
310 { ".debug_types", ".zdebug_types" },
311 { ".debug_addr", ".zdebug_addr" },
312 { ".debug_frame", ".zdebug_frame" },
313 { ".eh_frame", NULL
},
314 { ".gdb_index", ".zgdb_index" },
315 { ".debug_names", ".zdebug_names" },
316 { ".debug_aranges", ".zdebug_aranges" },
320 /* List of DWO/DWP sections. */
322 static const struct dwop_section_names
324 struct dwarf2_section_names abbrev_dwo
;
325 struct dwarf2_section_names info_dwo
;
326 struct dwarf2_section_names line_dwo
;
327 struct dwarf2_section_names loc_dwo
;
328 struct dwarf2_section_names loclists_dwo
;
329 struct dwarf2_section_names macinfo_dwo
;
330 struct dwarf2_section_names macro_dwo
;
331 struct dwarf2_section_names str_dwo
;
332 struct dwarf2_section_names str_offsets_dwo
;
333 struct dwarf2_section_names types_dwo
;
334 struct dwarf2_section_names cu_index
;
335 struct dwarf2_section_names tu_index
;
339 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
340 { ".debug_info.dwo", ".zdebug_info.dwo" },
341 { ".debug_line.dwo", ".zdebug_line.dwo" },
342 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
343 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
344 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
345 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
346 { ".debug_str.dwo", ".zdebug_str.dwo" },
347 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
348 { ".debug_types.dwo", ".zdebug_types.dwo" },
349 { ".debug_cu_index", ".zdebug_cu_index" },
350 { ".debug_tu_index", ".zdebug_tu_index" },
353 /* local data types */
355 /* The location list section (.debug_loclists) begins with a header,
356 which contains the following information. */
357 struct loclist_header
359 /* A 4-byte or 12-byte length containing the length of the
360 set of entries for this compilation unit, not including the
361 length field itself. */
364 /* A 2-byte version identifier. */
367 /* A 1-byte unsigned integer containing the size in bytes of an address on
368 the target system. */
369 unsigned char addr_size
;
371 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
372 on the target system. */
373 unsigned char segment_collector_size
;
375 /* A 4-byte count of the number of offsets that follow the header. */
376 unsigned int offset_entry_count
;
379 /* Type used for delaying computation of method physnames.
380 See comments for compute_delayed_physnames. */
381 struct delayed_method_info
383 /* The type to which the method is attached, i.e., its parent class. */
386 /* The index of the method in the type's function fieldlists. */
389 /* The index of the method in the fieldlist. */
392 /* The name of the DIE. */
395 /* The DIE associated with this method. */
396 struct die_info
*die
;
399 /* Internal state when decoding a particular compilation unit. */
402 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
403 dwarf2_per_objfile
*per_objfile
);
405 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
407 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
408 Create the set of symtabs used by this TU, or if this TU is sharing
409 symtabs with another TU and the symtabs have already been created
410 then restore those symtabs in the line header.
411 We don't need the pc/line-number mapping for type units. */
412 void setup_type_unit_groups (struct die_info
*die
);
414 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
415 buildsym_compunit constructor. */
416 struct compunit_symtab
*start_symtab (const char *name
,
417 const char *comp_dir
,
420 /* Reset the builder. */
421 void reset_builder () { m_builder
.reset (); }
423 /* Return a type that is a generic pointer type, the size of which
424 matches the address size given in the compilation unit header for
426 struct type
*addr_type () const;
428 /* Find an integer type the same size as the address size given in
429 the compilation unit header for this CU. UNSIGNED_P controls if
430 the integer is unsigned or not. */
431 struct type
*addr_sized_int_type (bool unsigned_p
) const;
433 /* The header of the compilation unit. */
434 struct comp_unit_head header
{};
436 /* Base address of this compilation unit. */
437 gdb::optional
<CORE_ADDR
> base_address
;
439 /* The language we are debugging. */
440 enum language language
= language_unknown
;
441 const struct language_defn
*language_defn
= nullptr;
443 const char *producer
= nullptr;
446 /* The symtab builder for this CU. This is only non-NULL when full
447 symbols are being read. */
448 std::unique_ptr
<buildsym_compunit
> m_builder
;
451 /* The generic symbol table building routines have separate lists for
452 file scope symbols and all all other scopes (local scopes). So
453 we need to select the right one to pass to add_symbol_to_list().
454 We do it by keeping a pointer to the correct list in list_in_scope.
456 FIXME: The original dwarf code just treated the file scope as the
457 first local scope, and all other local scopes as nested local
458 scopes, and worked fine. Check to see if we really need to
459 distinguish these in buildsym.c. */
460 struct pending
**list_in_scope
= nullptr;
462 /* Hash table holding all the loaded partial DIEs
463 with partial_die->offset.SECT_OFF as hash. */
464 htab_t partial_dies
= nullptr;
466 /* Storage for things with the same lifetime as this read-in compilation
467 unit, including partial DIEs. */
468 auto_obstack comp_unit_obstack
;
470 /* Backlink to our per_cu entry. */
471 struct dwarf2_per_cu_data
*per_cu
;
473 /* The dwarf2_per_objfile that owns this. */
474 struct dwarf2_per_objfile
*per_objfile
;
476 /* How many compilation units ago was this CU last referenced? */
479 /* A hash table of DIE cu_offset for following references with
480 die_info->offset.sect_off as hash. */
481 htab_t die_hash
= nullptr;
483 /* Full DIEs if read in. */
484 struct die_info
*dies
= nullptr;
486 /* A set of pointers to dwarf2_per_cu_data objects for compilation
487 units referenced by this one. Only set during full symbol processing;
488 partial symbol tables do not have dependencies. */
489 htab_t dependencies
= nullptr;
491 /* Header data from the line table, during full symbol processing. */
492 struct line_header
*line_header
= nullptr;
493 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
494 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
495 this is the DW_TAG_compile_unit die for this CU. We'll hold on
496 to the line header as long as this DIE is being processed. See
497 process_die_scope. */
498 die_info
*line_header_die_owner
= nullptr;
500 /* A list of methods which need to have physnames computed
501 after all type information has been read. */
502 std::vector
<delayed_method_info
> method_list
;
504 /* To be copied to symtab->call_site_htab. */
505 htab_t call_site_htab
= nullptr;
507 /* Non-NULL if this CU came from a DWO file.
508 There is an invariant here that is important to remember:
509 Except for attributes copied from the top level DIE in the "main"
510 (or "stub") file in preparation for reading the DWO file
511 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
512 Either there isn't a DWO file (in which case this is NULL and the point
513 is moot), or there is and either we're not going to read it (in which
514 case this is NULL) or there is and we are reading it (in which case this
516 struct dwo_unit
*dwo_unit
= nullptr;
518 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
519 Note this value comes from the Fission stub CU/TU's DIE. */
520 gdb::optional
<ULONGEST
> addr_base
;
522 /* The DW_AT_rnglists_base attribute if present.
523 Note this value comes from the Fission stub CU/TU's DIE.
524 Also note that the value is zero in the non-DWO case so this value can
525 be used without needing to know whether DWO files are in use or not.
526 N.B. This does not apply to DW_AT_ranges appearing in
527 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
528 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
529 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
530 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
531 ULONGEST ranges_base
= 0;
533 /* The DW_AT_loclists_base attribute if present. */
534 ULONGEST loclist_base
= 0;
536 /* When reading debug info generated by older versions of rustc, we
537 have to rewrite some union types to be struct types with a
538 variant part. This rewriting must be done after the CU is fully
539 read in, because otherwise at the point of rewriting some struct
540 type might not have been fully processed. So, we keep a list of
541 all such types here and process them after expansion. */
542 std::vector
<struct type
*> rust_unions
;
544 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
545 files, the value is implicitly zero. For DWARF 5 version DWO files, the
546 value is often implicit and is the size of the header of
547 .debug_str_offsets section (8 or 4, depending on the address size). */
548 gdb::optional
<ULONGEST
> str_offsets_base
;
550 /* Mark used when releasing cached dies. */
553 /* This CU references .debug_loc. See the symtab->locations_valid field.
554 This test is imperfect as there may exist optimized debug code not using
555 any location list and still facing inlining issues if handled as
556 unoptimized code. For a future better test see GCC PR other/32998. */
557 bool has_loclist
: 1;
559 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
560 if all the producer_is_* fields are valid. This information is cached
561 because profiling CU expansion showed excessive time spent in
562 producer_is_gxx_lt_4_6. */
563 bool checked_producer
: 1;
564 bool producer_is_gxx_lt_4_6
: 1;
565 bool producer_is_gcc_lt_4_3
: 1;
566 bool producer_is_icc
: 1;
567 bool producer_is_icc_lt_14
: 1;
568 bool producer_is_codewarrior
: 1;
570 /* When true, the file that we're processing is known to have
571 debugging info for C++ namespaces. GCC 3.3.x did not produce
572 this information, but later versions do. */
574 bool processing_has_namespace_info
: 1;
576 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
578 /* If this CU was inherited by another CU (via specification,
579 abstract_origin, etc), this is the ancestor CU. */
582 /* Get the buildsym_compunit for this CU. */
583 buildsym_compunit
*get_builder ()
585 /* If this CU has a builder associated with it, use that. */
586 if (m_builder
!= nullptr)
587 return m_builder
.get ();
589 /* Otherwise, search ancestors for a valid builder. */
590 if (ancestor
!= nullptr)
591 return ancestor
->get_builder ();
597 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
598 This includes type_unit_group and quick_file_names. */
600 struct stmt_list_hash
602 /* The DWO unit this table is from or NULL if there is none. */
603 struct dwo_unit
*dwo_unit
;
605 /* Offset in .debug_line or .debug_line.dwo. */
606 sect_offset line_sect_off
;
609 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
610 an object of this type. This contains elements of type unit groups
611 that can be shared across objfiles. The non-shareable parts are in
612 type_unit_group_unshareable. */
614 struct type_unit_group
616 /* dwarf2read.c's main "handle" on a TU symtab.
617 To simplify things we create an artificial CU that "includes" all the
618 type units using this stmt_list so that the rest of the code still has
619 a "per_cu" handle on the symtab. */
620 struct dwarf2_per_cu_data per_cu
;
622 /* The TUs that share this DW_AT_stmt_list entry.
623 This is added to while parsing type units to build partial symtabs,
624 and is deleted afterwards and not used again. */
625 std::vector
<signatured_type
*> *tus
;
627 /* The data used to construct the hash key. */
628 struct stmt_list_hash hash
;
631 /* These sections are what may appear in a (real or virtual) DWO file. */
635 struct dwarf2_section_info abbrev
;
636 struct dwarf2_section_info line
;
637 struct dwarf2_section_info loc
;
638 struct dwarf2_section_info loclists
;
639 struct dwarf2_section_info macinfo
;
640 struct dwarf2_section_info macro
;
641 struct dwarf2_section_info str
;
642 struct dwarf2_section_info str_offsets
;
643 /* In the case of a virtual DWO file, these two are unused. */
644 struct dwarf2_section_info info
;
645 std::vector
<dwarf2_section_info
> types
;
648 /* CUs/TUs in DWP/DWO files. */
652 /* Backlink to the containing struct dwo_file. */
653 struct dwo_file
*dwo_file
;
655 /* The "id" that distinguishes this CU/TU.
656 .debug_info calls this "dwo_id", .debug_types calls this "signature".
657 Since signatures came first, we stick with it for consistency. */
660 /* The section this CU/TU lives in, in the DWO file. */
661 struct dwarf2_section_info
*section
;
663 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
664 sect_offset sect_off
;
667 /* For types, offset in the type's DIE of the type defined by this TU. */
668 cu_offset type_offset_in_tu
;
671 /* include/dwarf2.h defines the DWP section codes.
672 It defines a max value but it doesn't define a min value, which we
673 use for error checking, so provide one. */
675 enum dwp_v2_section_ids
680 /* Data for one DWO file.
682 This includes virtual DWO files (a virtual DWO file is a DWO file as it
683 appears in a DWP file). DWP files don't really have DWO files per se -
684 comdat folding of types "loses" the DWO file they came from, and from
685 a high level view DWP files appear to contain a mass of random types.
686 However, to maintain consistency with the non-DWP case we pretend DWP
687 files contain virtual DWO files, and we assign each TU with one virtual
688 DWO file (generally based on the line and abbrev section offsets -
689 a heuristic that seems to work in practice). */
693 dwo_file () = default;
694 DISABLE_COPY_AND_ASSIGN (dwo_file
);
696 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
697 For virtual DWO files the name is constructed from the section offsets
698 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
699 from related CU+TUs. */
700 const char *dwo_name
= nullptr;
702 /* The DW_AT_comp_dir attribute. */
703 const char *comp_dir
= nullptr;
705 /* The bfd, when the file is open. Otherwise this is NULL.
706 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
707 gdb_bfd_ref_ptr dbfd
;
709 /* The sections that make up this DWO file.
710 Remember that for virtual DWO files in DWP V2, these are virtual
711 sections (for lack of a better name). */
712 struct dwo_sections sections
{};
714 /* The CUs in the file.
715 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
716 an extension to handle LLVM's Link Time Optimization output (where
717 multiple source files may be compiled into a single object/dwo pair). */
720 /* Table of TUs in the file.
721 Each element is a struct dwo_unit. */
725 /* These sections are what may appear in a DWP file. */
729 /* These are used by both DWP version 1 and 2. */
730 struct dwarf2_section_info str
;
731 struct dwarf2_section_info cu_index
;
732 struct dwarf2_section_info tu_index
;
734 /* These are only used by DWP version 2 files.
735 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
736 sections are referenced by section number, and are not recorded here.
737 In DWP version 2 there is at most one copy of all these sections, each
738 section being (effectively) comprised of the concatenation of all of the
739 individual sections that exist in the version 1 format.
740 To keep the code simple we treat each of these concatenated pieces as a
741 section itself (a virtual section?). */
742 struct dwarf2_section_info abbrev
;
743 struct dwarf2_section_info info
;
744 struct dwarf2_section_info line
;
745 struct dwarf2_section_info loc
;
746 struct dwarf2_section_info macinfo
;
747 struct dwarf2_section_info macro
;
748 struct dwarf2_section_info str_offsets
;
749 struct dwarf2_section_info types
;
752 /* These sections are what may appear in a virtual DWO file in DWP version 1.
753 A virtual DWO file is a DWO file as it appears in a DWP file. */
755 struct virtual_v1_dwo_sections
757 struct dwarf2_section_info abbrev
;
758 struct dwarf2_section_info line
;
759 struct dwarf2_section_info loc
;
760 struct dwarf2_section_info macinfo
;
761 struct dwarf2_section_info macro
;
762 struct dwarf2_section_info str_offsets
;
763 /* Each DWP hash table entry records one CU or one TU.
764 That is recorded here, and copied to dwo_unit.section. */
765 struct dwarf2_section_info info_or_types
;
768 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
769 In version 2, the sections of the DWO files are concatenated together
770 and stored in one section of that name. Thus each ELF section contains
771 several "virtual" sections. */
773 struct virtual_v2_dwo_sections
775 bfd_size_type abbrev_offset
;
776 bfd_size_type abbrev_size
;
778 bfd_size_type line_offset
;
779 bfd_size_type line_size
;
781 bfd_size_type loc_offset
;
782 bfd_size_type loc_size
;
784 bfd_size_type macinfo_offset
;
785 bfd_size_type macinfo_size
;
787 bfd_size_type macro_offset
;
788 bfd_size_type macro_size
;
790 bfd_size_type str_offsets_offset
;
791 bfd_size_type str_offsets_size
;
793 /* Each DWP hash table entry records one CU or one TU.
794 That is recorded here, and copied to dwo_unit.section. */
795 bfd_size_type info_or_types_offset
;
796 bfd_size_type info_or_types_size
;
799 /* Contents of DWP hash tables. */
801 struct dwp_hash_table
803 uint32_t version
, nr_columns
;
804 uint32_t nr_units
, nr_slots
;
805 const gdb_byte
*hash_table
, *unit_table
;
810 const gdb_byte
*indices
;
814 /* This is indexed by column number and gives the id of the section
816 #define MAX_NR_V2_DWO_SECTIONS \
817 (1 /* .debug_info or .debug_types */ \
818 + 1 /* .debug_abbrev */ \
819 + 1 /* .debug_line */ \
820 + 1 /* .debug_loc */ \
821 + 1 /* .debug_str_offsets */ \
822 + 1 /* .debug_macro or .debug_macinfo */)
823 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
824 const gdb_byte
*offsets
;
825 const gdb_byte
*sizes
;
830 /* Data for one DWP file. */
834 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
836 dbfd (std::move (abfd
))
840 /* Name of the file. */
843 /* File format version. */
847 gdb_bfd_ref_ptr dbfd
;
849 /* Section info for this file. */
850 struct dwp_sections sections
{};
852 /* Table of CUs in the file. */
853 const struct dwp_hash_table
*cus
= nullptr;
855 /* Table of TUs in the file. */
856 const struct dwp_hash_table
*tus
= nullptr;
858 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
862 /* Table to map ELF section numbers to their sections.
863 This is only needed for the DWP V1 file format. */
864 unsigned int num_sections
= 0;
865 asection
**elf_sections
= nullptr;
868 /* Struct used to pass misc. parameters to read_die_and_children, et
869 al. which are used for both .debug_info and .debug_types dies.
870 All parameters here are unchanging for the life of the call. This
871 struct exists to abstract away the constant parameters of die reading. */
873 struct die_reader_specs
875 /* The bfd of die_section. */
878 /* The CU of the DIE we are parsing. */
879 struct dwarf2_cu
*cu
;
881 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
882 struct dwo_file
*dwo_file
;
884 /* The section the die comes from.
885 This is either .debug_info or .debug_types, or the .dwo variants. */
886 struct dwarf2_section_info
*die_section
;
888 /* die_section->buffer. */
889 const gdb_byte
*buffer
;
891 /* The end of the buffer. */
892 const gdb_byte
*buffer_end
;
894 /* The abbreviation table to use when reading the DIEs. */
895 struct abbrev_table
*abbrev_table
;
898 /* A subclass of die_reader_specs that holds storage and has complex
899 constructor and destructor behavior. */
901 class cutu_reader
: public die_reader_specs
905 cutu_reader (dwarf2_per_cu_data
*this_cu
,
906 dwarf2_per_objfile
*per_objfile
,
907 struct abbrev_table
*abbrev_table
,
908 dwarf2_cu
*existing_cu
,
911 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
912 dwarf2_per_objfile
*per_objfile
,
913 struct dwarf2_cu
*parent_cu
= nullptr,
914 struct dwo_file
*dwo_file
= nullptr);
916 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
918 const gdb_byte
*info_ptr
= nullptr;
919 struct die_info
*comp_unit_die
= nullptr;
920 bool dummy_p
= false;
922 /* Release the new CU, putting it on the chain. This cannot be done
927 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
928 dwarf2_per_objfile
*per_objfile
,
929 dwarf2_cu
*existing_cu
);
931 struct dwarf2_per_cu_data
*m_this_cu
;
932 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
934 /* The ordinary abbreviation table. */
935 abbrev_table_up m_abbrev_table_holder
;
937 /* The DWO abbreviation table. */
938 abbrev_table_up m_dwo_abbrev_table
;
941 /* When we construct a partial symbol table entry we only
942 need this much information. */
943 struct partial_die_info
: public allocate_on_obstack
945 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
947 /* Disable assign but still keep copy ctor, which is needed
948 load_partial_dies. */
949 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
951 /* Adjust the partial die before generating a symbol for it. This
952 function may set the is_external flag or change the DIE's
954 void fixup (struct dwarf2_cu
*cu
);
956 /* Read a minimal amount of information into the minimal die
958 const gdb_byte
*read (const struct die_reader_specs
*reader
,
959 const struct abbrev_info
&abbrev
,
960 const gdb_byte
*info_ptr
);
962 /* Offset of this DIE. */
963 const sect_offset sect_off
;
965 /* DWARF-2 tag for this DIE. */
966 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
968 /* Assorted flags describing the data found in this DIE. */
969 const unsigned int has_children
: 1;
971 unsigned int is_external
: 1;
972 unsigned int is_declaration
: 1;
973 unsigned int has_type
: 1;
974 unsigned int has_specification
: 1;
975 unsigned int has_pc_info
: 1;
976 unsigned int may_be_inlined
: 1;
978 /* This DIE has been marked DW_AT_main_subprogram. */
979 unsigned int main_subprogram
: 1;
981 /* Flag set if the SCOPE field of this structure has been
983 unsigned int scope_set
: 1;
985 /* Flag set if the DIE has a byte_size attribute. */
986 unsigned int has_byte_size
: 1;
988 /* Flag set if the DIE has a DW_AT_const_value attribute. */
989 unsigned int has_const_value
: 1;
991 /* Flag set if any of the DIE's children are template arguments. */
992 unsigned int has_template_arguments
: 1;
994 /* Flag set if fixup has been called on this die. */
995 unsigned int fixup_called
: 1;
997 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
998 unsigned int is_dwz
: 1;
1000 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1001 unsigned int spec_is_dwz
: 1;
1003 /* The name of this DIE. Normally the value of DW_AT_name, but
1004 sometimes a default name for unnamed DIEs. */
1005 const char *name
= nullptr;
1007 /* The linkage name, if present. */
1008 const char *linkage_name
= nullptr;
1010 /* The scope to prepend to our children. This is generally
1011 allocated on the comp_unit_obstack, so will disappear
1012 when this compilation unit leaves the cache. */
1013 const char *scope
= nullptr;
1015 /* Some data associated with the partial DIE. The tag determines
1016 which field is live. */
1019 /* The location description associated with this DIE, if any. */
1020 struct dwarf_block
*locdesc
;
1021 /* The offset of an import, for DW_TAG_imported_unit. */
1022 sect_offset sect_off
;
1025 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1026 CORE_ADDR lowpc
= 0;
1027 CORE_ADDR highpc
= 0;
1029 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1030 DW_AT_sibling, if any. */
1031 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1032 could return DW_AT_sibling values to its caller load_partial_dies. */
1033 const gdb_byte
*sibling
= nullptr;
1035 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1036 DW_AT_specification (or DW_AT_abstract_origin or
1037 DW_AT_extension). */
1038 sect_offset spec_offset
{};
1040 /* Pointers to this DIE's parent, first child, and next sibling,
1042 struct partial_die_info
*die_parent
= nullptr;
1043 struct partial_die_info
*die_child
= nullptr;
1044 struct partial_die_info
*die_sibling
= nullptr;
1046 friend struct partial_die_info
*
1047 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1050 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1051 partial_die_info (sect_offset sect_off
)
1052 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1056 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1058 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1063 has_specification
= 0;
1066 main_subprogram
= 0;
1069 has_const_value
= 0;
1070 has_template_arguments
= 0;
1077 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1078 but this would require a corresponding change in unpack_field_as_long
1080 static int bits_per_byte
= 8;
1082 struct variant_part_builder
;
1084 /* When reading a variant, we track a bit more information about the
1085 field, and store it in an object of this type. */
1087 struct variant_field
1089 int first_field
= -1;
1090 int last_field
= -1;
1092 /* A variant can contain other variant parts. */
1093 std::vector
<variant_part_builder
> variant_parts
;
1095 /* If we see a DW_TAG_variant, then this will be set if this is the
1097 bool default_branch
= false;
1098 /* If we see a DW_AT_discr_value, then this will be the discriminant
1100 ULONGEST discriminant_value
= 0;
1101 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1103 struct dwarf_block
*discr_list_data
= nullptr;
1106 /* This represents a DW_TAG_variant_part. */
1108 struct variant_part_builder
1110 /* The offset of the discriminant field. */
1111 sect_offset discriminant_offset
{};
1113 /* Variants that are direct children of this variant part. */
1114 std::vector
<variant_field
> variants
;
1116 /* True if we're currently reading a variant. */
1117 bool processing_variant
= false;
1122 int accessibility
= 0;
1124 /* Variant parts need to find the discriminant, which is a DIE
1125 reference. We track the section offset of each field to make
1128 struct field field
{};
1133 const char *name
= nullptr;
1134 std::vector
<struct fn_field
> fnfields
;
1137 /* The routines that read and process dies for a C struct or C++ class
1138 pass lists of data member fields and lists of member function fields
1139 in an instance of a field_info structure, as defined below. */
1142 /* List of data member and baseclasses fields. */
1143 std::vector
<struct nextfield
> fields
;
1144 std::vector
<struct nextfield
> baseclasses
;
1146 /* Set if the accessibility of one of the fields is not public. */
1147 int non_public_fields
= 0;
1149 /* Member function fieldlist array, contains name of possibly overloaded
1150 member function, number of overloaded member functions and a pointer
1151 to the head of the member function field chain. */
1152 std::vector
<struct fnfieldlist
> fnfieldlists
;
1154 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1155 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1156 std::vector
<struct decl_field
> typedef_field_list
;
1158 /* Nested types defined by this class and the number of elements in this
1160 std::vector
<struct decl_field
> nested_types_list
;
1162 /* If non-null, this is the variant part we are currently
1164 variant_part_builder
*current_variant_part
= nullptr;
1165 /* This holds all the top-level variant parts attached to the type
1167 std::vector
<variant_part_builder
> variant_parts
;
1169 /* Return the total number of fields (including baseclasses). */
1170 int nfields () const
1172 return fields
.size () + baseclasses
.size ();
1176 /* Loaded secondary compilation units are kept in memory until they
1177 have not been referenced for the processing of this many
1178 compilation units. Set this to zero to disable caching. Cache
1179 sizes of up to at least twenty will improve startup time for
1180 typical inter-CU-reference binaries, at an obvious memory cost. */
1181 static int dwarf_max_cache_age
= 5;
1183 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1184 struct cmd_list_element
*c
, const char *value
)
1186 fprintf_filtered (file
, _("The upper bound on the age of cached "
1187 "DWARF compilation units is %s.\n"),
1191 /* local function prototypes */
1193 static void dwarf2_find_base_address (struct die_info
*die
,
1194 struct dwarf2_cu
*cu
);
1196 static dwarf2_psymtab
*create_partial_symtab
1197 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1200 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1201 const gdb_byte
*info_ptr
,
1202 struct die_info
*type_unit_die
);
1204 static void dwarf2_build_psymtabs_hard
1205 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1207 static void scan_partial_symbols (struct partial_die_info
*,
1208 CORE_ADDR
*, CORE_ADDR
*,
1209 int, struct dwarf2_cu
*);
1211 static void add_partial_symbol (struct partial_die_info
*,
1212 struct dwarf2_cu
*);
1214 static void add_partial_namespace (struct partial_die_info
*pdi
,
1215 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1216 int set_addrmap
, struct dwarf2_cu
*cu
);
1218 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1219 CORE_ADDR
*highpc
, int set_addrmap
,
1220 struct dwarf2_cu
*cu
);
1222 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1223 struct dwarf2_cu
*cu
);
1225 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1226 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1227 int need_pc
, struct dwarf2_cu
*cu
);
1229 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1231 static struct partial_die_info
*load_partial_dies
1232 (const struct die_reader_specs
*, const gdb_byte
*, int);
1234 /* A pair of partial_die_info and compilation unit. */
1235 struct cu_partial_die_info
1237 /* The compilation unit of the partial_die_info. */
1238 struct dwarf2_cu
*cu
;
1239 /* A partial_die_info. */
1240 struct partial_die_info
*pdi
;
1242 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1248 cu_partial_die_info () = delete;
1251 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1252 struct dwarf2_cu
*);
1254 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1255 struct attribute
*, struct attr_abbrev
*,
1256 const gdb_byte
*, bool *need_reprocess
);
1258 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1259 struct attribute
*attr
);
1261 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1263 static sect_offset read_abbrev_offset
1264 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1265 struct dwarf2_section_info
*, sect_offset
);
1267 static const char *read_indirect_string
1268 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1269 const struct comp_unit_head
*, unsigned int *);
1271 static const char *read_indirect_string_at_offset
1272 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1274 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1278 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1279 ULONGEST str_index
);
1281 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1282 ULONGEST str_index
);
1284 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1286 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1287 struct dwarf2_cu
*);
1289 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1290 struct dwarf2_cu
*cu
);
1292 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1294 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1295 struct dwarf2_cu
*cu
);
1297 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1299 static struct die_info
*die_specification (struct die_info
*die
,
1300 struct dwarf2_cu
**);
1302 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1303 struct dwarf2_cu
*cu
);
1305 static void dwarf_decode_lines (struct line_header
*, const char *,
1306 struct dwarf2_cu
*, dwarf2_psymtab
*,
1307 CORE_ADDR
, int decode_mapping
);
1309 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1312 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1313 struct dwarf2_cu
*, struct symbol
* = NULL
);
1315 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1316 struct dwarf2_cu
*);
1318 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1321 struct obstack
*obstack
,
1322 struct dwarf2_cu
*cu
, LONGEST
*value
,
1323 const gdb_byte
**bytes
,
1324 struct dwarf2_locexpr_baton
**baton
);
1326 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1328 static int need_gnat_info (struct dwarf2_cu
*);
1330 static struct type
*die_descriptive_type (struct die_info
*,
1331 struct dwarf2_cu
*);
1333 static void set_descriptive_type (struct type
*, struct die_info
*,
1334 struct dwarf2_cu
*);
1336 static struct type
*die_containing_type (struct die_info
*,
1337 struct dwarf2_cu
*);
1339 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1340 struct dwarf2_cu
*);
1342 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1344 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1346 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1348 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1349 const char *suffix
, int physname
,
1350 struct dwarf2_cu
*cu
);
1352 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1354 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1356 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1358 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1360 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1362 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1364 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1365 struct dwarf2_cu
*, dwarf2_psymtab
*);
1367 /* Return the .debug_loclists section to use for cu. */
1368 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1370 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1371 values. Keep the items ordered with increasing constraints compliance. */
1374 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1375 PC_BOUNDS_NOT_PRESENT
,
1377 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1378 were present but they do not form a valid range of PC addresses. */
1381 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1384 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1388 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1389 CORE_ADDR
*, CORE_ADDR
*,
1393 static void get_scope_pc_bounds (struct die_info
*,
1394 CORE_ADDR
*, CORE_ADDR
*,
1395 struct dwarf2_cu
*);
1397 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1398 CORE_ADDR
, struct dwarf2_cu
*);
1400 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1401 struct dwarf2_cu
*);
1403 static void dwarf2_attach_fields_to_type (struct field_info
*,
1404 struct type
*, struct dwarf2_cu
*);
1406 static void dwarf2_add_member_fn (struct field_info
*,
1407 struct die_info
*, struct type
*,
1408 struct dwarf2_cu
*);
1410 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1412 struct dwarf2_cu
*);
1414 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1416 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1418 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1420 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1422 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1424 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1426 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1428 static struct type
*read_module_type (struct die_info
*die
,
1429 struct dwarf2_cu
*cu
);
1431 static const char *namespace_name (struct die_info
*die
,
1432 int *is_anonymous
, struct dwarf2_cu
*);
1434 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1436 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1439 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1440 struct dwarf2_cu
*);
1442 static struct die_info
*read_die_and_siblings_1
1443 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1446 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1447 const gdb_byte
*info_ptr
,
1448 const gdb_byte
**new_info_ptr
,
1449 struct die_info
*parent
);
1451 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1452 struct die_info
**, const gdb_byte
*,
1455 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1456 struct die_info
**, const gdb_byte
*);
1458 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1460 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1463 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1465 static const char *dwarf2_full_name (const char *name
,
1466 struct die_info
*die
,
1467 struct dwarf2_cu
*cu
);
1469 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1470 struct dwarf2_cu
*cu
);
1472 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1473 struct dwarf2_cu
**);
1475 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1477 static void dump_die_for_error (struct die_info
*);
1479 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1482 /*static*/ void dump_die (struct die_info
*, int max_level
);
1484 static void store_in_ref_table (struct die_info
*,
1485 struct dwarf2_cu
*);
1487 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1488 const struct attribute
*,
1489 struct dwarf2_cu
**);
1491 static struct die_info
*follow_die_ref (struct die_info
*,
1492 const struct attribute
*,
1493 struct dwarf2_cu
**);
1495 static struct die_info
*follow_die_sig (struct die_info
*,
1496 const struct attribute
*,
1497 struct dwarf2_cu
**);
1499 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1500 struct dwarf2_cu
*);
1502 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1503 const struct attribute
*,
1504 struct dwarf2_cu
*);
1506 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1507 dwarf2_per_objfile
*per_objfile
);
1509 static void read_signatured_type (signatured_type
*sig_type
,
1510 dwarf2_per_objfile
*per_objfile
);
1512 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1513 struct die_info
*die
, struct dwarf2_cu
*cu
,
1514 struct dynamic_prop
*prop
, struct type
*type
);
1516 /* memory allocation interface */
1518 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1520 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1522 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1524 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1525 struct dwarf2_loclist_baton
*baton
,
1526 const struct attribute
*attr
);
1528 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1530 struct dwarf2_cu
*cu
,
1533 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1534 const gdb_byte
*info_ptr
,
1535 struct abbrev_info
*abbrev
);
1537 static hashval_t
partial_die_hash (const void *item
);
1539 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1541 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1542 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1543 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1545 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1546 struct die_info
*comp_unit_die
,
1547 enum language pretend_language
);
1549 static struct type
*set_die_type (struct die_info
*, struct type
*,
1550 struct dwarf2_cu
*);
1552 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1554 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1556 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1557 dwarf2_per_objfile
*per_objfile
,
1559 enum language pretend_language
);
1561 static void process_full_comp_unit (dwarf2_cu
*cu
,
1562 enum language pretend_language
);
1564 static void process_full_type_unit (dwarf2_cu
*cu
,
1565 enum language pretend_language
);
1567 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1568 struct dwarf2_per_cu_data
*);
1570 static void dwarf2_mark (struct dwarf2_cu
*);
1572 static struct type
*get_die_type_at_offset (sect_offset
,
1573 dwarf2_per_cu_data
*per_cu
,
1574 dwarf2_per_objfile
*per_objfile
);
1576 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1578 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1579 dwarf2_per_objfile
*per_objfile
,
1580 enum language pretend_language
);
1582 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1584 /* Class, the destructor of which frees all allocated queue entries. This
1585 will only have work to do if an error was thrown while processing the
1586 dwarf. If no error was thrown then the queue entries should have all
1587 been processed, and freed, as we went along. */
1589 class dwarf2_queue_guard
1592 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1593 : m_per_objfile (per_objfile
)
1597 /* Free any entries remaining on the queue. There should only be
1598 entries left if we hit an error while processing the dwarf. */
1599 ~dwarf2_queue_guard ()
1601 /* Ensure that no memory is allocated by the queue. */
1602 std::queue
<dwarf2_queue_item
> empty
;
1603 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1606 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1609 dwarf2_per_objfile
*m_per_objfile
;
1612 dwarf2_queue_item::~dwarf2_queue_item ()
1614 /* Anything still marked queued is likely to be in an
1615 inconsistent state, so discard it. */
1618 per_objfile
->remove_cu (per_cu
);
1623 /* The return type of find_file_and_directory. Note, the enclosed
1624 string pointers are only valid while this object is valid. */
1626 struct file_and_directory
1628 /* The filename. This is never NULL. */
1631 /* The compilation directory. NULL if not known. If we needed to
1632 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1633 points directly to the DW_AT_comp_dir string attribute owned by
1634 the obstack that owns the DIE. */
1635 const char *comp_dir
;
1637 /* If we needed to build a new string for comp_dir, this is what
1638 owns the storage. */
1639 std::string comp_dir_storage
;
1642 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1643 struct dwarf2_cu
*cu
);
1645 static htab_up
allocate_signatured_type_table ();
1647 static htab_up
allocate_dwo_unit_table ();
1649 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1650 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1651 struct dwp_file
*dwp_file
, const char *comp_dir
,
1652 ULONGEST signature
, int is_debug_types
);
1654 static struct dwp_file
*get_dwp_file
1655 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1657 static struct dwo_unit
*lookup_dwo_comp_unit
1658 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1659 ULONGEST signature
);
1661 static struct dwo_unit
*lookup_dwo_type_unit
1662 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1664 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1666 /* A unique pointer to a dwo_file. */
1668 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1670 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1672 static void check_producer (struct dwarf2_cu
*cu
);
1674 static void free_line_header_voidp (void *arg
);
1676 /* Various complaints about symbol reading that don't abort the process. */
1679 dwarf2_debug_line_missing_file_complaint (void)
1681 complaint (_(".debug_line section has line data without a file"));
1685 dwarf2_debug_line_missing_end_sequence_complaint (void)
1687 complaint (_(".debug_line section has line "
1688 "program sequence without an end"));
1692 dwarf2_complex_location_expr_complaint (void)
1694 complaint (_("location expression too complex"));
1698 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1701 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1706 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1708 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1712 /* Hash function for line_header_hash. */
1715 line_header_hash (const struct line_header
*ofs
)
1717 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1720 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1723 line_header_hash_voidp (const void *item
)
1725 const struct line_header
*ofs
= (const struct line_header
*) item
;
1727 return line_header_hash (ofs
);
1730 /* Equality function for line_header_hash. */
1733 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1735 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1736 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1738 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1739 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1744 /* See declaration. */
1746 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1749 can_copy (can_copy_
)
1752 names
= &dwarf2_elf_names
;
1754 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1755 locate_sections (obfd
, sec
, *names
);
1758 dwarf2_per_bfd::~dwarf2_per_bfd ()
1760 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1761 per_cu
->imported_symtabs_free ();
1763 for (signatured_type
*sig_type
: all_type_units
)
1764 sig_type
->per_cu
.imported_symtabs_free ();
1766 /* Everything else should be on this->obstack. */
1772 dwarf2_per_objfile::remove_all_cus ()
1774 for (auto pair
: m_dwarf2_cus
)
1777 m_dwarf2_cus
.clear ();
1780 /* A helper class that calls free_cached_comp_units on
1783 class free_cached_comp_units
1787 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1788 : m_per_objfile (per_objfile
)
1792 ~free_cached_comp_units ()
1794 m_per_objfile
->remove_all_cus ();
1797 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1801 dwarf2_per_objfile
*m_per_objfile
;
1807 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1809 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1811 return this->m_symtabs
[per_cu
->index
] != nullptr;
1817 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1819 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1821 return this->m_symtabs
[per_cu
->index
];
1827 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1828 compunit_symtab
*symtab
)
1830 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1831 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1833 this->m_symtabs
[per_cu
->index
] = symtab
;
1836 /* Try to locate the sections we need for DWARF 2 debugging
1837 information and return true if we have enough to do something.
1838 NAMES points to the dwarf2 section names, or is NULL if the standard
1839 ELF names are used. CAN_COPY is true for formats where symbol
1840 interposition is possible and so symbol values must follow copy
1841 relocation rules. */
1844 dwarf2_has_info (struct objfile
*objfile
,
1845 const struct dwarf2_debug_sections
*names
,
1848 if (objfile
->flags
& OBJF_READNEVER
)
1851 struct dwarf2_per_objfile
*dwarf2_per_objfile
1852 = get_dwarf2_per_objfile (objfile
);
1854 if (dwarf2_per_objfile
== NULL
)
1856 /* For now, each dwarf2_per_objfile owns its own dwarf2_per_bfd (no
1858 dwarf2_per_bfd
*per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1860 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1863 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1864 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1865 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1866 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1869 /* When loading sections, we look either for uncompressed section or for
1870 compressed section names. */
1873 section_is_p (const char *section_name
,
1874 const struct dwarf2_section_names
*names
)
1876 if (names
->normal
!= NULL
1877 && strcmp (section_name
, names
->normal
) == 0)
1879 if (names
->compressed
!= NULL
1880 && strcmp (section_name
, names
->compressed
) == 0)
1885 /* See declaration. */
1888 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1889 const dwarf2_debug_sections
&names
)
1891 flagword aflag
= bfd_section_flags (sectp
);
1893 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1896 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1897 > bfd_get_file_size (abfd
))
1899 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1900 warning (_("Discarding section %s which has a section size (%s"
1901 ") larger than the file size [in module %s]"),
1902 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1903 bfd_get_filename (abfd
));
1905 else if (section_is_p (sectp
->name
, &names
.info
))
1907 this->info
.s
.section
= sectp
;
1908 this->info
.size
= bfd_section_size (sectp
);
1910 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1912 this->abbrev
.s
.section
= sectp
;
1913 this->abbrev
.size
= bfd_section_size (sectp
);
1915 else if (section_is_p (sectp
->name
, &names
.line
))
1917 this->line
.s
.section
= sectp
;
1918 this->line
.size
= bfd_section_size (sectp
);
1920 else if (section_is_p (sectp
->name
, &names
.loc
))
1922 this->loc
.s
.section
= sectp
;
1923 this->loc
.size
= bfd_section_size (sectp
);
1925 else if (section_is_p (sectp
->name
, &names
.loclists
))
1927 this->loclists
.s
.section
= sectp
;
1928 this->loclists
.size
= bfd_section_size (sectp
);
1930 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1932 this->macinfo
.s
.section
= sectp
;
1933 this->macinfo
.size
= bfd_section_size (sectp
);
1935 else if (section_is_p (sectp
->name
, &names
.macro
))
1937 this->macro
.s
.section
= sectp
;
1938 this->macro
.size
= bfd_section_size (sectp
);
1940 else if (section_is_p (sectp
->name
, &names
.str
))
1942 this->str
.s
.section
= sectp
;
1943 this->str
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1947 this->str_offsets
.s
.section
= sectp
;
1948 this->str_offsets
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.line_str
))
1952 this->line_str
.s
.section
= sectp
;
1953 this->line_str
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.addr
))
1957 this->addr
.s
.section
= sectp
;
1958 this->addr
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.frame
))
1962 this->frame
.s
.section
= sectp
;
1963 this->frame
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1967 this->eh_frame
.s
.section
= sectp
;
1968 this->eh_frame
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.ranges
))
1972 this->ranges
.s
.section
= sectp
;
1973 this->ranges
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1977 this->rnglists
.s
.section
= sectp
;
1978 this->rnglists
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.types
))
1982 struct dwarf2_section_info type_section
;
1984 memset (&type_section
, 0, sizeof (type_section
));
1985 type_section
.s
.section
= sectp
;
1986 type_section
.size
= bfd_section_size (sectp
);
1988 this->types
.push_back (type_section
);
1990 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1992 this->gdb_index
.s
.section
= sectp
;
1993 this->gdb_index
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1997 this->debug_names
.s
.section
= sectp
;
1998 this->debug_names
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2002 this->debug_aranges
.s
.section
= sectp
;
2003 this->debug_aranges
.size
= bfd_section_size (sectp
);
2006 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2007 && bfd_section_vma (sectp
) == 0)
2008 this->has_section_at_zero
= true;
2011 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2015 dwarf2_get_section_info (struct objfile
*objfile
,
2016 enum dwarf2_section_enum sect
,
2017 asection
**sectp
, const gdb_byte
**bufp
,
2018 bfd_size_type
*sizep
)
2020 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2021 struct dwarf2_section_info
*info
;
2023 /* We may see an objfile without any DWARF, in which case we just
2034 case DWARF2_DEBUG_FRAME
:
2035 info
= &data
->per_bfd
->frame
;
2037 case DWARF2_EH_FRAME
:
2038 info
= &data
->per_bfd
->eh_frame
;
2041 gdb_assert_not_reached ("unexpected section");
2044 info
->read (objfile
);
2046 *sectp
= info
->get_bfd_section ();
2047 *bufp
= info
->buffer
;
2048 *sizep
= info
->size
;
2051 /* A helper function to find the sections for a .dwz file. */
2054 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2056 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2058 /* Note that we only support the standard ELF names, because .dwz
2059 is ELF-only (at the time of writing). */
2060 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2062 dwz_file
->abbrev
.s
.section
= sectp
;
2063 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2065 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2067 dwz_file
->info
.s
.section
= sectp
;
2068 dwz_file
->info
.size
= bfd_section_size (sectp
);
2070 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2072 dwz_file
->str
.s
.section
= sectp
;
2073 dwz_file
->str
.size
= bfd_section_size (sectp
);
2075 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2077 dwz_file
->line
.s
.section
= sectp
;
2078 dwz_file
->line
.size
= bfd_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2082 dwz_file
->macro
.s
.section
= sectp
;
2083 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2087 dwz_file
->gdb_index
.s
.section
= sectp
;
2088 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2090 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2092 dwz_file
->debug_names
.s
.section
= sectp
;
2093 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2097 /* See dwarf2read.h. */
2100 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2102 const char *filename
;
2103 bfd_size_type buildid_len_arg
;
2107 if (per_bfd
->dwz_file
!= NULL
)
2108 return per_bfd
->dwz_file
.get ();
2110 bfd_set_error (bfd_error_no_error
);
2111 gdb::unique_xmalloc_ptr
<char> data
2112 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2113 &buildid_len_arg
, &buildid
));
2116 if (bfd_get_error () == bfd_error_no_error
)
2118 error (_("could not read '.gnu_debugaltlink' section: %s"),
2119 bfd_errmsg (bfd_get_error ()));
2122 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2124 buildid_len
= (size_t) buildid_len_arg
;
2126 filename
= data
.get ();
2128 std::string abs_storage
;
2129 if (!IS_ABSOLUTE_PATH (filename
))
2131 gdb::unique_xmalloc_ptr
<char> abs
2132 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2134 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2135 filename
= abs_storage
.c_str ();
2138 /* First try the file name given in the section. If that doesn't
2139 work, try to use the build-id instead. */
2140 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2141 if (dwz_bfd
!= NULL
)
2143 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2144 dwz_bfd
.reset (nullptr);
2147 if (dwz_bfd
== NULL
)
2148 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2150 if (dwz_bfd
== nullptr)
2152 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2153 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2155 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2162 /* File successfully retrieved from server. */
2163 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2165 if (dwz_bfd
== nullptr)
2166 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2167 alt_filename
.get ());
2168 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2169 dwz_bfd
.reset (nullptr);
2173 if (dwz_bfd
== NULL
)
2174 error (_("could not find '.gnu_debugaltlink' file for %s"),
2175 bfd_get_filename (per_bfd
->obfd
));
2177 std::unique_ptr
<struct dwz_file
> result
2178 (new struct dwz_file (std::move (dwz_bfd
)));
2180 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2183 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2184 per_bfd
->dwz_file
= std::move (result
);
2185 return per_bfd
->dwz_file
.get ();
2188 /* DWARF quick_symbols_functions support. */
2190 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2191 unique line tables, so we maintain a separate table of all .debug_line
2192 derived entries to support the sharing.
2193 All the quick functions need is the list of file names. We discard the
2194 line_header when we're done and don't need to record it here. */
2195 struct quick_file_names
2197 /* The data used to construct the hash key. */
2198 struct stmt_list_hash hash
;
2200 /* The number of entries in file_names, real_names. */
2201 unsigned int num_file_names
;
2203 /* The file names from the line table, after being run through
2205 const char **file_names
;
2207 /* The file names from the line table after being run through
2208 gdb_realpath. These are computed lazily. */
2209 const char **real_names
;
2212 /* When using the index (and thus not using psymtabs), each CU has an
2213 object of this type. This is used to hold information needed by
2214 the various "quick" methods. */
2215 struct dwarf2_per_cu_quick_data
2217 /* The file table. This can be NULL if there was no file table
2218 or it's currently not read in.
2219 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2220 struct quick_file_names
*file_names
;
2222 /* A temporary mark bit used when iterating over all CUs in
2223 expand_symtabs_matching. */
2224 unsigned int mark
: 1;
2226 /* True if we've tried to read the file table and found there isn't one.
2227 There will be no point in trying to read it again next time. */
2228 unsigned int no_file_data
: 1;
2231 /* Utility hash function for a stmt_list_hash. */
2234 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2238 if (stmt_list_hash
->dwo_unit
!= NULL
)
2239 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2240 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2244 /* Utility equality function for a stmt_list_hash. */
2247 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2248 const struct stmt_list_hash
*rhs
)
2250 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2252 if (lhs
->dwo_unit
!= NULL
2253 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2256 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2259 /* Hash function for a quick_file_names. */
2262 hash_file_name_entry (const void *e
)
2264 const struct quick_file_names
*file_data
2265 = (const struct quick_file_names
*) e
;
2267 return hash_stmt_list_entry (&file_data
->hash
);
2270 /* Equality function for a quick_file_names. */
2273 eq_file_name_entry (const void *a
, const void *b
)
2275 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2276 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2278 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2281 /* Delete function for a quick_file_names. */
2284 delete_file_name_entry (void *e
)
2286 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2289 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2291 xfree ((void*) file_data
->file_names
[i
]);
2292 if (file_data
->real_names
)
2293 xfree ((void*) file_data
->real_names
[i
]);
2296 /* The space for the struct itself lives on the obstack, so we don't
2300 /* Create a quick_file_names hash table. */
2303 create_quick_file_names_table (unsigned int nr_initial_entries
)
2305 return htab_up (htab_create_alloc (nr_initial_entries
,
2306 hash_file_name_entry
, eq_file_name_entry
,
2307 delete_file_name_entry
, xcalloc
, xfree
));
2310 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2311 function is unrelated to symtabs, symtab would have to be created afterwards.
2312 You should call age_cached_comp_units after processing the CU. */
2315 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2318 if (per_cu
->is_debug_types
)
2319 load_full_type_unit (per_cu
, per_objfile
);
2321 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2323 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2325 return nullptr; /* Dummy CU. */
2327 dwarf2_find_base_address (cu
->dies
, cu
);
2332 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2335 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2336 dwarf2_per_objfile
*dwarf2_per_objfile
,
2339 /* Skip type_unit_groups, reading the type units they contain
2340 is handled elsewhere. */
2341 if (per_cu
->type_unit_group_p ())
2344 /* The destructor of dwarf2_queue_guard frees any entries left on
2345 the queue. After this point we're guaranteed to leave this function
2346 with the dwarf queue empty. */
2347 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2349 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2351 queue_comp_unit (per_cu
, dwarf2_per_objfile
, language_minimal
);
2352 dwarf2_cu
*cu
= load_cu (per_cu
, dwarf2_per_objfile
, skip_partial
);
2354 /* If we just loaded a CU from a DWO, and we're working with an index
2355 that may badly handle TUs, load all the TUs in that DWO as well.
2356 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2357 if (!per_cu
->is_debug_types
2359 && cu
->dwo_unit
!= NULL
2360 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2361 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2362 /* DWP files aren't supported yet. */
2363 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2364 queue_and_load_all_dwo_tus (cu
);
2367 process_queue (dwarf2_per_objfile
);
2369 /* Age the cache, releasing compilation units that have not
2370 been used recently. */
2371 dwarf2_per_objfile
->age_comp_units ();
2374 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2375 the per-objfile for which this symtab is instantiated.
2377 Returns the resulting symbol table. */
2379 static struct compunit_symtab
*
2380 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2381 dwarf2_per_objfile
*dwarf2_per_objfile
,
2384 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2386 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2388 free_cached_comp_units
freer (dwarf2_per_objfile
);
2389 scoped_restore decrementer
= increment_reading_symtab ();
2390 dw2_do_instantiate_symtab (per_cu
, dwarf2_per_objfile
, skip_partial
);
2391 process_cu_includes (dwarf2_per_objfile
);
2394 return dwarf2_per_objfile
->get_symtab (per_cu
);
2397 /* See declaration. */
2399 dwarf2_per_cu_data
*
2400 dwarf2_per_bfd::get_cutu (int index
)
2402 if (index
>= this->all_comp_units
.size ())
2404 index
-= this->all_comp_units
.size ();
2405 gdb_assert (index
< this->all_type_units
.size ());
2406 return &this->all_type_units
[index
]->per_cu
;
2409 return this->all_comp_units
[index
];
2412 /* See declaration. */
2414 dwarf2_per_cu_data
*
2415 dwarf2_per_bfd::get_cu (int index
)
2417 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2419 return this->all_comp_units
[index
];
2422 /* See declaration. */
2425 dwarf2_per_bfd::get_tu (int index
)
2427 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2429 return this->all_type_units
[index
];
2434 dwarf2_per_cu_data
*
2435 dwarf2_per_bfd::allocate_per_cu ()
2437 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2438 result
->per_bfd
= this;
2439 result
->index
= m_num_psymtabs
++;
2446 dwarf2_per_bfd::allocate_signatured_type ()
2448 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2449 result
->per_cu
.per_bfd
= this;
2450 result
->per_cu
.index
= m_num_psymtabs
++;
2454 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2455 obstack, and constructed with the specified field values. */
2457 static dwarf2_per_cu_data
*
2458 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2459 struct dwarf2_section_info
*section
,
2461 sect_offset sect_off
, ULONGEST length
)
2463 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2464 the_cu
->sect_off
= sect_off
;
2465 the_cu
->length
= length
;
2466 the_cu
->section
= section
;
2467 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2468 struct dwarf2_per_cu_quick_data
);
2469 the_cu
->is_dwz
= is_dwz
;
2473 /* A helper for create_cus_from_index that handles a given list of
2477 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2478 const gdb_byte
*cu_list
, offset_type n_elements
,
2479 struct dwarf2_section_info
*section
,
2482 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2484 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2486 sect_offset sect_off
2487 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2488 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2491 dwarf2_per_cu_data
*per_cu
2492 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2494 per_bfd
->all_comp_units
.push_back (per_cu
);
2498 /* Read the CU list from the mapped index, and use it to create all
2499 the CU objects for PER_BFD. */
2502 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2503 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2504 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2506 gdb_assert (per_bfd
->all_comp_units
.empty ());
2507 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2509 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2512 if (dwz_elements
== 0)
2515 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2516 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2520 /* Create the signatured type hash table from the index. */
2523 create_signatured_type_table_from_index
2524 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2525 const gdb_byte
*bytes
, offset_type elements
)
2527 gdb_assert (per_bfd
->all_type_units
.empty ());
2528 per_bfd
->all_type_units
.reserve (elements
/ 3);
2530 htab_up sig_types_hash
= allocate_signatured_type_table ();
2532 for (offset_type i
= 0; i
< elements
; i
+= 3)
2534 struct signatured_type
*sig_type
;
2537 cu_offset type_offset_in_tu
;
2539 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2540 sect_offset sect_off
2541 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2543 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2545 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2548 sig_type
= per_bfd
->allocate_signatured_type ();
2549 sig_type
->signature
= signature
;
2550 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2551 sig_type
->per_cu
.is_debug_types
= 1;
2552 sig_type
->per_cu
.section
= section
;
2553 sig_type
->per_cu
.sect_off
= sect_off
;
2554 sig_type
->per_cu
.v
.quick
2555 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2556 struct dwarf2_per_cu_quick_data
);
2558 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2561 per_bfd
->all_type_units
.push_back (sig_type
);
2564 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2567 /* Create the signatured type hash table from .debug_names. */
2570 create_signatured_type_table_from_debug_names
2571 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2572 const mapped_debug_names
&map
,
2573 struct dwarf2_section_info
*section
,
2574 struct dwarf2_section_info
*abbrev_section
)
2576 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2578 section
->read (objfile
);
2579 abbrev_section
->read (objfile
);
2581 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2582 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2584 htab_up sig_types_hash
= allocate_signatured_type_table ();
2586 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2588 struct signatured_type
*sig_type
;
2591 sect_offset sect_off
2592 = (sect_offset
) (extract_unsigned_integer
2593 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2595 map
.dwarf5_byte_order
));
2597 comp_unit_head cu_header
;
2598 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2600 section
->buffer
+ to_underlying (sect_off
),
2603 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2604 sig_type
->signature
= cu_header
.signature
;
2605 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2606 sig_type
->per_cu
.is_debug_types
= 1;
2607 sig_type
->per_cu
.section
= section
;
2608 sig_type
->per_cu
.sect_off
= sect_off
;
2609 sig_type
->per_cu
.v
.quick
2610 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2611 struct dwarf2_per_cu_quick_data
);
2613 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2616 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2619 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2622 /* Read the address map data from the mapped index, and use it to
2623 populate the objfile's psymtabs_addrmap. */
2626 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2627 struct mapped_index
*index
)
2629 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2630 struct gdbarch
*gdbarch
= objfile
->arch ();
2631 const gdb_byte
*iter
, *end
;
2632 struct addrmap
*mutable_map
;
2635 auto_obstack temp_obstack
;
2637 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2639 iter
= index
->address_table
.data ();
2640 end
= iter
+ index
->address_table
.size ();
2642 baseaddr
= objfile
->text_section_offset ();
2646 ULONGEST hi
, lo
, cu_index
;
2647 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2649 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2651 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2656 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2657 hex_string (lo
), hex_string (hi
));
2661 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2663 complaint (_(".gdb_index address table has invalid CU number %u"),
2664 (unsigned) cu_index
);
2668 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2669 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2670 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2671 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2674 objfile
->partial_symtabs
->psymtabs_addrmap
2675 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2678 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2679 populate the objfile's psymtabs_addrmap. */
2682 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2683 struct dwarf2_section_info
*section
)
2685 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2686 bfd
*abfd
= objfile
->obfd
;
2687 struct gdbarch
*gdbarch
= objfile
->arch ();
2688 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2690 auto_obstack temp_obstack
;
2691 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2693 std::unordered_map
<sect_offset
,
2694 dwarf2_per_cu_data
*,
2695 gdb::hash_enum
<sect_offset
>>
2696 debug_info_offset_to_per_cu
;
2697 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2699 const auto insertpair
2700 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2701 if (!insertpair
.second
)
2703 warning (_("Section .debug_aranges in %s has duplicate "
2704 "debug_info_offset %s, ignoring .debug_aranges."),
2705 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2710 section
->read (objfile
);
2712 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2714 const gdb_byte
*addr
= section
->buffer
;
2716 while (addr
< section
->buffer
+ section
->size
)
2718 const gdb_byte
*const entry_addr
= addr
;
2719 unsigned int bytes_read
;
2721 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2725 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2726 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2727 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2728 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2730 warning (_("Section .debug_aranges in %s entry at offset %s "
2731 "length %s exceeds section length %s, "
2732 "ignoring .debug_aranges."),
2733 objfile_name (objfile
),
2734 plongest (entry_addr
- section
->buffer
),
2735 plongest (bytes_read
+ entry_length
),
2736 pulongest (section
->size
));
2740 /* The version number. */
2741 const uint16_t version
= read_2_bytes (abfd
, addr
);
2745 warning (_("Section .debug_aranges in %s entry at offset %s "
2746 "has unsupported version %d, ignoring .debug_aranges."),
2747 objfile_name (objfile
),
2748 plongest (entry_addr
- section
->buffer
), version
);
2752 const uint64_t debug_info_offset
2753 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2754 addr
+= offset_size
;
2755 const auto per_cu_it
2756 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2757 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2759 warning (_("Section .debug_aranges in %s entry at offset %s "
2760 "debug_info_offset %s does not exists, "
2761 "ignoring .debug_aranges."),
2762 objfile_name (objfile
),
2763 plongest (entry_addr
- section
->buffer
),
2764 pulongest (debug_info_offset
));
2767 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2769 const uint8_t address_size
= *addr
++;
2770 if (address_size
< 1 || address_size
> 8)
2772 warning (_("Section .debug_aranges in %s entry at offset %s "
2773 "address_size %u is invalid, ignoring .debug_aranges."),
2774 objfile_name (objfile
),
2775 plongest (entry_addr
- section
->buffer
), address_size
);
2779 const uint8_t segment_selector_size
= *addr
++;
2780 if (segment_selector_size
!= 0)
2782 warning (_("Section .debug_aranges in %s entry at offset %s "
2783 "segment_selector_size %u is not supported, "
2784 "ignoring .debug_aranges."),
2785 objfile_name (objfile
),
2786 plongest (entry_addr
- section
->buffer
),
2787 segment_selector_size
);
2791 /* Must pad to an alignment boundary that is twice the address
2792 size. It is undocumented by the DWARF standard but GCC does
2794 for (size_t padding
= ((-(addr
- section
->buffer
))
2795 & (2 * address_size
- 1));
2796 padding
> 0; padding
--)
2799 warning (_("Section .debug_aranges in %s entry at offset %s "
2800 "padding is not zero, ignoring .debug_aranges."),
2801 objfile_name (objfile
),
2802 plongest (entry_addr
- section
->buffer
));
2808 if (addr
+ 2 * address_size
> entry_end
)
2810 warning (_("Section .debug_aranges in %s entry at offset %s "
2811 "address list is not properly terminated, "
2812 "ignoring .debug_aranges."),
2813 objfile_name (objfile
),
2814 plongest (entry_addr
- section
->buffer
));
2817 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2819 addr
+= address_size
;
2820 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2822 addr
+= address_size
;
2823 if (start
== 0 && length
== 0)
2825 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2827 /* Symbol was eliminated due to a COMDAT group. */
2830 ULONGEST end
= start
+ length
;
2831 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2833 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2835 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2839 objfile
->partial_symtabs
->psymtabs_addrmap
2840 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2843 /* Find a slot in the mapped index INDEX for the object named NAME.
2844 If NAME is found, set *VEC_OUT to point to the CU vector in the
2845 constant pool and return true. If NAME cannot be found, return
2849 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2850 offset_type
**vec_out
)
2853 offset_type slot
, step
;
2854 int (*cmp
) (const char *, const char *);
2856 gdb::unique_xmalloc_ptr
<char> without_params
;
2857 if (current_language
->la_language
== language_cplus
2858 || current_language
->la_language
== language_fortran
2859 || current_language
->la_language
== language_d
)
2861 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2864 if (strchr (name
, '(') != NULL
)
2866 without_params
= cp_remove_params (name
);
2868 if (without_params
!= NULL
)
2869 name
= without_params
.get ();
2873 /* Index version 4 did not support case insensitive searches. But the
2874 indices for case insensitive languages are built in lowercase, therefore
2875 simulate our NAME being searched is also lowercased. */
2876 hash
= mapped_index_string_hash ((index
->version
== 4
2877 && case_sensitivity
== case_sensitive_off
2878 ? 5 : index
->version
),
2881 slot
= hash
& (index
->symbol_table
.size () - 1);
2882 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2883 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2889 const auto &bucket
= index
->symbol_table
[slot
];
2890 if (bucket
.name
== 0 && bucket
.vec
== 0)
2893 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2894 if (!cmp (name
, str
))
2896 *vec_out
= (offset_type
*) (index
->constant_pool
2897 + MAYBE_SWAP (bucket
.vec
));
2901 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2905 /* A helper function that reads the .gdb_index from BUFFER and fills
2906 in MAP. FILENAME is the name of the file containing the data;
2907 it is used for error reporting. DEPRECATED_OK is true if it is
2908 ok to use deprecated sections.
2910 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2911 out parameters that are filled in with information about the CU and
2912 TU lists in the section.
2914 Returns true if all went well, false otherwise. */
2917 read_gdb_index_from_buffer (const char *filename
,
2919 gdb::array_view
<const gdb_byte
> buffer
,
2920 struct mapped_index
*map
,
2921 const gdb_byte
**cu_list
,
2922 offset_type
*cu_list_elements
,
2923 const gdb_byte
**types_list
,
2924 offset_type
*types_list_elements
)
2926 const gdb_byte
*addr
= &buffer
[0];
2928 /* Version check. */
2929 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2930 /* Versions earlier than 3 emitted every copy of a psymbol. This
2931 causes the index to behave very poorly for certain requests. Version 3
2932 contained incomplete addrmap. So, it seems better to just ignore such
2936 static int warning_printed
= 0;
2937 if (!warning_printed
)
2939 warning (_("Skipping obsolete .gdb_index section in %s."),
2941 warning_printed
= 1;
2945 /* Index version 4 uses a different hash function than index version
2948 Versions earlier than 6 did not emit psymbols for inlined
2949 functions. Using these files will cause GDB not to be able to
2950 set breakpoints on inlined functions by name, so we ignore these
2951 indices unless the user has done
2952 "set use-deprecated-index-sections on". */
2953 if (version
< 6 && !deprecated_ok
)
2955 static int warning_printed
= 0;
2956 if (!warning_printed
)
2959 Skipping deprecated .gdb_index section in %s.\n\
2960 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2961 to use the section anyway."),
2963 warning_printed
= 1;
2967 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2968 of the TU (for symbols coming from TUs),
2969 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2970 Plus gold-generated indices can have duplicate entries for global symbols,
2971 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2972 These are just performance bugs, and we can't distinguish gdb-generated
2973 indices from gold-generated ones, so issue no warning here. */
2975 /* Indexes with higher version than the one supported by GDB may be no
2976 longer backward compatible. */
2980 map
->version
= version
;
2982 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2985 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2986 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2990 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2991 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2992 - MAYBE_SWAP (metadata
[i
]))
2996 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2997 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2999 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3002 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3003 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3005 = gdb::array_view
<mapped_index::symbol_table_slot
>
3006 ((mapped_index::symbol_table_slot
*) symbol_table
,
3007 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3010 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3015 /* Callback types for dwarf2_read_gdb_index. */
3017 typedef gdb::function_view
3018 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3019 get_gdb_index_contents_ftype
;
3020 typedef gdb::function_view
3021 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3022 get_gdb_index_contents_dwz_ftype
;
3024 /* Read .gdb_index. If everything went ok, initialize the "quick"
3025 elements of all the CUs and return 1. Otherwise, return 0. */
3028 dwarf2_read_gdb_index
3029 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3030 get_gdb_index_contents_ftype get_gdb_index_contents
,
3031 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3033 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3034 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3035 struct dwz_file
*dwz
;
3036 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3038 gdb::array_view
<const gdb_byte
> main_index_contents
3039 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3041 if (main_index_contents
.empty ())
3044 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3045 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3046 use_deprecated_index_sections
,
3047 main_index_contents
, map
.get (), &cu_list
,
3048 &cu_list_elements
, &types_list
,
3049 &types_list_elements
))
3052 /* Don't use the index if it's empty. */
3053 if (map
->symbol_table
.empty ())
3056 /* If there is a .dwz file, read it so we can get its CU list as
3058 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
3061 struct mapped_index dwz_map
;
3062 const gdb_byte
*dwz_types_ignore
;
3063 offset_type dwz_types_elements_ignore
;
3065 gdb::array_view
<const gdb_byte
> dwz_index_content
3066 = get_gdb_index_contents_dwz (objfile
, dwz
);
3068 if (dwz_index_content
.empty ())
3071 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3072 1, dwz_index_content
, &dwz_map
,
3073 &dwz_list
, &dwz_list_elements
,
3075 &dwz_types_elements_ignore
))
3077 warning (_("could not read '.gdb_index' section from %s; skipping"),
3078 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3083 create_cus_from_index (dwarf2_per_objfile
->per_bfd
, cu_list
, cu_list_elements
,
3084 dwz_list
, dwz_list_elements
);
3086 if (types_list_elements
)
3088 /* We can only handle a single .debug_types when we have an
3090 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3093 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3095 create_signatured_type_table_from_index (dwarf2_per_objfile
->per_bfd
,
3096 section
, types_list
,
3097 types_list_elements
);
3100 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3102 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3103 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3104 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3105 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3110 /* die_reader_func for dw2_get_file_names. */
3113 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3114 const gdb_byte
*info_ptr
,
3115 struct die_info
*comp_unit_die
)
3117 struct dwarf2_cu
*cu
= reader
->cu
;
3118 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3119 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
3120 struct dwarf2_per_cu_data
*lh_cu
;
3121 struct attribute
*attr
;
3123 struct quick_file_names
*qfn
;
3125 gdb_assert (! this_cu
->is_debug_types
);
3127 /* Our callers never want to match partial units -- instead they
3128 will match the enclosing full CU. */
3129 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3131 this_cu
->v
.quick
->no_file_data
= 1;
3139 sect_offset line_offset
{};
3141 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3142 if (attr
!= nullptr)
3144 struct quick_file_names find_entry
;
3146 line_offset
= (sect_offset
) DW_UNSND (attr
);
3148 /* We may have already read in this line header (TU line header sharing).
3149 If we have we're done. */
3150 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3151 find_entry
.hash
.line_sect_off
= line_offset
;
3152 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3153 &find_entry
, INSERT
);
3156 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3160 lh
= dwarf_decode_line_header (line_offset
, cu
);
3164 lh_cu
->v
.quick
->no_file_data
= 1;
3168 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3169 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3170 qfn
->hash
.line_sect_off
= line_offset
;
3171 gdb_assert (slot
!= NULL
);
3174 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3177 if (strcmp (fnd
.name
, "<unknown>") != 0)
3180 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3182 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3183 qfn
->num_file_names
);
3185 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3186 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3187 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3188 fnd
.comp_dir
).release ();
3189 qfn
->real_names
= NULL
;
3191 lh_cu
->v
.quick
->file_names
= qfn
;
3194 /* A helper for the "quick" functions which attempts to read the line
3195 table for THIS_CU. */
3197 static struct quick_file_names
*
3198 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3199 dwarf2_per_objfile
*per_objfile
)
3201 /* This should never be called for TUs. */
3202 gdb_assert (! this_cu
->is_debug_types
);
3203 /* Nor type unit groups. */
3204 gdb_assert (! this_cu
->type_unit_group_p ());
3206 if (this_cu
->v
.quick
->file_names
!= NULL
)
3207 return this_cu
->v
.quick
->file_names
;
3208 /* If we know there is no line data, no point in looking again. */
3209 if (this_cu
->v
.quick
->no_file_data
)
3212 cutu_reader
reader (this_cu
, per_objfile
);
3213 if (!reader
.dummy_p
)
3214 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3216 if (this_cu
->v
.quick
->no_file_data
)
3218 return this_cu
->v
.quick
->file_names
;
3221 /* A helper for the "quick" functions which computes and caches the
3222 real path for a given file name from the line table. */
3225 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3226 struct quick_file_names
*qfn
, int index
)
3228 if (qfn
->real_names
== NULL
)
3229 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3230 qfn
->num_file_names
, const char *);
3232 if (qfn
->real_names
[index
] == NULL
)
3233 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3235 return qfn
->real_names
[index
];
3238 static struct symtab
*
3239 dw2_find_last_source_symtab (struct objfile
*objfile
)
3241 struct dwarf2_per_objfile
*dwarf2_per_objfile
3242 = get_dwarf2_per_objfile (objfile
);
3243 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3244 compunit_symtab
*cust
3245 = dw2_instantiate_symtab (dwarf_cu
, dwarf2_per_objfile
, false);
3250 return compunit_primary_filetab (cust
);
3253 /* Traversal function for dw2_forget_cached_source_info. */
3256 dw2_free_cached_file_names (void **slot
, void *info
)
3258 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3260 if (file_data
->real_names
)
3264 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3266 xfree ((void*) file_data
->real_names
[i
]);
3267 file_data
->real_names
[i
] = NULL
;
3275 dw2_forget_cached_source_info (struct objfile
*objfile
)
3277 struct dwarf2_per_objfile
*dwarf2_per_objfile
3278 = get_dwarf2_per_objfile (objfile
);
3280 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3281 dw2_free_cached_file_names
, NULL
);
3284 /* Helper function for dw2_map_symtabs_matching_filename that expands
3285 the symtabs and calls the iterator. */
3288 dw2_map_expand_apply (struct objfile
*objfile
,
3289 struct dwarf2_per_cu_data
*per_cu
,
3290 const char *name
, const char *real_path
,
3291 gdb::function_view
<bool (symtab
*)> callback
)
3293 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3295 /* Don't visit already-expanded CUs. */
3296 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3297 if (per_objfile
->symtab_set_p (per_cu
))
3300 /* This may expand more than one symtab, and we want to iterate over
3302 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3304 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3305 last_made
, callback
);
3308 /* Implementation of the map_symtabs_matching_filename method. */
3311 dw2_map_symtabs_matching_filename
3312 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3313 gdb::function_view
<bool (symtab
*)> callback
)
3315 const char *name_basename
= lbasename (name
);
3316 struct dwarf2_per_objfile
*dwarf2_per_objfile
3317 = get_dwarf2_per_objfile (objfile
);
3319 /* The rule is CUs specify all the files, including those used by
3320 any TU, so there's no need to scan TUs here. */
3322 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3324 /* We only need to look at symtabs not already expanded. */
3325 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3328 quick_file_names
*file_data
3329 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3330 if (file_data
== NULL
)
3333 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3335 const char *this_name
= file_data
->file_names
[j
];
3336 const char *this_real_name
;
3338 if (compare_filenames_for_search (this_name
, name
))
3340 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3346 /* Before we invoke realpath, which can get expensive when many
3347 files are involved, do a quick comparison of the basenames. */
3348 if (! basenames_may_differ
3349 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3352 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3354 if (compare_filenames_for_search (this_real_name
, name
))
3356 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3362 if (real_path
!= NULL
)
3364 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3365 gdb_assert (IS_ABSOLUTE_PATH (name
));
3366 if (this_real_name
!= NULL
3367 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3369 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3381 /* Struct used to manage iterating over all CUs looking for a symbol. */
3383 struct dw2_symtab_iterator
3385 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3386 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3387 /* If set, only look for symbols that match that block. Valid values are
3388 GLOBAL_BLOCK and STATIC_BLOCK. */
3389 gdb::optional
<block_enum
> block_index
;
3390 /* The kind of symbol we're looking for. */
3392 /* The list of CUs from the index entry of the symbol,
3393 or NULL if not found. */
3395 /* The next element in VEC to look at. */
3397 /* The number of elements in VEC, or zero if there is no match. */
3399 /* Have we seen a global version of the symbol?
3400 If so we can ignore all further global instances.
3401 This is to work around gold/15646, inefficient gold-generated
3406 /* Initialize the index symtab iterator ITER. */
3409 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3410 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3411 gdb::optional
<block_enum
> block_index
,
3415 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3416 iter
->block_index
= block_index
;
3417 iter
->domain
= domain
;
3419 iter
->global_seen
= 0;
3421 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3423 /* index is NULL if OBJF_READNOW. */
3424 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3425 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3433 /* Return the next matching CU or NULL if there are no more. */
3435 static struct dwarf2_per_cu_data
*
3436 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3438 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3440 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3442 offset_type cu_index_and_attrs
=
3443 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3444 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3445 gdb_index_symbol_kind symbol_kind
=
3446 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3447 /* Only check the symbol attributes if they're present.
3448 Indices prior to version 7 don't record them,
3449 and indices >= 7 may elide them for certain symbols
3450 (gold does this). */
3452 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3453 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3455 /* Don't crash on bad data. */
3456 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3457 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3459 complaint (_(".gdb_index entry has bad CU index"
3461 objfile_name (dwarf2_per_objfile
->objfile
));
3465 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3467 /* Skip if already read in. */
3468 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3471 /* Check static vs global. */
3474 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3476 if (iter
->block_index
.has_value ())
3478 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3480 if (is_static
!= want_static
)
3484 /* Work around gold/15646. */
3485 if (!is_static
&& iter
->global_seen
)
3488 iter
->global_seen
= 1;
3491 /* Only check the symbol's kind if it has one. */
3494 switch (iter
->domain
)
3497 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3498 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3499 /* Some types are also in VAR_DOMAIN. */
3500 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3504 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3508 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3512 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3527 static struct compunit_symtab
*
3528 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3529 const char *name
, domain_enum domain
)
3531 struct compunit_symtab
*stab_best
= NULL
;
3532 struct dwarf2_per_objfile
*dwarf2_per_objfile
3533 = get_dwarf2_per_objfile (objfile
);
3535 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3537 struct dw2_symtab_iterator iter
;
3538 struct dwarf2_per_cu_data
*per_cu
;
3540 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3542 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3544 struct symbol
*sym
, *with_opaque
= NULL
;
3545 struct compunit_symtab
*stab
3546 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3547 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3548 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3550 sym
= block_find_symbol (block
, name
, domain
,
3551 block_find_non_opaque_type_preferred
,
3554 /* Some caution must be observed with overloaded functions
3555 and methods, since the index will not contain any overload
3556 information (but NAME might contain it). */
3559 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3561 if (with_opaque
!= NULL
3562 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3565 /* Keep looking through other CUs. */
3572 dw2_print_stats (struct objfile
*objfile
)
3574 struct dwarf2_per_objfile
*dwarf2_per_objfile
3575 = get_dwarf2_per_objfile (objfile
);
3576 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3577 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3580 for (int i
= 0; i
< total
; ++i
)
3582 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3584 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3587 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3588 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3591 /* This dumps minimal information about the index.
3592 It is called via "mt print objfiles".
3593 One use is to verify .gdb_index has been loaded by the
3594 gdb.dwarf2/gdb-index.exp testcase. */
3597 dw2_dump (struct objfile
*objfile
)
3599 struct dwarf2_per_objfile
*dwarf2_per_objfile
3600 = get_dwarf2_per_objfile (objfile
);
3602 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3603 printf_filtered (".gdb_index:");
3604 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3606 printf_filtered (" version %d\n",
3607 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3610 printf_filtered (" faked for \"readnow\"\n");
3611 printf_filtered ("\n");
3615 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3616 const char *func_name
)
3618 struct dwarf2_per_objfile
*dwarf2_per_objfile
3619 = get_dwarf2_per_objfile (objfile
);
3621 struct dw2_symtab_iterator iter
;
3622 struct dwarf2_per_cu_data
*per_cu
;
3624 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3626 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3627 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3632 dw2_expand_all_symtabs (struct objfile
*objfile
)
3634 struct dwarf2_per_objfile
*dwarf2_per_objfile
3635 = get_dwarf2_per_objfile (objfile
);
3636 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3637 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3639 for (int i
= 0; i
< total_units
; ++i
)
3641 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3643 /* We don't want to directly expand a partial CU, because if we
3644 read it with the wrong language, then assertion failures can
3645 be triggered later on. See PR symtab/23010. So, tell
3646 dw2_instantiate_symtab to skip partial CUs -- any important
3647 partial CU will be read via DW_TAG_imported_unit anyway. */
3648 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, true);
3653 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3654 const char *fullname
)
3656 struct dwarf2_per_objfile
*dwarf2_per_objfile
3657 = get_dwarf2_per_objfile (objfile
);
3659 /* We don't need to consider type units here.
3660 This is only called for examining code, e.g. expand_line_sal.
3661 There can be an order of magnitude (or more) more type units
3662 than comp units, and we avoid them if we can. */
3664 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3666 /* We only need to look at symtabs not already expanded. */
3667 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3670 quick_file_names
*file_data
3671 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3672 if (file_data
== NULL
)
3675 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3677 const char *this_fullname
= file_data
->file_names
[j
];
3679 if (filename_cmp (this_fullname
, fullname
) == 0)
3681 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3689 dw2_expand_symtabs_matching_symbol
3690 (mapped_index_base
&index
,
3691 const lookup_name_info
&lookup_name_in
,
3692 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3693 enum search_domain kind
,
3694 gdb::function_view
<bool (offset_type
)> match_callback
);
3697 dw2_expand_symtabs_matching_one
3698 (dwarf2_per_cu_data
*per_cu
,
3699 dwarf2_per_objfile
*per_objfile
,
3700 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3701 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3704 dw2_map_matching_symbols
3705 (struct objfile
*objfile
,
3706 const lookup_name_info
&name
, domain_enum domain
,
3708 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3709 symbol_compare_ftype
*ordered_compare
)
3712 struct dwarf2_per_objfile
*dwarf2_per_objfile
3713 = get_dwarf2_per_objfile (objfile
);
3715 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3717 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3719 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3720 here though if the current language is Ada for a non-Ada objfile
3722 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3724 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3725 auto matcher
= [&] (const char *symname
)
3727 if (ordered_compare
== nullptr)
3729 return ordered_compare (symname
, match_name
) == 0;
3732 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3733 [&] (offset_type namei
)
3735 struct dw2_symtab_iterator iter
;
3736 struct dwarf2_per_cu_data
*per_cu
;
3738 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3740 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3741 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
3748 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3749 proceed assuming all symtabs have been read in. */
3752 for (compunit_symtab
*cust
: objfile
->compunits ())
3754 const struct block
*block
;
3758 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3759 if (!iterate_over_symbols_terminated (block
, name
,
3765 /* Starting from a search name, return the string that finds the upper
3766 bound of all strings that start with SEARCH_NAME in a sorted name
3767 list. Returns the empty string to indicate that the upper bound is
3768 the end of the list. */
3771 make_sort_after_prefix_name (const char *search_name
)
3773 /* When looking to complete "func", we find the upper bound of all
3774 symbols that start with "func" by looking for where we'd insert
3775 the closest string that would follow "func" in lexicographical
3776 order. Usually, that's "func"-with-last-character-incremented,
3777 i.e. "fund". Mind non-ASCII characters, though. Usually those
3778 will be UTF-8 multi-byte sequences, but we can't be certain.
3779 Especially mind the 0xff character, which is a valid character in
3780 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3781 rule out compilers allowing it in identifiers. Note that
3782 conveniently, strcmp/strcasecmp are specified to compare
3783 characters interpreted as unsigned char. So what we do is treat
3784 the whole string as a base 256 number composed of a sequence of
3785 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3786 to 0, and carries 1 to the following more-significant position.
3787 If the very first character in SEARCH_NAME ends up incremented
3788 and carries/overflows, then the upper bound is the end of the
3789 list. The string after the empty string is also the empty
3792 Some examples of this operation:
3794 SEARCH_NAME => "+1" RESULT
3798 "\xff" "a" "\xff" => "\xff" "b"
3803 Then, with these symbols for example:
3809 completing "func" looks for symbols between "func" and
3810 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3811 which finds "func" and "func1", but not "fund".
3815 funcÿ (Latin1 'ÿ' [0xff])
3819 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3820 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3824 ÿÿ (Latin1 'ÿ' [0xff])
3827 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3828 the end of the list.
3830 std::string after
= search_name
;
3831 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3833 if (!after
.empty ())
3834 after
.back () = (unsigned char) after
.back () + 1;
3838 /* See declaration. */
3840 std::pair
<std::vector
<name_component
>::const_iterator
,
3841 std::vector
<name_component
>::const_iterator
>
3842 mapped_index_base::find_name_components_bounds
3843 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3846 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3848 const char *lang_name
3849 = lookup_name_without_params
.language_lookup_name (lang
);
3851 /* Comparison function object for lower_bound that matches against a
3852 given symbol name. */
3853 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3856 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3857 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3858 return name_cmp (elem_name
, name
) < 0;
3861 /* Comparison function object for upper_bound that matches against a
3862 given symbol name. */
3863 auto lookup_compare_upper
= [&] (const char *name
,
3864 const name_component
&elem
)
3866 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3867 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3868 return name_cmp (name
, elem_name
) < 0;
3871 auto begin
= this->name_components
.begin ();
3872 auto end
= this->name_components
.end ();
3874 /* Find the lower bound. */
3877 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3880 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3883 /* Find the upper bound. */
3886 if (lookup_name_without_params
.completion_mode ())
3888 /* In completion mode, we want UPPER to point past all
3889 symbols names that have the same prefix. I.e., with
3890 these symbols, and completing "func":
3892 function << lower bound
3894 other_function << upper bound
3896 We find the upper bound by looking for the insertion
3897 point of "func"-with-last-character-incremented,
3899 std::string after
= make_sort_after_prefix_name (lang_name
);
3902 return std::lower_bound (lower
, end
, after
.c_str (),
3903 lookup_compare_lower
);
3906 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3909 return {lower
, upper
};
3912 /* See declaration. */
3915 mapped_index_base::build_name_components ()
3917 if (!this->name_components
.empty ())
3920 this->name_components_casing
= case_sensitivity
;
3922 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3924 /* The code below only knows how to break apart components of C++
3925 symbol names (and other languages that use '::' as
3926 namespace/module separator) and Ada symbol names. */
3927 auto count
= this->symbol_name_count ();
3928 for (offset_type idx
= 0; idx
< count
; idx
++)
3930 if (this->symbol_name_slot_invalid (idx
))
3933 const char *name
= this->symbol_name_at (idx
);
3935 /* Add each name component to the name component table. */
3936 unsigned int previous_len
= 0;
3938 if (strstr (name
, "::") != nullptr)
3940 for (unsigned int current_len
= cp_find_first_component (name
);
3941 name
[current_len
] != '\0';
3942 current_len
+= cp_find_first_component (name
+ current_len
))
3944 gdb_assert (name
[current_len
] == ':');
3945 this->name_components
.push_back ({previous_len
, idx
});
3946 /* Skip the '::'. */
3948 previous_len
= current_len
;
3953 /* Handle the Ada encoded (aka mangled) form here. */
3954 for (const char *iter
= strstr (name
, "__");
3956 iter
= strstr (iter
, "__"))
3958 this->name_components
.push_back ({previous_len
, idx
});
3960 previous_len
= iter
- name
;
3964 this->name_components
.push_back ({previous_len
, idx
});
3967 /* Sort name_components elements by name. */
3968 auto name_comp_compare
= [&] (const name_component
&left
,
3969 const name_component
&right
)
3971 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3972 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3974 const char *left_name
= left_qualified
+ left
.name_offset
;
3975 const char *right_name
= right_qualified
+ right
.name_offset
;
3977 return name_cmp (left_name
, right_name
) < 0;
3980 std::sort (this->name_components
.begin (),
3981 this->name_components
.end (),
3985 /* Helper for dw2_expand_symtabs_matching that works with a
3986 mapped_index_base instead of the containing objfile. This is split
3987 to a separate function in order to be able to unit test the
3988 name_components matching using a mock mapped_index_base. For each
3989 symbol name that matches, calls MATCH_CALLBACK, passing it the
3990 symbol's index in the mapped_index_base symbol table. */
3993 dw2_expand_symtabs_matching_symbol
3994 (mapped_index_base
&index
,
3995 const lookup_name_info
&lookup_name_in
,
3996 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3997 enum search_domain kind
,
3998 gdb::function_view
<bool (offset_type
)> match_callback
)
4000 lookup_name_info lookup_name_without_params
4001 = lookup_name_in
.make_ignore_params ();
4003 /* Build the symbol name component sorted vector, if we haven't
4005 index
.build_name_components ();
4007 /* The same symbol may appear more than once in the range though.
4008 E.g., if we're looking for symbols that complete "w", and we have
4009 a symbol named "w1::w2", we'll find the two name components for
4010 that same symbol in the range. To be sure we only call the
4011 callback once per symbol, we first collect the symbol name
4012 indexes that matched in a temporary vector and ignore
4014 std::vector
<offset_type
> matches
;
4016 struct name_and_matcher
4018 symbol_name_matcher_ftype
*matcher
;
4021 bool operator== (const name_and_matcher
&other
) const
4023 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4027 /* A vector holding all the different symbol name matchers, for all
4029 std::vector
<name_and_matcher
> matchers
;
4031 for (int i
= 0; i
< nr_languages
; i
++)
4033 enum language lang_e
= (enum language
) i
;
4035 const language_defn
*lang
= language_def (lang_e
);
4036 symbol_name_matcher_ftype
*name_matcher
4037 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4039 name_and_matcher key
{
4041 lookup_name_without_params
.language_lookup_name (lang_e
)
4044 /* Don't insert the same comparison routine more than once.
4045 Note that we do this linear walk. This is not a problem in
4046 practice because the number of supported languages is
4048 if (std::find (matchers
.begin (), matchers
.end (), key
)
4051 matchers
.push_back (std::move (key
));
4054 = index
.find_name_components_bounds (lookup_name_without_params
,
4057 /* Now for each symbol name in range, check to see if we have a name
4058 match, and if so, call the MATCH_CALLBACK callback. */
4060 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4062 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4064 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4065 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4068 matches
.push_back (bounds
.first
->idx
);
4072 std::sort (matches
.begin (), matches
.end ());
4074 /* Finally call the callback, once per match. */
4076 for (offset_type idx
: matches
)
4080 if (!match_callback (idx
))
4086 /* Above we use a type wider than idx's for 'prev', since 0 and
4087 (offset_type)-1 are both possible values. */
4088 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4093 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4095 /* A mock .gdb_index/.debug_names-like name index table, enough to
4096 exercise dw2_expand_symtabs_matching_symbol, which works with the
4097 mapped_index_base interface. Builds an index from the symbol list
4098 passed as parameter to the constructor. */
4099 class mock_mapped_index
: public mapped_index_base
4102 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4103 : m_symbol_table (symbols
)
4106 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4108 /* Return the number of names in the symbol table. */
4109 size_t symbol_name_count () const override
4111 return m_symbol_table
.size ();
4114 /* Get the name of the symbol at IDX in the symbol table. */
4115 const char *symbol_name_at (offset_type idx
) const override
4117 return m_symbol_table
[idx
];
4121 gdb::array_view
<const char *> m_symbol_table
;
4124 /* Convenience function that converts a NULL pointer to a "<null>"
4125 string, to pass to print routines. */
4128 string_or_null (const char *str
)
4130 return str
!= NULL
? str
: "<null>";
4133 /* Check if a lookup_name_info built from
4134 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4135 index. EXPECTED_LIST is the list of expected matches, in expected
4136 matching order. If no match expected, then an empty list is
4137 specified. Returns true on success. On failure prints a warning
4138 indicating the file:line that failed, and returns false. */
4141 check_match (const char *file
, int line
,
4142 mock_mapped_index
&mock_index
,
4143 const char *name
, symbol_name_match_type match_type
,
4144 bool completion_mode
,
4145 std::initializer_list
<const char *> expected_list
)
4147 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4149 bool matched
= true;
4151 auto mismatch
= [&] (const char *expected_str
,
4154 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4155 "expected=\"%s\", got=\"%s\"\n"),
4157 (match_type
== symbol_name_match_type::FULL
4159 name
, string_or_null (expected_str
), string_or_null (got
));
4163 auto expected_it
= expected_list
.begin ();
4164 auto expected_end
= expected_list
.end ();
4166 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4168 [&] (offset_type idx
)
4170 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4171 const char *expected_str
4172 = expected_it
== expected_end
? NULL
: *expected_it
++;
4174 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4175 mismatch (expected_str
, matched_name
);
4179 const char *expected_str
4180 = expected_it
== expected_end
? NULL
: *expected_it
++;
4181 if (expected_str
!= NULL
)
4182 mismatch (expected_str
, NULL
);
4187 /* The symbols added to the mock mapped_index for testing (in
4189 static const char *test_symbols
[] = {
4198 "ns2::tmpl<int>::foo2",
4199 "(anonymous namespace)::A::B::C",
4201 /* These are used to check that the increment-last-char in the
4202 matching algorithm for completion doesn't match "t1_fund" when
4203 completing "t1_func". */
4209 /* A UTF-8 name with multi-byte sequences to make sure that
4210 cp-name-parser understands this as a single identifier ("função"
4211 is "function" in PT). */
4214 /* \377 (0xff) is Latin1 'ÿ'. */
4217 /* \377 (0xff) is Latin1 'ÿ'. */
4221 /* A name with all sorts of complications. Starts with "z" to make
4222 it easier for the completion tests below. */
4223 #define Z_SYM_NAME \
4224 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4225 "::tuple<(anonymous namespace)::ui*, " \
4226 "std::default_delete<(anonymous namespace)::ui>, void>"
4231 /* Returns true if the mapped_index_base::find_name_component_bounds
4232 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4233 in completion mode. */
4236 check_find_bounds_finds (mapped_index_base
&index
,
4237 const char *search_name
,
4238 gdb::array_view
<const char *> expected_syms
)
4240 lookup_name_info
lookup_name (search_name
,
4241 symbol_name_match_type::FULL
, true);
4243 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4246 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4247 if (distance
!= expected_syms
.size ())
4250 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4252 auto nc_elem
= bounds
.first
+ exp_elem
;
4253 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4254 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4261 /* Test the lower-level mapped_index::find_name_component_bounds
4265 test_mapped_index_find_name_component_bounds ()
4267 mock_mapped_index
mock_index (test_symbols
);
4269 mock_index
.build_name_components ();
4271 /* Test the lower-level mapped_index::find_name_component_bounds
4272 method in completion mode. */
4274 static const char *expected_syms
[] = {
4279 SELF_CHECK (check_find_bounds_finds (mock_index
,
4280 "t1_func", expected_syms
));
4283 /* Check that the increment-last-char in the name matching algorithm
4284 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4286 static const char *expected_syms1
[] = {
4290 SELF_CHECK (check_find_bounds_finds (mock_index
,
4291 "\377", expected_syms1
));
4293 static const char *expected_syms2
[] = {
4296 SELF_CHECK (check_find_bounds_finds (mock_index
,
4297 "\377\377", expected_syms2
));
4301 /* Test dw2_expand_symtabs_matching_symbol. */
4304 test_dw2_expand_symtabs_matching_symbol ()
4306 mock_mapped_index
mock_index (test_symbols
);
4308 /* We let all tests run until the end even if some fails, for debug
4310 bool any_mismatch
= false;
4312 /* Create the expected symbols list (an initializer_list). Needed
4313 because lists have commas, and we need to pass them to CHECK,
4314 which is a macro. */
4315 #define EXPECT(...) { __VA_ARGS__ }
4317 /* Wrapper for check_match that passes down the current
4318 __FILE__/__LINE__. */
4319 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4320 any_mismatch |= !check_match (__FILE__, __LINE__, \
4322 NAME, MATCH_TYPE, COMPLETION_MODE, \
4325 /* Identity checks. */
4326 for (const char *sym
: test_symbols
)
4328 /* Should be able to match all existing symbols. */
4329 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4332 /* Should be able to match all existing symbols with
4334 std::string with_params
= std::string (sym
) + "(int)";
4335 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4338 /* Should be able to match all existing symbols with
4339 parameters and qualifiers. */
4340 with_params
= std::string (sym
) + " ( int ) const";
4341 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4344 /* This should really find sym, but cp-name-parser.y doesn't
4345 know about lvalue/rvalue qualifiers yet. */
4346 with_params
= std::string (sym
) + " ( int ) &&";
4347 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4351 /* Check that the name matching algorithm for completion doesn't get
4352 confused with Latin1 'ÿ' / 0xff. */
4354 static const char str
[] = "\377";
4355 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4356 EXPECT ("\377", "\377\377123"));
4359 /* Check that the increment-last-char in the matching algorithm for
4360 completion doesn't match "t1_fund" when completing "t1_func". */
4362 static const char str
[] = "t1_func";
4363 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4364 EXPECT ("t1_func", "t1_func1"));
4367 /* Check that completion mode works at each prefix of the expected
4370 static const char str
[] = "function(int)";
4371 size_t len
= strlen (str
);
4374 for (size_t i
= 1; i
< len
; i
++)
4376 lookup
.assign (str
, i
);
4377 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4378 EXPECT ("function"));
4382 /* While "w" is a prefix of both components, the match function
4383 should still only be called once. */
4385 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4387 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4391 /* Same, with a "complicated" symbol. */
4393 static const char str
[] = Z_SYM_NAME
;
4394 size_t len
= strlen (str
);
4397 for (size_t i
= 1; i
< len
; i
++)
4399 lookup
.assign (str
, i
);
4400 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4401 EXPECT (Z_SYM_NAME
));
4405 /* In FULL mode, an incomplete symbol doesn't match. */
4407 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4411 /* A complete symbol with parameters matches any overload, since the
4412 index has no overload info. */
4414 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4415 EXPECT ("std::zfunction", "std::zfunction2"));
4416 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4417 EXPECT ("std::zfunction", "std::zfunction2"));
4418 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4419 EXPECT ("std::zfunction", "std::zfunction2"));
4422 /* Check that whitespace is ignored appropriately. A symbol with a
4423 template argument list. */
4425 static const char expected
[] = "ns::foo<int>";
4426 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4428 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4432 /* Check that whitespace is ignored appropriately. A symbol with a
4433 template argument list that includes a pointer. */
4435 static const char expected
[] = "ns::foo<char*>";
4436 /* Try both completion and non-completion modes. */
4437 static const bool completion_mode
[2] = {false, true};
4438 for (size_t i
= 0; i
< 2; i
++)
4440 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4441 completion_mode
[i
], EXPECT (expected
));
4442 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4443 completion_mode
[i
], EXPECT (expected
));
4445 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4446 completion_mode
[i
], EXPECT (expected
));
4447 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4448 completion_mode
[i
], EXPECT (expected
));
4453 /* Check method qualifiers are ignored. */
4454 static const char expected
[] = "ns::foo<char*>";
4455 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4456 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4457 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4458 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4459 CHECK_MATCH ("foo < char * > ( int ) const",
4460 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4461 CHECK_MATCH ("foo < char * > ( int ) &&",
4462 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4465 /* Test lookup names that don't match anything. */
4467 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4470 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4474 /* Some wild matching tests, exercising "(anonymous namespace)",
4475 which should not be confused with a parameter list. */
4477 static const char *syms
[] = {
4481 "A :: B :: C ( int )",
4486 for (const char *s
: syms
)
4488 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4489 EXPECT ("(anonymous namespace)::A::B::C"));
4494 static const char expected
[] = "ns2::tmpl<int>::foo2";
4495 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4497 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4501 SELF_CHECK (!any_mismatch
);
4510 test_mapped_index_find_name_component_bounds ();
4511 test_dw2_expand_symtabs_matching_symbol ();
4514 }} // namespace selftests::dw2_expand_symtabs_matching
4516 #endif /* GDB_SELF_TEST */
4518 /* If FILE_MATCHER is NULL or if PER_CU has
4519 dwarf2_per_cu_quick_data::MARK set (see
4520 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4521 EXPANSION_NOTIFY on it. */
4524 dw2_expand_symtabs_matching_one
4525 (dwarf2_per_cu_data
*per_cu
,
4526 dwarf2_per_objfile
*per_objfile
,
4527 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4528 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4530 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4532 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4534 compunit_symtab
*symtab
4535 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4536 gdb_assert (symtab
!= nullptr);
4538 if (expansion_notify
!= NULL
&& symtab_was_null
)
4539 expansion_notify (symtab
);
4543 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4544 matched, to expand corresponding CUs that were marked. IDX is the
4545 index of the symbol name that matched. */
4548 dw2_expand_marked_cus
4549 (dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4550 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4551 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4554 offset_type
*vec
, vec_len
, vec_idx
;
4555 bool global_seen
= false;
4556 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4558 vec
= (offset_type
*) (index
.constant_pool
4559 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4560 vec_len
= MAYBE_SWAP (vec
[0]);
4561 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4563 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4564 /* This value is only valid for index versions >= 7. */
4565 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4566 gdb_index_symbol_kind symbol_kind
=
4567 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4568 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4569 /* Only check the symbol attributes if they're present.
4570 Indices prior to version 7 don't record them,
4571 and indices >= 7 may elide them for certain symbols
4572 (gold does this). */
4575 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4577 /* Work around gold/15646. */
4580 if (!is_static
&& global_seen
)
4586 /* Only check the symbol's kind if it has one. */
4591 case VARIABLES_DOMAIN
:
4592 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4595 case FUNCTIONS_DOMAIN
:
4596 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4600 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4603 case MODULES_DOMAIN
:
4604 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4612 /* Don't crash on bad data. */
4613 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4614 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4616 complaint (_(".gdb_index entry has bad CU index"
4618 objfile_name (dwarf2_per_objfile
->objfile
));
4622 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4623 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, file_matcher
,
4628 /* If FILE_MATCHER is non-NULL, set all the
4629 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4630 that match FILE_MATCHER. */
4633 dw_expand_symtabs_matching_file_matcher
4634 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4635 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4637 if (file_matcher
== NULL
)
4640 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4642 NULL
, xcalloc
, xfree
));
4643 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4645 NULL
, xcalloc
, xfree
));
4647 /* The rule is CUs specify all the files, including those used by
4648 any TU, so there's no need to scan TUs here. */
4650 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4654 per_cu
->v
.quick
->mark
= 0;
4656 /* We only need to look at symtabs not already expanded. */
4657 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4660 quick_file_names
*file_data
4661 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4662 if (file_data
== NULL
)
4665 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4667 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4669 per_cu
->v
.quick
->mark
= 1;
4673 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4675 const char *this_real_name
;
4677 if (file_matcher (file_data
->file_names
[j
], false))
4679 per_cu
->v
.quick
->mark
= 1;
4683 /* Before we invoke realpath, which can get expensive when many
4684 files are involved, do a quick comparison of the basenames. */
4685 if (!basenames_may_differ
4686 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4690 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4692 if (file_matcher (this_real_name
, false))
4694 per_cu
->v
.quick
->mark
= 1;
4699 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4700 ? visited_found
.get ()
4701 : visited_not_found
.get (),
4708 dw2_expand_symtabs_matching
4709 (struct objfile
*objfile
,
4710 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4711 const lookup_name_info
*lookup_name
,
4712 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4713 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4714 enum search_domain kind
)
4716 struct dwarf2_per_objfile
*dwarf2_per_objfile
4717 = get_dwarf2_per_objfile (objfile
);
4719 /* index_table is NULL if OBJF_READNOW. */
4720 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4723 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4725 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4727 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4731 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
4732 file_matcher
, expansion_notify
);
4737 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4739 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4741 kind
, [&] (offset_type idx
)
4743 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4744 expansion_notify
, kind
);
4749 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4752 static struct compunit_symtab
*
4753 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4758 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4759 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4762 if (cust
->includes
== NULL
)
4765 for (i
= 0; cust
->includes
[i
]; ++i
)
4767 struct compunit_symtab
*s
= cust
->includes
[i
];
4769 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4777 static struct compunit_symtab
*
4778 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4779 struct bound_minimal_symbol msymbol
,
4781 struct obj_section
*section
,
4784 struct dwarf2_per_cu_data
*data
;
4785 struct compunit_symtab
*result
;
4787 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4790 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4791 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4792 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4796 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4797 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4798 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4799 paddress (objfile
->arch (), pc
));
4801 result
= recursively_find_pc_sect_compunit_symtab
4802 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4804 gdb_assert (result
!= NULL
);
4809 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4810 void *data
, int need_fullname
)
4812 struct dwarf2_per_objfile
*dwarf2_per_objfile
4813 = get_dwarf2_per_objfile (objfile
);
4815 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4817 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4819 htab_up
visited (htab_create_alloc (10,
4820 htab_hash_pointer
, htab_eq_pointer
,
4821 NULL
, xcalloc
, xfree
));
4823 /* The rule is CUs specify all the files, including those used
4824 by any TU, so there's no need to scan TUs here. We can
4825 ignore file names coming from already-expanded CUs. */
4827 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4829 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4831 void **slot
= htab_find_slot (visited
.get (),
4832 per_cu
->v
.quick
->file_names
,
4835 *slot
= per_cu
->v
.quick
->file_names
;
4839 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4841 /* We only need to look at symtabs not already expanded. */
4842 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4845 quick_file_names
*file_data
4846 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4847 if (file_data
== NULL
)
4850 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4853 /* Already visited. */
4858 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4860 const char *filename
= file_data
->file_names
[j
];
4861 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4866 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4868 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4871 this_real_name
= gdb_realpath (filename
);
4872 (*fun
) (filename
, this_real_name
.get (), data
);
4877 dw2_has_symbols (struct objfile
*objfile
)
4882 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4885 dw2_find_last_source_symtab
,
4886 dw2_forget_cached_source_info
,
4887 dw2_map_symtabs_matching_filename
,
4892 dw2_expand_symtabs_for_function
,
4893 dw2_expand_all_symtabs
,
4894 dw2_expand_symtabs_with_fullname
,
4895 dw2_map_matching_symbols
,
4896 dw2_expand_symtabs_matching
,
4897 dw2_find_pc_sect_compunit_symtab
,
4899 dw2_map_symbol_filenames
4902 /* DWARF-5 debug_names reader. */
4904 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4905 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4907 /* A helper function that reads the .debug_names section in SECTION
4908 and fills in MAP. FILENAME is the name of the file containing the
4909 section; it is used for error reporting.
4911 Returns true if all went well, false otherwise. */
4914 read_debug_names_from_section (struct objfile
*objfile
,
4915 const char *filename
,
4916 struct dwarf2_section_info
*section
,
4917 mapped_debug_names
&map
)
4919 if (section
->empty ())
4922 /* Older elfutils strip versions could keep the section in the main
4923 executable while splitting it for the separate debug info file. */
4924 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4927 section
->read (objfile
);
4929 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4931 const gdb_byte
*addr
= section
->buffer
;
4933 bfd
*const abfd
= section
->get_bfd_owner ();
4935 unsigned int bytes_read
;
4936 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4939 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4940 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4941 if (bytes_read
+ length
!= section
->size
)
4943 /* There may be multiple per-CU indices. */
4944 warning (_("Section .debug_names in %s length %s does not match "
4945 "section length %s, ignoring .debug_names."),
4946 filename
, plongest (bytes_read
+ length
),
4947 pulongest (section
->size
));
4951 /* The version number. */
4952 uint16_t version
= read_2_bytes (abfd
, addr
);
4956 warning (_("Section .debug_names in %s has unsupported version %d, "
4957 "ignoring .debug_names."),
4963 uint16_t padding
= read_2_bytes (abfd
, addr
);
4967 warning (_("Section .debug_names in %s has unsupported padding %d, "
4968 "ignoring .debug_names."),
4973 /* comp_unit_count - The number of CUs in the CU list. */
4974 map
.cu_count
= read_4_bytes (abfd
, addr
);
4977 /* local_type_unit_count - The number of TUs in the local TU
4979 map
.tu_count
= read_4_bytes (abfd
, addr
);
4982 /* foreign_type_unit_count - The number of TUs in the foreign TU
4984 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4986 if (foreign_tu_count
!= 0)
4988 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4989 "ignoring .debug_names."),
4990 filename
, static_cast<unsigned long> (foreign_tu_count
));
4994 /* bucket_count - The number of hash buckets in the hash lookup
4996 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4999 /* name_count - The number of unique names in the index. */
5000 map
.name_count
= read_4_bytes (abfd
, addr
);
5003 /* abbrev_table_size - The size in bytes of the abbreviations
5005 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5008 /* augmentation_string_size - The size in bytes of the augmentation
5009 string. This value is rounded up to a multiple of 4. */
5010 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5012 map
.augmentation_is_gdb
= ((augmentation_string_size
5013 == sizeof (dwarf5_augmentation
))
5014 && memcmp (addr
, dwarf5_augmentation
,
5015 sizeof (dwarf5_augmentation
)) == 0);
5016 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5017 addr
+= augmentation_string_size
;
5020 map
.cu_table_reordered
= addr
;
5021 addr
+= map
.cu_count
* map
.offset_size
;
5023 /* List of Local TUs */
5024 map
.tu_table_reordered
= addr
;
5025 addr
+= map
.tu_count
* map
.offset_size
;
5027 /* Hash Lookup Table */
5028 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5029 addr
+= map
.bucket_count
* 4;
5030 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5031 addr
+= map
.name_count
* 4;
5034 map
.name_table_string_offs_reordered
= addr
;
5035 addr
+= map
.name_count
* map
.offset_size
;
5036 map
.name_table_entry_offs_reordered
= addr
;
5037 addr
+= map
.name_count
* map
.offset_size
;
5039 const gdb_byte
*abbrev_table_start
= addr
;
5042 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5047 const auto insertpair
5048 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5049 if (!insertpair
.second
)
5051 warning (_("Section .debug_names in %s has duplicate index %s, "
5052 "ignoring .debug_names."),
5053 filename
, pulongest (index_num
));
5056 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5057 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5062 mapped_debug_names::index_val::attr attr
;
5063 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5065 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5067 if (attr
.form
== DW_FORM_implicit_const
)
5069 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5073 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5075 indexval
.attr_vec
.push_back (std::move (attr
));
5078 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5080 warning (_("Section .debug_names in %s has abbreviation_table "
5081 "of size %s vs. written as %u, ignoring .debug_names."),
5082 filename
, plongest (addr
- abbrev_table_start
),
5086 map
.entry_pool
= addr
;
5091 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5095 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5096 const mapped_debug_names
&map
,
5097 dwarf2_section_info
§ion
,
5100 if (!map
.augmentation_is_gdb
)
5102 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5104 sect_offset sect_off
5105 = (sect_offset
) (extract_unsigned_integer
5106 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5108 map
.dwarf5_byte_order
));
5109 /* We don't know the length of the CU, because the CU list in a
5110 .debug_names index can be incomplete, so we can't use the start of
5111 the next CU as end of this CU. We create the CUs here with length 0,
5112 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5113 dwarf2_per_cu_data
*per_cu
5114 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5115 per_bfd
->all_comp_units
.push_back (per_cu
);
5119 sect_offset sect_off_prev
;
5120 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5122 sect_offset sect_off_next
;
5123 if (i
< map
.cu_count
)
5126 = (sect_offset
) (extract_unsigned_integer
5127 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5129 map
.dwarf5_byte_order
));
5132 sect_off_next
= (sect_offset
) section
.size
;
5135 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5136 dwarf2_per_cu_data
*per_cu
5137 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5138 sect_off_prev
, length
);
5139 per_bfd
->all_comp_units
.push_back (per_cu
);
5141 sect_off_prev
= sect_off_next
;
5145 /* Read the CU list from the mapped index, and use it to create all
5146 the CU objects for this dwarf2_per_objfile. */
5149 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5150 const mapped_debug_names
&map
,
5151 const mapped_debug_names
&dwz_map
)
5153 gdb_assert (per_bfd
->all_comp_units
.empty ());
5154 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5156 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5157 false /* is_dwz */);
5159 if (dwz_map
.cu_count
== 0)
5162 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5163 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5167 /* Read .debug_names. If everything went ok, initialize the "quick"
5168 elements of all the CUs and return true. Otherwise, return false. */
5171 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5173 std::unique_ptr
<mapped_debug_names
> map
5174 (new mapped_debug_names (dwarf2_per_objfile
));
5175 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5176 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5178 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5179 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5183 /* Don't use the index if it's empty. */
5184 if (map
->name_count
== 0)
5187 /* If there is a .dwz file, read it so we can get its CU list as
5189 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5192 if (!read_debug_names_from_section (objfile
,
5193 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5194 &dwz
->debug_names
, dwz_map
))
5196 warning (_("could not read '.debug_names' section from %s; skipping"),
5197 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5202 create_cus_from_debug_names (dwarf2_per_objfile
->per_bfd
, *map
, dwz_map
);
5204 if (map
->tu_count
!= 0)
5206 /* We can only handle a single .debug_types when we have an
5208 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5211 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5213 create_signatured_type_table_from_debug_names
5214 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5217 create_addrmap_from_aranges (dwarf2_per_objfile
,
5218 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5220 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5221 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5222 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5223 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5228 /* Type used to manage iterating over all CUs looking for a symbol for
5231 class dw2_debug_names_iterator
5234 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5235 gdb::optional
<block_enum
> block_index
,
5238 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5239 m_addr (find_vec_in_debug_names (map
, name
))
5242 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5243 search_domain search
, uint32_t namei
)
5246 m_addr (find_vec_in_debug_names (map
, namei
))
5249 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5250 block_enum block_index
, domain_enum domain
,
5252 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5253 m_addr (find_vec_in_debug_names (map
, namei
))
5256 /* Return the next matching CU or NULL if there are no more. */
5257 dwarf2_per_cu_data
*next ();
5260 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5262 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5265 /* The internalized form of .debug_names. */
5266 const mapped_debug_names
&m_map
;
5268 /* If set, only look for symbols that match that block. Valid values are
5269 GLOBAL_BLOCK and STATIC_BLOCK. */
5270 const gdb::optional
<block_enum
> m_block_index
;
5272 /* The kind of symbol we're looking for. */
5273 const domain_enum m_domain
= UNDEF_DOMAIN
;
5274 const search_domain m_search
= ALL_DOMAIN
;
5276 /* The list of CUs from the index entry of the symbol, or NULL if
5278 const gdb_byte
*m_addr
;
5282 mapped_debug_names::namei_to_name (uint32_t namei
) const
5284 const ULONGEST namei_string_offs
5285 = extract_unsigned_integer ((name_table_string_offs_reordered
5286 + namei
* offset_size
),
5289 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5293 /* Find a slot in .debug_names for the object named NAME. If NAME is
5294 found, return pointer to its pool data. If NAME cannot be found,
5298 dw2_debug_names_iterator::find_vec_in_debug_names
5299 (const mapped_debug_names
&map
, const char *name
)
5301 int (*cmp
) (const char *, const char *);
5303 gdb::unique_xmalloc_ptr
<char> without_params
;
5304 if (current_language
->la_language
== language_cplus
5305 || current_language
->la_language
== language_fortran
5306 || current_language
->la_language
== language_d
)
5308 /* NAME is already canonical. Drop any qualifiers as
5309 .debug_names does not contain any. */
5311 if (strchr (name
, '(') != NULL
)
5313 without_params
= cp_remove_params (name
);
5314 if (without_params
!= NULL
)
5315 name
= without_params
.get ();
5319 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5321 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5323 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5324 (map
.bucket_table_reordered
5325 + (full_hash
% map
.bucket_count
)), 4,
5326 map
.dwarf5_byte_order
);
5330 if (namei
>= map
.name_count
)
5332 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5334 namei
, map
.name_count
,
5335 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5341 const uint32_t namei_full_hash
5342 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5343 (map
.hash_table_reordered
+ namei
), 4,
5344 map
.dwarf5_byte_order
);
5345 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5348 if (full_hash
== namei_full_hash
)
5350 const char *const namei_string
= map
.namei_to_name (namei
);
5352 #if 0 /* An expensive sanity check. */
5353 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5355 complaint (_("Wrong .debug_names hash for string at index %u "
5357 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5362 if (cmp (namei_string
, name
) == 0)
5364 const ULONGEST namei_entry_offs
5365 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5366 + namei
* map
.offset_size
),
5367 map
.offset_size
, map
.dwarf5_byte_order
);
5368 return map
.entry_pool
+ namei_entry_offs
;
5373 if (namei
>= map
.name_count
)
5379 dw2_debug_names_iterator::find_vec_in_debug_names
5380 (const mapped_debug_names
&map
, uint32_t namei
)
5382 if (namei
>= map
.name_count
)
5384 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5386 namei
, map
.name_count
,
5387 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5391 const ULONGEST namei_entry_offs
5392 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5393 + namei
* map
.offset_size
),
5394 map
.offset_size
, map
.dwarf5_byte_order
);
5395 return map
.entry_pool
+ namei_entry_offs
;
5398 /* See dw2_debug_names_iterator. */
5400 dwarf2_per_cu_data
*
5401 dw2_debug_names_iterator::next ()
5406 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5407 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5408 bfd
*const abfd
= objfile
->obfd
;
5412 unsigned int bytes_read
;
5413 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5414 m_addr
+= bytes_read
;
5418 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5419 if (indexval_it
== m_map
.abbrev_map
.cend ())
5421 complaint (_("Wrong .debug_names undefined abbrev code %s "
5423 pulongest (abbrev
), objfile_name (objfile
));
5426 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5427 enum class symbol_linkage
{
5431 } symbol_linkage_
= symbol_linkage::unknown
;
5432 dwarf2_per_cu_data
*per_cu
= NULL
;
5433 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5438 case DW_FORM_implicit_const
:
5439 ull
= attr
.implicit_const
;
5441 case DW_FORM_flag_present
:
5445 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5446 m_addr
+= bytes_read
;
5449 ull
= read_4_bytes (abfd
, m_addr
);
5453 ull
= read_8_bytes (abfd
, m_addr
);
5456 case DW_FORM_ref_sig8
:
5457 ull
= read_8_bytes (abfd
, m_addr
);
5461 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5462 dwarf_form_name (attr
.form
),
5463 objfile_name (objfile
));
5466 switch (attr
.dw_idx
)
5468 case DW_IDX_compile_unit
:
5469 /* Don't crash on bad data. */
5470 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
5472 complaint (_(".debug_names entry has bad CU index %s"
5475 objfile_name (dwarf2_per_objfile
->objfile
));
5478 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (ull
);
5480 case DW_IDX_type_unit
:
5481 /* Don't crash on bad data. */
5482 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_type_units
.size ())
5484 complaint (_(".debug_names entry has bad TU index %s"
5487 objfile_name (dwarf2_per_objfile
->objfile
));
5490 per_cu
= &dwarf2_per_objfile
->per_bfd
->get_tu (ull
)->per_cu
;
5492 case DW_IDX_die_offset
:
5493 /* In a per-CU index (as opposed to a per-module index), index
5494 entries without CU attribute implicitly refer to the single CU. */
5496 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cu (0);
5498 case DW_IDX_GNU_internal
:
5499 if (!m_map
.augmentation_is_gdb
)
5501 symbol_linkage_
= symbol_linkage::static_
;
5503 case DW_IDX_GNU_external
:
5504 if (!m_map
.augmentation_is_gdb
)
5506 symbol_linkage_
= symbol_linkage::extern_
;
5511 /* Skip if already read in. */
5512 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
5515 /* Check static vs global. */
5516 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5518 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5519 const bool symbol_is_static
=
5520 symbol_linkage_
== symbol_linkage::static_
;
5521 if (want_static
!= symbol_is_static
)
5525 /* Match dw2_symtab_iter_next, symbol_kind
5526 and debug_names::psymbol_tag. */
5530 switch (indexval
.dwarf_tag
)
5532 case DW_TAG_variable
:
5533 case DW_TAG_subprogram
:
5534 /* Some types are also in VAR_DOMAIN. */
5535 case DW_TAG_typedef
:
5536 case DW_TAG_structure_type
:
5543 switch (indexval
.dwarf_tag
)
5545 case DW_TAG_typedef
:
5546 case DW_TAG_structure_type
:
5553 switch (indexval
.dwarf_tag
)
5556 case DW_TAG_variable
:
5563 switch (indexval
.dwarf_tag
)
5575 /* Match dw2_expand_symtabs_matching, symbol_kind and
5576 debug_names::psymbol_tag. */
5579 case VARIABLES_DOMAIN
:
5580 switch (indexval
.dwarf_tag
)
5582 case DW_TAG_variable
:
5588 case FUNCTIONS_DOMAIN
:
5589 switch (indexval
.dwarf_tag
)
5591 case DW_TAG_subprogram
:
5598 switch (indexval
.dwarf_tag
)
5600 case DW_TAG_typedef
:
5601 case DW_TAG_structure_type
:
5607 case MODULES_DOMAIN
:
5608 switch (indexval
.dwarf_tag
)
5622 static struct compunit_symtab
*
5623 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5624 const char *name
, domain_enum domain
)
5626 struct dwarf2_per_objfile
*dwarf2_per_objfile
5627 = get_dwarf2_per_objfile (objfile
);
5629 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5632 /* index is NULL if OBJF_READNOW. */
5635 const auto &map
= *mapp
;
5637 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5639 struct compunit_symtab
*stab_best
= NULL
;
5640 struct dwarf2_per_cu_data
*per_cu
;
5641 while ((per_cu
= iter
.next ()) != NULL
)
5643 struct symbol
*sym
, *with_opaque
= NULL
;
5644 compunit_symtab
*stab
5645 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5646 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5647 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5649 sym
= block_find_symbol (block
, name
, domain
,
5650 block_find_non_opaque_type_preferred
,
5653 /* Some caution must be observed with overloaded functions and
5654 methods, since the index will not contain any overload
5655 information (but NAME might contain it). */
5658 && strcmp_iw (sym
->search_name (), name
) == 0)
5660 if (with_opaque
!= NULL
5661 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5664 /* Keep looking through other CUs. */
5670 /* This dumps minimal information about .debug_names. It is called
5671 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5672 uses this to verify that .debug_names has been loaded. */
5675 dw2_debug_names_dump (struct objfile
*objfile
)
5677 struct dwarf2_per_objfile
*dwarf2_per_objfile
5678 = get_dwarf2_per_objfile (objfile
);
5680 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5681 printf_filtered (".debug_names:");
5682 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5683 printf_filtered (" exists\n");
5685 printf_filtered (" faked for \"readnow\"\n");
5686 printf_filtered ("\n");
5690 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5691 const char *func_name
)
5693 struct dwarf2_per_objfile
*dwarf2_per_objfile
5694 = get_dwarf2_per_objfile (objfile
);
5696 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5697 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5699 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5701 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5703 struct dwarf2_per_cu_data
*per_cu
;
5704 while ((per_cu
= iter
.next ()) != NULL
)
5705 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5710 dw2_debug_names_map_matching_symbols
5711 (struct objfile
*objfile
,
5712 const lookup_name_info
&name
, domain_enum domain
,
5714 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5715 symbol_compare_ftype
*ordered_compare
)
5717 struct dwarf2_per_objfile
*dwarf2_per_objfile
5718 = get_dwarf2_per_objfile (objfile
);
5720 /* debug_names_table is NULL if OBJF_READNOW. */
5721 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5724 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5725 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5727 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5728 auto matcher
= [&] (const char *symname
)
5730 if (ordered_compare
== nullptr)
5732 return ordered_compare (symname
, match_name
) == 0;
5735 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5736 [&] (offset_type namei
)
5738 /* The name was matched, now expand corresponding CUs that were
5740 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5742 struct dwarf2_per_cu_data
*per_cu
;
5743 while ((per_cu
= iter
.next ()) != NULL
)
5744 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
5749 /* It's a shame we couldn't do this inside the
5750 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5751 that have already been expanded. Instead, this loop matches what
5752 the psymtab code does. */
5753 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5755 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5756 if (symtab
!= nullptr)
5758 const struct block
*block
5759 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5760 if (!iterate_over_symbols_terminated (block
, name
,
5768 dw2_debug_names_expand_symtabs_matching
5769 (struct objfile
*objfile
,
5770 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5771 const lookup_name_info
*lookup_name
,
5772 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5773 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5774 enum search_domain kind
)
5776 struct dwarf2_per_objfile
*dwarf2_per_objfile
5777 = get_dwarf2_per_objfile (objfile
);
5779 /* debug_names_table is NULL if OBJF_READNOW. */
5780 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5783 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5785 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5787 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5791 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5792 file_matcher
, expansion_notify
);
5797 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5799 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5801 kind
, [&] (offset_type namei
)
5803 /* The name was matched, now expand corresponding CUs that were
5805 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5807 struct dwarf2_per_cu_data
*per_cu
;
5808 while ((per_cu
= iter
.next ()) != NULL
)
5809 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5810 file_matcher
, expansion_notify
);
5815 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5818 dw2_find_last_source_symtab
,
5819 dw2_forget_cached_source_info
,
5820 dw2_map_symtabs_matching_filename
,
5821 dw2_debug_names_lookup_symbol
,
5824 dw2_debug_names_dump
,
5825 dw2_debug_names_expand_symtabs_for_function
,
5826 dw2_expand_all_symtabs
,
5827 dw2_expand_symtabs_with_fullname
,
5828 dw2_debug_names_map_matching_symbols
,
5829 dw2_debug_names_expand_symtabs_matching
,
5830 dw2_find_pc_sect_compunit_symtab
,
5832 dw2_map_symbol_filenames
5835 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5836 to either a dwarf2_per_bfd or dwz_file object. */
5838 template <typename T
>
5839 static gdb::array_view
<const gdb_byte
>
5840 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5842 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5844 if (section
->empty ())
5847 /* Older elfutils strip versions could keep the section in the main
5848 executable while splitting it for the separate debug info file. */
5849 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5852 section
->read (obj
);
5854 /* dwarf2_section_info::size is a bfd_size_type, while
5855 gdb::array_view works with size_t. On 32-bit hosts, with
5856 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5857 is 32-bit. So we need an explicit narrowing conversion here.
5858 This is fine, because it's impossible to allocate or mmap an
5859 array/buffer larger than what size_t can represent. */
5860 return gdb::make_array_view (section
->buffer
, section
->size
);
5863 /* Lookup the index cache for the contents of the index associated to
5866 static gdb::array_view
<const gdb_byte
>
5867 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5869 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5870 if (build_id
== nullptr)
5873 return global_index_cache
.lookup_gdb_index (build_id
,
5874 &dwarf2_per_bfd
->index_cache_res
);
5877 /* Same as the above, but for DWZ. */
5879 static gdb::array_view
<const gdb_byte
>
5880 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5882 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5883 if (build_id
== nullptr)
5886 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5889 /* See symfile.h. */
5892 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5894 struct dwarf2_per_objfile
*dwarf2_per_objfile
5895 = get_dwarf2_per_objfile (objfile
);
5897 /* If we're about to read full symbols, don't bother with the
5898 indices. In this case we also don't care if some other debug
5899 format is making psymtabs, because they are all about to be
5901 if ((objfile
->flags
& OBJF_READNOW
))
5903 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5904 create_all_comp_units (dwarf2_per_objfile
);
5905 create_all_type_units (dwarf2_per_objfile
);
5906 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
5907 = create_quick_file_names_table
5908 (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5909 dwarf2_per_objfile
->resize_symtabs ();
5911 for (int i
= 0; i
< (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
5912 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()); ++i
)
5914 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
5916 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
5917 struct dwarf2_per_cu_quick_data
);
5920 /* Return 1 so that gdb sees the "quick" functions. However,
5921 these functions will be no-ops because we will have expanded
5923 *index_kind
= dw_index_kind::GDB_INDEX
;
5927 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5929 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5930 dwarf2_per_objfile
->resize_symtabs ();
5934 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5935 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5936 get_gdb_index_contents_from_section
<dwz_file
>))
5938 *index_kind
= dw_index_kind::GDB_INDEX
;
5939 dwarf2_per_objfile
->resize_symtabs ();
5943 /* ... otherwise, try to find the index in the index cache. */
5944 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5945 get_gdb_index_contents_from_cache
,
5946 get_gdb_index_contents_from_cache_dwz
))
5948 global_index_cache
.hit ();
5949 *index_kind
= dw_index_kind::GDB_INDEX
;
5950 dwarf2_per_objfile
->resize_symtabs ();
5954 global_index_cache
.miss ();
5960 /* Build a partial symbol table. */
5963 dwarf2_build_psymtabs (struct objfile
*objfile
)
5965 struct dwarf2_per_objfile
*dwarf2_per_objfile
5966 = get_dwarf2_per_objfile (objfile
);
5968 init_psymbol_list (objfile
, 1024);
5972 /* This isn't really ideal: all the data we allocate on the
5973 objfile's obstack is still uselessly kept around. However,
5974 freeing it seems unsafe. */
5975 psymtab_discarder
psymtabs (objfile
);
5976 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5979 dwarf2_per_objfile
->resize_symtabs ();
5981 /* (maybe) store an index in the cache. */
5982 global_index_cache
.store (dwarf2_per_objfile
);
5984 catch (const gdb_exception_error
&except
)
5986 exception_print (gdb_stderr
, except
);
5990 /* Find the base address of the compilation unit for range lists and
5991 location lists. It will normally be specified by DW_AT_low_pc.
5992 In DWARF-3 draft 4, the base address could be overridden by
5993 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5994 compilation units with discontinuous ranges. */
5997 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5999 struct attribute
*attr
;
6001 cu
->base_address
.reset ();
6003 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6004 if (attr
!= nullptr)
6005 cu
->base_address
= attr
->value_as_address ();
6008 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6009 if (attr
!= nullptr)
6010 cu
->base_address
= attr
->value_as_address ();
6014 /* Helper function that returns the proper abbrev section for
6017 static struct dwarf2_section_info
*
6018 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6020 struct dwarf2_section_info
*abbrev
;
6021 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6023 if (this_cu
->is_dwz
)
6024 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6026 abbrev
= &per_bfd
->abbrev
;
6031 /* Fetch the abbreviation table offset from a comp or type unit header. */
6034 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6035 struct dwarf2_section_info
*section
,
6036 sect_offset sect_off
)
6038 bfd
*abfd
= section
->get_bfd_owner ();
6039 const gdb_byte
*info_ptr
;
6040 unsigned int initial_length_size
, offset_size
;
6043 section
->read (dwarf2_per_objfile
->objfile
);
6044 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6045 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6046 offset_size
= initial_length_size
== 4 ? 4 : 8;
6047 info_ptr
+= initial_length_size
;
6049 version
= read_2_bytes (abfd
, info_ptr
);
6053 /* Skip unit type and address size. */
6057 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6060 /* A partial symtab that is used only for include files. */
6061 struct dwarf2_include_psymtab
: public partial_symtab
6063 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6064 : partial_symtab (filename
, objfile
)
6068 void read_symtab (struct objfile
*objfile
) override
6070 /* It's an include file, no symbols to read for it.
6071 Everything is in the includer symtab. */
6073 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6074 expansion of the includer psymtab. We use the dependencies[0] field to
6075 model the includer. But if we go the regular route of calling
6076 expand_psymtab here, and having expand_psymtab call expand_dependencies
6077 to expand the includer, we'll only use expand_psymtab on the includer
6078 (making it a non-toplevel psymtab), while if we expand the includer via
6079 another path, we'll use read_symtab (making it a toplevel psymtab).
6080 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6081 psymtab, and trigger read_symtab on the includer here directly. */
6082 includer ()->read_symtab (objfile
);
6085 void expand_psymtab (struct objfile
*objfile
) override
6087 /* This is not called by read_symtab, and should not be called by any
6088 expand_dependencies. */
6092 bool readin_p (struct objfile
*objfile
) const override
6094 return includer ()->readin_p (objfile
);
6097 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6103 partial_symtab
*includer () const
6105 /* An include psymtab has exactly one dependency: the psymtab that
6107 gdb_assert (this->number_of_dependencies
== 1);
6108 return this->dependencies
[0];
6112 /* Allocate a new partial symtab for file named NAME and mark this new
6113 partial symtab as being an include of PST. */
6116 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6117 struct objfile
*objfile
)
6119 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6121 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6122 subpst
->dirname
= pst
->dirname
;
6124 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6125 subpst
->dependencies
[0] = pst
;
6126 subpst
->number_of_dependencies
= 1;
6129 /* Read the Line Number Program data and extract the list of files
6130 included by the source file represented by PST. Build an include
6131 partial symtab for each of these included files. */
6134 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6135 struct die_info
*die
,
6136 dwarf2_psymtab
*pst
)
6139 struct attribute
*attr
;
6141 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6142 if (attr
!= nullptr)
6143 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6145 return; /* No linetable, so no includes. */
6147 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6148 that we pass in the raw text_low here; that is ok because we're
6149 only decoding the line table to make include partial symtabs, and
6150 so the addresses aren't really used. */
6151 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6152 pst
->raw_text_low (), 1);
6156 hash_signatured_type (const void *item
)
6158 const struct signatured_type
*sig_type
6159 = (const struct signatured_type
*) item
;
6161 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6162 return sig_type
->signature
;
6166 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6168 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6169 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6171 return lhs
->signature
== rhs
->signature
;
6174 /* Allocate a hash table for signatured types. */
6177 allocate_signatured_type_table ()
6179 return htab_up (htab_create_alloc (41,
6180 hash_signatured_type
,
6182 NULL
, xcalloc
, xfree
));
6185 /* A helper function to add a signatured type CU to a table. */
6188 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6190 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6191 std::vector
<signatured_type
*> *all_type_units
6192 = (std::vector
<signatured_type
*> *) datum
;
6194 all_type_units
->push_back (sigt
);
6199 /* A helper for create_debug_types_hash_table. Read types from SECTION
6200 and fill them into TYPES_HTAB. It will process only type units,
6201 therefore DW_UT_type. */
6204 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6205 struct dwo_file
*dwo_file
,
6206 dwarf2_section_info
*section
, htab_up
&types_htab
,
6207 rcuh_kind section_kind
)
6209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6210 struct dwarf2_section_info
*abbrev_section
;
6212 const gdb_byte
*info_ptr
, *end_ptr
;
6214 abbrev_section
= (dwo_file
!= NULL
6215 ? &dwo_file
->sections
.abbrev
6216 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6218 if (dwarf_read_debug
)
6219 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6220 section
->get_name (),
6221 abbrev_section
->get_file_name ());
6223 section
->read (objfile
);
6224 info_ptr
= section
->buffer
;
6226 if (info_ptr
== NULL
)
6229 /* We can't set abfd until now because the section may be empty or
6230 not present, in which case the bfd is unknown. */
6231 abfd
= section
->get_bfd_owner ();
6233 /* We don't use cutu_reader here because we don't need to read
6234 any dies: the signature is in the header. */
6236 end_ptr
= info_ptr
+ section
->size
;
6237 while (info_ptr
< end_ptr
)
6239 struct signatured_type
*sig_type
;
6240 struct dwo_unit
*dwo_tu
;
6242 const gdb_byte
*ptr
= info_ptr
;
6243 struct comp_unit_head header
;
6244 unsigned int length
;
6246 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6248 /* Initialize it due to a false compiler warning. */
6249 header
.signature
= -1;
6250 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6252 /* We need to read the type's signature in order to build the hash
6253 table, but we don't need anything else just yet. */
6255 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6256 abbrev_section
, ptr
, section_kind
);
6258 length
= header
.get_length ();
6260 /* Skip dummy type units. */
6261 if (ptr
>= info_ptr
+ length
6262 || peek_abbrev_code (abfd
, ptr
) == 0
6263 || header
.unit_type
!= DW_UT_type
)
6269 if (types_htab
== NULL
)
6272 types_htab
= allocate_dwo_unit_table ();
6274 types_htab
= allocate_signatured_type_table ();
6280 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6282 dwo_tu
->dwo_file
= dwo_file
;
6283 dwo_tu
->signature
= header
.signature
;
6284 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6285 dwo_tu
->section
= section
;
6286 dwo_tu
->sect_off
= sect_off
;
6287 dwo_tu
->length
= length
;
6291 /* N.B.: type_offset is not usable if this type uses a DWO file.
6292 The real type_offset is in the DWO file. */
6294 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6295 sig_type
->signature
= header
.signature
;
6296 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6297 sig_type
->per_cu
.is_debug_types
= 1;
6298 sig_type
->per_cu
.section
= section
;
6299 sig_type
->per_cu
.sect_off
= sect_off
;
6300 sig_type
->per_cu
.length
= length
;
6303 slot
= htab_find_slot (types_htab
.get (),
6304 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6306 gdb_assert (slot
!= NULL
);
6309 sect_offset dup_sect_off
;
6313 const struct dwo_unit
*dup_tu
6314 = (const struct dwo_unit
*) *slot
;
6316 dup_sect_off
= dup_tu
->sect_off
;
6320 const struct signatured_type
*dup_tu
6321 = (const struct signatured_type
*) *slot
;
6323 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6326 complaint (_("debug type entry at offset %s is duplicate to"
6327 " the entry at offset %s, signature %s"),
6328 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6329 hex_string (header
.signature
));
6331 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6333 if (dwarf_read_debug
> 1)
6334 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6335 sect_offset_str (sect_off
),
6336 hex_string (header
.signature
));
6342 /* Create the hash table of all entries in the .debug_types
6343 (or .debug_types.dwo) section(s).
6344 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6345 otherwise it is NULL.
6347 The result is a pointer to the hash table or NULL if there are no types.
6349 Note: This function processes DWO files only, not DWP files. */
6352 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6353 struct dwo_file
*dwo_file
,
6354 gdb::array_view
<dwarf2_section_info
> type_sections
,
6355 htab_up
&types_htab
)
6357 for (dwarf2_section_info
§ion
: type_sections
)
6358 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6359 types_htab
, rcuh_kind::TYPE
);
6362 /* Create the hash table of all entries in the .debug_types section,
6363 and initialize all_type_units.
6364 The result is zero if there is an error (e.g. missing .debug_types section),
6365 otherwise non-zero. */
6368 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6372 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6373 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6374 rcuh_kind::COMPILE
);
6375 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6376 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6377 if (types_htab
== NULL
)
6379 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6383 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6385 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6386 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6387 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6389 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6390 add_signatured_type_cu_to_table
,
6391 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6396 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6397 If SLOT is non-NULL, it is the entry to use in the hash table.
6398 Otherwise we find one. */
6400 static struct signatured_type
*
6401 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6404 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6405 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6406 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6408 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6410 dwarf2_per_objfile
->resize_symtabs ();
6412 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6413 sig_type
->signature
= sig
;
6414 sig_type
->per_cu
.is_debug_types
= 1;
6415 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6417 sig_type
->per_cu
.v
.quick
=
6418 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6419 struct dwarf2_per_cu_quick_data
);
6424 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6427 gdb_assert (*slot
== NULL
);
6429 /* The rest of sig_type must be filled in by the caller. */
6433 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6434 Fill in SIG_ENTRY with DWO_ENTRY. */
6437 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6438 struct signatured_type
*sig_entry
,
6439 struct dwo_unit
*dwo_entry
)
6441 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6443 /* Make sure we're not clobbering something we don't expect to. */
6444 gdb_assert (! sig_entry
->per_cu
.queued
);
6445 gdb_assert (dwarf2_per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6446 if (per_bfd
->using_index
)
6448 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6449 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6452 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6453 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6454 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6455 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6456 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6458 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6459 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6460 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6461 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6462 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6463 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6464 sig_entry
->dwo_unit
= dwo_entry
;
6467 /* Subroutine of lookup_signatured_type.
6468 If we haven't read the TU yet, create the signatured_type data structure
6469 for a TU to be read in directly from a DWO file, bypassing the stub.
6470 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6471 using .gdb_index, then when reading a CU we want to stay in the DWO file
6472 containing that CU. Otherwise we could end up reading several other DWO
6473 files (due to comdat folding) to process the transitive closure of all the
6474 mentioned TUs, and that can be slow. The current DWO file will have every
6475 type signature that it needs.
6476 We only do this for .gdb_index because in the psymtab case we already have
6477 to read all the DWOs to build the type unit groups. */
6479 static struct signatured_type
*
6480 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6482 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6483 struct dwo_file
*dwo_file
;
6484 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6485 struct signatured_type find_sig_entry
, *sig_entry
;
6488 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6490 /* If TU skeletons have been removed then we may not have read in any
6492 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6493 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6495 /* We only ever need to read in one copy of a signatured type.
6496 Use the global signatured_types array to do our own comdat-folding
6497 of types. If this is the first time we're reading this TU, and
6498 the TU has an entry in .gdb_index, replace the recorded data from
6499 .gdb_index with this TU. */
6501 find_sig_entry
.signature
= sig
;
6502 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6503 &find_sig_entry
, INSERT
);
6504 sig_entry
= (struct signatured_type
*) *slot
;
6506 /* We can get here with the TU already read, *or* in the process of being
6507 read. Don't reassign the global entry to point to this DWO if that's
6508 the case. Also note that if the TU is already being read, it may not
6509 have come from a DWO, the program may be a mix of Fission-compiled
6510 code and non-Fission-compiled code. */
6512 /* Have we already tried to read this TU?
6513 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6514 needn't exist in the global table yet). */
6515 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6518 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6519 dwo_unit of the TU itself. */
6520 dwo_file
= cu
->dwo_unit
->dwo_file
;
6522 /* Ok, this is the first time we're reading this TU. */
6523 if (dwo_file
->tus
== NULL
)
6525 find_dwo_entry
.signature
= sig
;
6526 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6528 if (dwo_entry
== NULL
)
6531 /* If the global table doesn't have an entry for this TU, add one. */
6532 if (sig_entry
== NULL
)
6533 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6535 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6536 sig_entry
->per_cu
.tu_read
= 1;
6540 /* Subroutine of lookup_signatured_type.
6541 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6542 then try the DWP file. If the TU stub (skeleton) has been removed then
6543 it won't be in .gdb_index. */
6545 static struct signatured_type
*
6546 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6548 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6549 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6550 struct dwo_unit
*dwo_entry
;
6551 struct signatured_type find_sig_entry
, *sig_entry
;
6554 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6555 gdb_assert (dwp_file
!= NULL
);
6557 /* If TU skeletons have been removed then we may not have read in any
6559 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6560 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6562 find_sig_entry
.signature
= sig
;
6563 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6564 &find_sig_entry
, INSERT
);
6565 sig_entry
= (struct signatured_type
*) *slot
;
6567 /* Have we already tried to read this TU?
6568 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6569 needn't exist in the global table yet). */
6570 if (sig_entry
!= NULL
)
6573 if (dwp_file
->tus
== NULL
)
6575 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6576 sig
, 1 /* is_debug_types */);
6577 if (dwo_entry
== NULL
)
6580 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6581 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6586 /* Lookup a signature based type for DW_FORM_ref_sig8.
6587 Returns NULL if signature SIG is not present in the table.
6588 It is up to the caller to complain about this. */
6590 static struct signatured_type
*
6591 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6593 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6596 && dwarf2_per_objfile
->per_bfd
->using_index
)
6598 /* We're in a DWO/DWP file, and we're using .gdb_index.
6599 These cases require special processing. */
6600 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6601 return lookup_dwo_signatured_type (cu
, sig
);
6603 return lookup_dwp_signatured_type (cu
, sig
);
6607 struct signatured_type find_entry
, *entry
;
6609 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6611 find_entry
.signature
= sig
;
6612 entry
= ((struct signatured_type
*)
6613 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6619 /* Low level DIE reading support. */
6621 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6624 init_cu_die_reader (struct die_reader_specs
*reader
,
6625 struct dwarf2_cu
*cu
,
6626 struct dwarf2_section_info
*section
,
6627 struct dwo_file
*dwo_file
,
6628 struct abbrev_table
*abbrev_table
)
6630 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6631 reader
->abfd
= section
->get_bfd_owner ();
6633 reader
->dwo_file
= dwo_file
;
6634 reader
->die_section
= section
;
6635 reader
->buffer
= section
->buffer
;
6636 reader
->buffer_end
= section
->buffer
+ section
->size
;
6637 reader
->abbrev_table
= abbrev_table
;
6640 /* Subroutine of cutu_reader to simplify it.
6641 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6642 There's just a lot of work to do, and cutu_reader is big enough
6645 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6646 from it to the DIE in the DWO. If NULL we are skipping the stub.
6647 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6648 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6649 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6650 STUB_COMP_DIR may be non-NULL.
6651 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6652 are filled in with the info of the DIE from the DWO file.
6653 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6654 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6655 kept around for at least as long as *RESULT_READER.
6657 The result is non-zero if a valid (non-dummy) DIE was found. */
6660 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6661 struct dwo_unit
*dwo_unit
,
6662 struct die_info
*stub_comp_unit_die
,
6663 const char *stub_comp_dir
,
6664 struct die_reader_specs
*result_reader
,
6665 const gdb_byte
**result_info_ptr
,
6666 struct die_info
**result_comp_unit_die
,
6667 abbrev_table_up
*result_dwo_abbrev_table
)
6669 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6670 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6671 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6673 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6674 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6675 int i
,num_extra_attrs
;
6676 struct dwarf2_section_info
*dwo_abbrev_section
;
6677 struct die_info
*comp_unit_die
;
6679 /* At most one of these may be provided. */
6680 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6682 /* These attributes aren't processed until later:
6683 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6684 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6685 referenced later. However, these attributes are found in the stub
6686 which we won't have later. In order to not impose this complication
6687 on the rest of the code, we read them here and copy them to the
6696 if (stub_comp_unit_die
!= NULL
)
6698 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6700 if (!per_cu
->is_debug_types
)
6701 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6702 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6703 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6704 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6705 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6707 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6709 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6710 here (if needed). We need the value before we can process
6712 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6714 else if (stub_comp_dir
!= NULL
)
6716 /* Reconstruct the comp_dir attribute to simplify the code below. */
6717 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6718 comp_dir
->name
= DW_AT_comp_dir
;
6719 comp_dir
->form
= DW_FORM_string
;
6720 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6721 DW_STRING (comp_dir
) = stub_comp_dir
;
6724 /* Set up for reading the DWO CU/TU. */
6725 cu
->dwo_unit
= dwo_unit
;
6726 dwarf2_section_info
*section
= dwo_unit
->section
;
6727 section
->read (objfile
);
6728 abfd
= section
->get_bfd_owner ();
6729 begin_info_ptr
= info_ptr
= (section
->buffer
6730 + to_underlying (dwo_unit
->sect_off
));
6731 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6733 if (per_cu
->is_debug_types
)
6735 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6737 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6738 &cu
->header
, section
,
6740 info_ptr
, rcuh_kind::TYPE
);
6741 /* This is not an assert because it can be caused by bad debug info. */
6742 if (sig_type
->signature
!= cu
->header
.signature
)
6744 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6745 " TU at offset %s [in module %s]"),
6746 hex_string (sig_type
->signature
),
6747 hex_string (cu
->header
.signature
),
6748 sect_offset_str (dwo_unit
->sect_off
),
6749 bfd_get_filename (abfd
));
6751 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6752 /* For DWOs coming from DWP files, we don't know the CU length
6753 nor the type's offset in the TU until now. */
6754 dwo_unit
->length
= cu
->header
.get_length ();
6755 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6757 /* Establish the type offset that can be used to lookup the type.
6758 For DWO files, we don't know it until now. */
6759 sig_type
->type_offset_in_section
6760 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6764 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6765 &cu
->header
, section
,
6767 info_ptr
, rcuh_kind::COMPILE
);
6768 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6769 /* For DWOs coming from DWP files, we don't know the CU length
6771 dwo_unit
->length
= cu
->header
.get_length ();
6774 *result_dwo_abbrev_table
6775 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6776 cu
->header
.abbrev_sect_off
);
6777 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6778 result_dwo_abbrev_table
->get ());
6780 /* Read in the die, but leave space to copy over the attributes
6781 from the stub. This has the benefit of simplifying the rest of
6782 the code - all the work to maintain the illusion of a single
6783 DW_TAG_{compile,type}_unit DIE is done here. */
6784 num_extra_attrs
= ((stmt_list
!= NULL
)
6788 + (comp_dir
!= NULL
));
6789 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6792 /* Copy over the attributes from the stub to the DIE we just read in. */
6793 comp_unit_die
= *result_comp_unit_die
;
6794 i
= comp_unit_die
->num_attrs
;
6795 if (stmt_list
!= NULL
)
6796 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6798 comp_unit_die
->attrs
[i
++] = *low_pc
;
6799 if (high_pc
!= NULL
)
6800 comp_unit_die
->attrs
[i
++] = *high_pc
;
6802 comp_unit_die
->attrs
[i
++] = *ranges
;
6803 if (comp_dir
!= NULL
)
6804 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6805 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6807 if (dwarf_die_debug
)
6809 fprintf_unfiltered (gdb_stdlog
,
6810 "Read die from %s@0x%x of %s:\n",
6811 section
->get_name (),
6812 (unsigned) (begin_info_ptr
- section
->buffer
),
6813 bfd_get_filename (abfd
));
6814 dump_die (comp_unit_die
, dwarf_die_debug
);
6817 /* Skip dummy compilation units. */
6818 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6819 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6822 *result_info_ptr
= info_ptr
;
6826 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6827 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6828 signature is part of the header. */
6829 static gdb::optional
<ULONGEST
>
6830 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6832 if (cu
->header
.version
>= 5)
6833 return cu
->header
.signature
;
6834 struct attribute
*attr
;
6835 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6836 if (attr
== nullptr)
6837 return gdb::optional
<ULONGEST
> ();
6838 return DW_UNSND (attr
);
6841 /* Subroutine of cutu_reader to simplify it.
6842 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6843 Returns NULL if the specified DWO unit cannot be found. */
6845 static struct dwo_unit
*
6846 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6848 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6849 struct dwo_unit
*dwo_unit
;
6850 const char *comp_dir
;
6852 gdb_assert (cu
!= NULL
);
6854 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6855 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6856 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6858 if (per_cu
->is_debug_types
)
6859 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6862 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6864 if (!signature
.has_value ())
6865 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6867 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6869 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6875 /* Subroutine of cutu_reader to simplify it.
6876 See it for a description of the parameters.
6877 Read a TU directly from a DWO file, bypassing the stub. */
6880 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6881 dwarf2_per_objfile
*per_objfile
,
6882 dwarf2_cu
*existing_cu
)
6884 struct signatured_type
*sig_type
;
6886 /* Verify we can do the following downcast, and that we have the
6888 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6889 sig_type
= (struct signatured_type
*) this_cu
;
6890 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6894 if (existing_cu
!= nullptr)
6897 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6898 /* There's no need to do the rereading_dwo_cu handling that
6899 cutu_reader does since we don't read the stub. */
6903 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6904 in per_objfile yet. */
6905 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6906 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6907 cu
= m_new_cu
.get ();
6910 /* A future optimization, if needed, would be to use an existing
6911 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6912 could share abbrev tables. */
6914 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6915 NULL
/* stub_comp_unit_die */,
6916 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6919 &m_dwo_abbrev_table
) == 0)
6926 /* Initialize a CU (or TU) and read its DIEs.
6927 If the CU defers to a DWO file, read the DWO file as well.
6929 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6930 Otherwise the table specified in the comp unit header is read in and used.
6931 This is an optimization for when we already have the abbrev table.
6933 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6936 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6937 dwarf2_per_objfile
*dwarf2_per_objfile
,
6938 struct abbrev_table
*abbrev_table
,
6939 dwarf2_cu
*existing_cu
,
6941 : die_reader_specs
{},
6944 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6945 struct dwarf2_section_info
*section
= this_cu
->section
;
6946 bfd
*abfd
= section
->get_bfd_owner ();
6947 const gdb_byte
*begin_info_ptr
;
6948 struct signatured_type
*sig_type
= NULL
;
6949 struct dwarf2_section_info
*abbrev_section
;
6950 /* Non-zero if CU currently points to a DWO file and we need to
6951 reread it. When this happens we need to reread the skeleton die
6952 before we can reread the DWO file (this only applies to CUs, not TUs). */
6953 int rereading_dwo_cu
= 0;
6955 if (dwarf_die_debug
)
6956 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6957 this_cu
->is_debug_types
? "type" : "comp",
6958 sect_offset_str (this_cu
->sect_off
));
6960 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6961 file (instead of going through the stub), short-circuit all of this. */
6962 if (this_cu
->reading_dwo_directly
)
6964 /* Narrow down the scope of possibilities to have to understand. */
6965 gdb_assert (this_cu
->is_debug_types
);
6966 gdb_assert (abbrev_table
== NULL
);
6967 init_tu_and_read_dwo_dies (this_cu
, dwarf2_per_objfile
, existing_cu
);
6971 /* This is cheap if the section is already read in. */
6972 section
->read (objfile
);
6974 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6976 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6980 if (existing_cu
!= nullptr)
6983 /* If this CU is from a DWO file we need to start over, we need to
6984 refetch the attributes from the skeleton CU.
6985 This could be optimized by retrieving those attributes from when we
6986 were here the first time: the previous comp_unit_die was stored in
6987 comp_unit_obstack. But there's no data yet that we need this
6989 if (cu
->dwo_unit
!= NULL
)
6990 rereading_dwo_cu
= 1;
6994 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6995 in per_objfile yet. */
6996 gdb_assert (dwarf2_per_objfile
->get_cu (this_cu
) == nullptr);
6997 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
6998 cu
= m_new_cu
.get ();
7001 /* Get the header. */
7002 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7004 /* We already have the header, there's no need to read it in again. */
7005 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7009 if (this_cu
->is_debug_types
)
7011 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7012 &cu
->header
, section
,
7013 abbrev_section
, info_ptr
,
7016 /* Since per_cu is the first member of struct signatured_type,
7017 we can go from a pointer to one to a pointer to the other. */
7018 sig_type
= (struct signatured_type
*) this_cu
;
7019 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7020 gdb_assert (sig_type
->type_offset_in_tu
7021 == cu
->header
.type_cu_offset_in_tu
);
7022 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7024 /* LENGTH has not been set yet for type units if we're
7025 using .gdb_index. */
7026 this_cu
->length
= cu
->header
.get_length ();
7028 /* Establish the type offset that can be used to lookup the type. */
7029 sig_type
->type_offset_in_section
=
7030 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7032 this_cu
->dwarf_version
= cu
->header
.version
;
7036 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7037 &cu
->header
, section
,
7040 rcuh_kind::COMPILE
);
7042 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7043 if (this_cu
->length
== 0)
7044 this_cu
->length
= cu
->header
.get_length ();
7046 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7047 this_cu
->dwarf_version
= cu
->header
.version
;
7051 /* Skip dummy compilation units. */
7052 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7053 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7059 /* If we don't have them yet, read the abbrevs for this compilation unit.
7060 And if we need to read them now, make sure they're freed when we're
7062 if (abbrev_table
!= NULL
)
7063 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7066 m_abbrev_table_holder
7067 = abbrev_table::read (objfile
, abbrev_section
,
7068 cu
->header
.abbrev_sect_off
);
7069 abbrev_table
= m_abbrev_table_holder
.get ();
7072 /* Read the top level CU/TU die. */
7073 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7074 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7076 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7082 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7083 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7084 table from the DWO file and pass the ownership over to us. It will be
7085 referenced from READER, so we must make sure to free it after we're done
7088 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7089 DWO CU, that this test will fail (the attribute will not be present). */
7090 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7091 if (dwo_name
!= nullptr)
7093 struct dwo_unit
*dwo_unit
;
7094 struct die_info
*dwo_comp_unit_die
;
7096 if (comp_unit_die
->has_children
)
7098 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7099 " has children (offset %s) [in module %s]"),
7100 sect_offset_str (this_cu
->sect_off
),
7101 bfd_get_filename (abfd
));
7103 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7104 if (dwo_unit
!= NULL
)
7106 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7107 comp_unit_die
, NULL
,
7110 &m_dwo_abbrev_table
) == 0)
7116 comp_unit_die
= dwo_comp_unit_die
;
7120 /* Yikes, we couldn't find the rest of the DIE, we only have
7121 the stub. A complaint has already been logged. There's
7122 not much more we can do except pass on the stub DIE to
7123 die_reader_func. We don't want to throw an error on bad
7130 cutu_reader::keep ()
7132 /* Done, clean up. */
7133 gdb_assert (!dummy_p
);
7134 if (m_new_cu
!= NULL
)
7136 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7138 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7139 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7143 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7144 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7145 assumed to have already done the lookup to find the DWO file).
7147 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7148 THIS_CU->is_debug_types, but nothing else.
7150 We fill in THIS_CU->length.
7152 THIS_CU->cu is always freed when done.
7153 This is done in order to not leave THIS_CU->cu in a state where we have
7154 to care whether it refers to the "main" CU or the DWO CU.
7156 When parent_cu is passed, it is used to provide a default value for
7157 str_offsets_base and addr_base from the parent. */
7159 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7160 dwarf2_per_objfile
*dwarf2_per_objfile
,
7161 struct dwarf2_cu
*parent_cu
,
7162 struct dwo_file
*dwo_file
)
7163 : die_reader_specs
{},
7166 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7167 struct dwarf2_section_info
*section
= this_cu
->section
;
7168 bfd
*abfd
= section
->get_bfd_owner ();
7169 struct dwarf2_section_info
*abbrev_section
;
7170 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7172 if (dwarf_die_debug
)
7173 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7174 this_cu
->is_debug_types
? "type" : "comp",
7175 sect_offset_str (this_cu
->sect_off
));
7177 gdb_assert (dwarf2_per_objfile
->get_cu (this_cu
) == nullptr);
7179 abbrev_section
= (dwo_file
!= NULL
7180 ? &dwo_file
->sections
.abbrev
7181 : get_abbrev_section_for_cu (this_cu
));
7183 /* This is cheap if the section is already read in. */
7184 section
->read (objfile
);
7186 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7188 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7189 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7190 &m_new_cu
->header
, section
,
7191 abbrev_section
, info_ptr
,
7192 (this_cu
->is_debug_types
7194 : rcuh_kind::COMPILE
));
7196 if (parent_cu
!= nullptr)
7198 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7199 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7201 this_cu
->length
= m_new_cu
->header
.get_length ();
7203 /* Skip dummy compilation units. */
7204 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7205 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7211 m_abbrev_table_holder
7212 = abbrev_table::read (objfile
, abbrev_section
,
7213 m_new_cu
->header
.abbrev_sect_off
);
7215 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7216 m_abbrev_table_holder
.get ());
7217 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7221 /* Type Unit Groups.
7223 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7224 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7225 so that all types coming from the same compilation (.o file) are grouped
7226 together. A future step could be to put the types in the same symtab as
7227 the CU the types ultimately came from. */
7230 hash_type_unit_group (const void *item
)
7232 const struct type_unit_group
*tu_group
7233 = (const struct type_unit_group
*) item
;
7235 return hash_stmt_list_entry (&tu_group
->hash
);
7239 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7241 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7242 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7244 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7247 /* Allocate a hash table for type unit groups. */
7250 allocate_type_unit_groups_table ()
7252 return htab_up (htab_create_alloc (3,
7253 hash_type_unit_group
,
7255 NULL
, xcalloc
, xfree
));
7258 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7259 partial symtabs. We combine several TUs per psymtab to not let the size
7260 of any one psymtab grow too big. */
7261 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7262 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7264 /* Helper routine for get_type_unit_group.
7265 Create the type_unit_group object used to hold one or more TUs. */
7267 static struct type_unit_group
*
7268 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7270 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7271 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
7272 struct dwarf2_per_cu_data
*per_cu
;
7273 struct type_unit_group
*tu_group
;
7275 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7276 struct type_unit_group
);
7277 per_cu
= &tu_group
->per_cu
;
7278 per_cu
->per_bfd
= per_bfd
;
7280 if (per_bfd
->using_index
)
7282 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7283 struct dwarf2_per_cu_quick_data
);
7287 unsigned int line_offset
= to_underlying (line_offset_struct
);
7288 dwarf2_psymtab
*pst
;
7291 /* Give the symtab a useful name for debug purposes. */
7292 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7293 name
= string_printf ("<type_units_%d>",
7294 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7296 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7298 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, name
.c_str ());
7299 pst
->anonymous
= true;
7302 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7303 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7308 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7309 STMT_LIST is a DW_AT_stmt_list attribute. */
7311 static struct type_unit_group
*
7312 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7314 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7315 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7316 struct type_unit_group
*tu_group
;
7318 unsigned int line_offset
;
7319 struct type_unit_group type_unit_group_for_lookup
;
7321 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7322 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7324 /* Do we need to create a new group, or can we use an existing one? */
7328 line_offset
= DW_UNSND (stmt_list
);
7329 ++tu_stats
->nr_symtab_sharers
;
7333 /* Ugh, no stmt_list. Rare, but we have to handle it.
7334 We can do various things here like create one group per TU or
7335 spread them over multiple groups to split up the expansion work.
7336 To avoid worst case scenarios (too many groups or too large groups)
7337 we, umm, group them in bunches. */
7338 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7339 | (tu_stats
->nr_stmt_less_type_units
7340 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7341 ++tu_stats
->nr_stmt_less_type_units
;
7344 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7345 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7346 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7347 &type_unit_group_for_lookup
, INSERT
);
7350 tu_group
= (struct type_unit_group
*) *slot
;
7351 gdb_assert (tu_group
!= NULL
);
7355 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7356 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7358 ++tu_stats
->nr_symtabs
;
7364 /* Partial symbol tables. */
7366 /* Create a psymtab named NAME and assign it to PER_CU.
7368 The caller must fill in the following details:
7369 dirname, textlow, texthigh. */
7371 static dwarf2_psymtab
*
7372 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7373 dwarf2_per_objfile
*per_objfile
,
7376 struct objfile
*objfile
= per_objfile
->objfile
;
7377 dwarf2_psymtab
*pst
;
7379 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7381 pst
->psymtabs_addrmap_supported
= true;
7383 /* This is the glue that links PST into GDB's symbol API. */
7384 per_cu
->v
.psymtab
= pst
;
7389 /* DIE reader function for process_psymtab_comp_unit. */
7392 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7393 const gdb_byte
*info_ptr
,
7394 struct die_info
*comp_unit_die
,
7395 enum language pretend_language
)
7397 struct dwarf2_cu
*cu
= reader
->cu
;
7398 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7399 struct objfile
*objfile
= per_objfile
->objfile
;
7400 struct gdbarch
*gdbarch
= objfile
->arch ();
7401 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7403 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7404 dwarf2_psymtab
*pst
;
7405 enum pc_bounds_kind cu_bounds_kind
;
7406 const char *filename
;
7408 gdb_assert (! per_cu
->is_debug_types
);
7410 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7412 /* Allocate a new partial symbol table structure. */
7413 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7414 static const char artificial
[] = "<artificial>";
7415 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7416 if (filename
== NULL
)
7418 else if (strcmp (filename
, artificial
) == 0)
7420 debug_filename
.reset (concat (artificial
, "@",
7421 sect_offset_str (per_cu
->sect_off
),
7423 filename
= debug_filename
.get ();
7426 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7428 /* This must be done before calling dwarf2_build_include_psymtabs. */
7429 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7431 baseaddr
= objfile
->text_section_offset ();
7433 dwarf2_find_base_address (comp_unit_die
, cu
);
7435 /* Possibly set the default values of LOWPC and HIGHPC from
7437 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7438 &best_highpc
, cu
, pst
);
7439 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7442 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7445 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7447 /* Store the contiguous range if it is not empty; it can be
7448 empty for CUs with no code. */
7449 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7453 /* Check if comp unit has_children.
7454 If so, read the rest of the partial symbols from this comp unit.
7455 If not, there's no more debug_info for this comp unit. */
7456 if (comp_unit_die
->has_children
)
7458 struct partial_die_info
*first_die
;
7459 CORE_ADDR lowpc
, highpc
;
7461 lowpc
= ((CORE_ADDR
) -1);
7462 highpc
= ((CORE_ADDR
) 0);
7464 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7466 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7467 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7469 /* If we didn't find a lowpc, set it to highpc to avoid
7470 complaints from `maint check'. */
7471 if (lowpc
== ((CORE_ADDR
) -1))
7474 /* If the compilation unit didn't have an explicit address range,
7475 then use the information extracted from its child dies. */
7476 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7479 best_highpc
= highpc
;
7482 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7483 best_lowpc
+ baseaddr
)
7485 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7486 best_highpc
+ baseaddr
)
7489 end_psymtab_common (objfile
, pst
);
7491 if (!cu
->per_cu
->imported_symtabs_empty ())
7494 int len
= cu
->per_cu
->imported_symtabs_size ();
7496 /* Fill in 'dependencies' here; we fill in 'users' in a
7498 pst
->number_of_dependencies
= len
;
7500 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7501 for (i
= 0; i
< len
; ++i
)
7503 pst
->dependencies
[i
]
7504 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7507 cu
->per_cu
->imported_symtabs_free ();
7510 /* Get the list of files included in the current compilation unit,
7511 and build a psymtab for each of them. */
7512 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7514 if (dwarf_read_debug
)
7515 fprintf_unfiltered (gdb_stdlog
,
7516 "Psymtab for %s unit @%s: %s - %s"
7517 ", %d global, %d static syms\n",
7518 per_cu
->is_debug_types
? "type" : "comp",
7519 sect_offset_str (per_cu
->sect_off
),
7520 paddress (gdbarch
, pst
->text_low (objfile
)),
7521 paddress (gdbarch
, pst
->text_high (objfile
)),
7522 pst
->n_global_syms
, pst
->n_static_syms
);
7525 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7526 Process compilation unit THIS_CU for a psymtab. */
7529 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7530 dwarf2_per_objfile
*per_objfile
,
7531 bool want_partial_unit
,
7532 enum language pretend_language
)
7534 /* If this compilation unit was already read in, free the
7535 cached copy in order to read it in again. This is
7536 necessary because we skipped some symbols when we first
7537 read in the compilation unit (see load_partial_dies).
7538 This problem could be avoided, but the benefit is unclear. */
7539 per_objfile
->remove_cu (this_cu
);
7541 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7543 switch (reader
.comp_unit_die
->tag
)
7545 case DW_TAG_compile_unit
:
7546 this_cu
->unit_type
= DW_UT_compile
;
7548 case DW_TAG_partial_unit
:
7549 this_cu
->unit_type
= DW_UT_partial
;
7559 else if (this_cu
->is_debug_types
)
7560 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7561 reader
.comp_unit_die
);
7562 else if (want_partial_unit
7563 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7564 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7565 reader
.comp_unit_die
,
7568 this_cu
->lang
= reader
.cu
->language
;
7570 /* Age out any secondary CUs. */
7571 per_objfile
->age_comp_units ();
7574 /* Reader function for build_type_psymtabs. */
7577 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7578 const gdb_byte
*info_ptr
,
7579 struct die_info
*type_unit_die
)
7581 struct dwarf2_per_objfile
*dwarf2_per_objfile
= reader
->cu
->per_objfile
;
7582 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7583 struct dwarf2_cu
*cu
= reader
->cu
;
7584 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7585 struct signatured_type
*sig_type
;
7586 struct type_unit_group
*tu_group
;
7587 struct attribute
*attr
;
7588 struct partial_die_info
*first_die
;
7589 CORE_ADDR lowpc
, highpc
;
7590 dwarf2_psymtab
*pst
;
7592 gdb_assert (per_cu
->is_debug_types
);
7593 sig_type
= (struct signatured_type
*) per_cu
;
7595 if (! type_unit_die
->has_children
)
7598 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7599 tu_group
= get_type_unit_group (cu
, attr
);
7601 if (tu_group
->tus
== nullptr)
7602 tu_group
->tus
= new std::vector
<signatured_type
*>;
7603 tu_group
->tus
->push_back (sig_type
);
7605 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7606 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, "");
7607 pst
->anonymous
= true;
7609 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7611 lowpc
= (CORE_ADDR
) -1;
7612 highpc
= (CORE_ADDR
) 0;
7613 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7615 end_psymtab_common (objfile
, pst
);
7618 /* Struct used to sort TUs by their abbreviation table offset. */
7620 struct tu_abbrev_offset
7622 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7623 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7626 signatured_type
*sig_type
;
7627 sect_offset abbrev_offset
;
7630 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7633 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7634 const struct tu_abbrev_offset
&b
)
7636 return a
.abbrev_offset
< b
.abbrev_offset
;
7639 /* Efficiently read all the type units.
7640 This does the bulk of the work for build_type_psymtabs.
7642 The efficiency is because we sort TUs by the abbrev table they use and
7643 only read each abbrev table once. In one program there are 200K TUs
7644 sharing 8K abbrev tables.
7646 The main purpose of this function is to support building the
7647 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7648 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7649 can collapse the search space by grouping them by stmt_list.
7650 The savings can be significant, in the same program from above the 200K TUs
7651 share 8K stmt_list tables.
7653 FUNC is expected to call get_type_unit_group, which will create the
7654 struct type_unit_group if necessary and add it to
7655 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7658 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7660 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7661 abbrev_table_up abbrev_table
;
7662 sect_offset abbrev_offset
;
7664 /* It's up to the caller to not call us multiple times. */
7665 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7667 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7670 /* TUs typically share abbrev tables, and there can be way more TUs than
7671 abbrev tables. Sort by abbrev table to reduce the number of times we
7672 read each abbrev table in.
7673 Alternatives are to punt or to maintain a cache of abbrev tables.
7674 This is simpler and efficient enough for now.
7676 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7677 symtab to use). Typically TUs with the same abbrev offset have the same
7678 stmt_list value too so in practice this should work well.
7680 The basic algorithm here is:
7682 sort TUs by abbrev table
7683 for each TU with same abbrev table:
7684 read abbrev table if first user
7685 read TU top level DIE
7686 [IWBN if DWO skeletons had DW_AT_stmt_list]
7689 if (dwarf_read_debug
)
7690 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7692 /* Sort in a separate table to maintain the order of all_type_units
7693 for .gdb_index: TU indices directly index all_type_units. */
7694 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7695 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7697 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7698 sorted_by_abbrev
.emplace_back
7699 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7700 sig_type
->per_cu
.section
,
7701 sig_type
->per_cu
.sect_off
));
7703 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7704 sort_tu_by_abbrev_offset
);
7706 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7708 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7710 /* Switch to the next abbrev table if necessary. */
7711 if (abbrev_table
== NULL
7712 || tu
.abbrev_offset
!= abbrev_offset
)
7714 abbrev_offset
= tu
.abbrev_offset
;
7716 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7717 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7719 ++tu_stats
->nr_uniq_abbrev_tables
;
7722 cutu_reader
reader (&tu
.sig_type
->per_cu
, dwarf2_per_objfile
,
7723 abbrev_table
.get (), nullptr, false);
7724 if (!reader
.dummy_p
)
7725 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7726 reader
.comp_unit_die
);
7730 /* Print collected type unit statistics. */
7733 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7735 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7737 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7738 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7739 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7740 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7741 tu_stats
->nr_uniq_abbrev_tables
);
7742 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7743 tu_stats
->nr_symtabs
);
7744 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7745 tu_stats
->nr_symtab_sharers
);
7746 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7747 tu_stats
->nr_stmt_less_type_units
);
7748 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7749 tu_stats
->nr_all_type_units_reallocs
);
7752 /* Traversal function for build_type_psymtabs. */
7755 build_type_psymtab_dependencies (void **slot
, void *info
)
7757 struct dwarf2_per_objfile
*dwarf2_per_objfile
7758 = (struct dwarf2_per_objfile
*) info
;
7759 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7760 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7761 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7762 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7763 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7766 gdb_assert (len
> 0);
7767 gdb_assert (per_cu
->type_unit_group_p ());
7769 pst
->number_of_dependencies
= len
;
7770 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7771 for (i
= 0; i
< len
; ++i
)
7773 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7774 gdb_assert (iter
->per_cu
.is_debug_types
);
7775 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7776 iter
->type_unit_group
= tu_group
;
7779 delete tu_group
->tus
;
7780 tu_group
->tus
= nullptr;
7785 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7786 Build partial symbol tables for the .debug_types comp-units. */
7789 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7791 if (! create_all_type_units (dwarf2_per_objfile
))
7794 build_type_psymtabs_1 (dwarf2_per_objfile
);
7797 /* Traversal function for process_skeletonless_type_unit.
7798 Read a TU in a DWO file and build partial symbols for it. */
7801 process_skeletonless_type_unit (void **slot
, void *info
)
7803 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7804 struct dwarf2_per_objfile
*dwarf2_per_objfile
7805 = (struct dwarf2_per_objfile
*) info
;
7806 struct signatured_type find_entry
, *entry
;
7808 /* If this TU doesn't exist in the global table, add it and read it in. */
7810 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7811 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7813 find_entry
.signature
= dwo_unit
->signature
;
7814 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7815 &find_entry
, INSERT
);
7816 /* If we've already seen this type there's nothing to do. What's happening
7817 is we're doing our own version of comdat-folding here. */
7821 /* This does the job that create_all_type_units would have done for
7823 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7824 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7827 /* This does the job that build_type_psymtabs_1 would have done. */
7828 cutu_reader
reader (&entry
->per_cu
, dwarf2_per_objfile
, nullptr, nullptr,
7830 if (!reader
.dummy_p
)
7831 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7832 reader
.comp_unit_die
);
7837 /* Traversal function for process_skeletonless_type_units. */
7840 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7842 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7844 if (dwo_file
->tus
!= NULL
)
7845 htab_traverse_noresize (dwo_file
->tus
.get (),
7846 process_skeletonless_type_unit
, info
);
7851 /* Scan all TUs of DWO files, verifying we've processed them.
7852 This is needed in case a TU was emitted without its skeleton.
7853 Note: This can't be done until we know what all the DWO files are. */
7856 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7858 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7859 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7860 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7862 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7863 process_dwo_file_for_skeletonless_type_units
,
7864 dwarf2_per_objfile
);
7868 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7871 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7873 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7875 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7880 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7882 /* Set the 'user' field only if it is not already set. */
7883 if (pst
->dependencies
[j
]->user
== NULL
)
7884 pst
->dependencies
[j
]->user
= pst
;
7889 /* Build the partial symbol table by doing a quick pass through the
7890 .debug_info and .debug_abbrev sections. */
7893 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7895 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7897 if (dwarf_read_debug
)
7899 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7900 objfile_name (objfile
));
7903 scoped_restore restore_reading_psyms
7904 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
7907 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
7909 /* Any cached compilation units will be linked by the per-objfile
7910 read_in_chain. Make sure to free them when we're done. */
7911 free_cached_comp_units
freer (dwarf2_per_objfile
);
7913 build_type_psymtabs (dwarf2_per_objfile
);
7915 create_all_comp_units (dwarf2_per_objfile
);
7917 /* Create a temporary address map on a temporary obstack. We later
7918 copy this to the final obstack. */
7919 auto_obstack temp_obstack
;
7921 scoped_restore save_psymtabs_addrmap
7922 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7923 addrmap_create_mutable (&temp_obstack
));
7925 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7927 if (per_cu
->v
.psymtab
!= NULL
)
7928 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7930 process_psymtab_comp_unit (per_cu
, dwarf2_per_objfile
, false,
7934 /* This has to wait until we read the CUs, we need the list of DWOs. */
7935 process_skeletonless_type_units (dwarf2_per_objfile
);
7937 /* Now that all TUs have been processed we can fill in the dependencies. */
7938 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
7940 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7941 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7944 if (dwarf_read_debug
)
7945 print_tu_stats (dwarf2_per_objfile
);
7947 set_partial_user (dwarf2_per_objfile
);
7949 objfile
->partial_symtabs
->psymtabs_addrmap
7950 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7951 objfile
->partial_symtabs
->obstack ());
7952 /* At this point we want to keep the address map. */
7953 save_psymtabs_addrmap
.release ();
7955 if (dwarf_read_debug
)
7956 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7957 objfile_name (objfile
));
7960 /* Load the partial DIEs for a secondary CU into memory.
7961 This is also used when rereading a primary CU with load_all_dies. */
7964 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7965 dwarf2_per_objfile
*per_objfile
,
7966 dwarf2_cu
*existing_cu
)
7968 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7970 if (!reader
.dummy_p
)
7972 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7975 /* Check if comp unit has_children.
7976 If so, read the rest of the partial symbols from this comp unit.
7977 If not, there's no more debug_info for this comp unit. */
7978 if (reader
.comp_unit_die
->has_children
)
7979 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7986 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7987 struct dwarf2_section_info
*section
,
7988 struct dwarf2_section_info
*abbrev_section
,
7989 unsigned int is_dwz
)
7991 const gdb_byte
*info_ptr
;
7992 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7994 if (dwarf_read_debug
)
7995 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7996 section
->get_name (),
7997 section
->get_file_name ());
7999 section
->read (objfile
);
8001 info_ptr
= section
->buffer
;
8003 while (info_ptr
< section
->buffer
+ section
->size
)
8005 struct dwarf2_per_cu_data
*this_cu
;
8007 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8009 comp_unit_head cu_header
;
8010 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8011 abbrev_section
, info_ptr
,
8012 rcuh_kind::COMPILE
);
8014 /* Save the compilation unit for later lookup. */
8015 if (cu_header
.unit_type
!= DW_UT_type
)
8016 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8019 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8020 sig_type
->signature
= cu_header
.signature
;
8021 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8022 this_cu
= &sig_type
->per_cu
;
8024 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8025 this_cu
->sect_off
= sect_off
;
8026 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8027 this_cu
->is_dwz
= is_dwz
;
8028 this_cu
->section
= section
;
8030 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8032 info_ptr
= info_ptr
+ this_cu
->length
;
8036 /* Create a list of all compilation units in OBJFILE.
8037 This is only done for -readnow and building partial symtabs. */
8040 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8042 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8043 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8044 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8046 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
8048 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8052 /* Process all loaded DIEs for compilation unit CU, starting at
8053 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8054 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8055 DW_AT_ranges). See the comments of add_partial_subprogram on how
8056 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8059 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8060 CORE_ADDR
*highpc
, int set_addrmap
,
8061 struct dwarf2_cu
*cu
)
8063 struct partial_die_info
*pdi
;
8065 /* Now, march along the PDI's, descending into ones which have
8066 interesting children but skipping the children of the other ones,
8067 until we reach the end of the compilation unit. */
8075 /* Anonymous namespaces or modules have no name but have interesting
8076 children, so we need to look at them. Ditto for anonymous
8079 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8080 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8081 || pdi
->tag
== DW_TAG_imported_unit
8082 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8086 case DW_TAG_subprogram
:
8087 case DW_TAG_inlined_subroutine
:
8088 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8090 case DW_TAG_constant
:
8091 case DW_TAG_variable
:
8092 case DW_TAG_typedef
:
8093 case DW_TAG_union_type
:
8094 if (!pdi
->is_declaration
8095 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8097 add_partial_symbol (pdi
, cu
);
8100 case DW_TAG_class_type
:
8101 case DW_TAG_interface_type
:
8102 case DW_TAG_structure_type
:
8103 if (!pdi
->is_declaration
)
8105 add_partial_symbol (pdi
, cu
);
8107 if ((cu
->language
== language_rust
8108 || cu
->language
== language_cplus
) && pdi
->has_children
)
8109 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8112 case DW_TAG_enumeration_type
:
8113 if (!pdi
->is_declaration
)
8114 add_partial_enumeration (pdi
, cu
);
8116 case DW_TAG_base_type
:
8117 case DW_TAG_subrange_type
:
8118 /* File scope base type definitions are added to the partial
8120 add_partial_symbol (pdi
, cu
);
8122 case DW_TAG_namespace
:
8123 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8126 if (!pdi
->is_declaration
)
8127 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8129 case DW_TAG_imported_unit
:
8131 struct dwarf2_per_cu_data
*per_cu
;
8133 /* For now we don't handle imported units in type units. */
8134 if (cu
->per_cu
->is_debug_types
)
8136 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8137 " supported in type units [in module %s]"),
8138 objfile_name (cu
->per_objfile
->objfile
));
8141 per_cu
= dwarf2_find_containing_comp_unit
8142 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8144 /* Go read the partial unit, if needed. */
8145 if (per_cu
->v
.psymtab
== NULL
)
8146 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8149 cu
->per_cu
->imported_symtabs_push (per_cu
);
8152 case DW_TAG_imported_declaration
:
8153 add_partial_symbol (pdi
, cu
);
8160 /* If the die has a sibling, skip to the sibling. */
8162 pdi
= pdi
->die_sibling
;
8166 /* Functions used to compute the fully scoped name of a partial DIE.
8168 Normally, this is simple. For C++, the parent DIE's fully scoped
8169 name is concatenated with "::" and the partial DIE's name.
8170 Enumerators are an exception; they use the scope of their parent
8171 enumeration type, i.e. the name of the enumeration type is not
8172 prepended to the enumerator.
8174 There are two complexities. One is DW_AT_specification; in this
8175 case "parent" means the parent of the target of the specification,
8176 instead of the direct parent of the DIE. The other is compilers
8177 which do not emit DW_TAG_namespace; in this case we try to guess
8178 the fully qualified name of structure types from their members'
8179 linkage names. This must be done using the DIE's children rather
8180 than the children of any DW_AT_specification target. We only need
8181 to do this for structures at the top level, i.e. if the target of
8182 any DW_AT_specification (if any; otherwise the DIE itself) does not
8185 /* Compute the scope prefix associated with PDI's parent, in
8186 compilation unit CU. The result will be allocated on CU's
8187 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8188 field. NULL is returned if no prefix is necessary. */
8190 partial_die_parent_scope (struct partial_die_info
*pdi
,
8191 struct dwarf2_cu
*cu
)
8193 const char *grandparent_scope
;
8194 struct partial_die_info
*parent
, *real_pdi
;
8196 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8197 then this means the parent of the specification DIE. */
8200 while (real_pdi
->has_specification
)
8202 auto res
= find_partial_die (real_pdi
->spec_offset
,
8203 real_pdi
->spec_is_dwz
, cu
);
8208 parent
= real_pdi
->die_parent
;
8212 if (parent
->scope_set
)
8213 return parent
->scope
;
8217 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8219 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8220 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8221 Work around this problem here. */
8222 if (cu
->language
== language_cplus
8223 && parent
->tag
== DW_TAG_namespace
8224 && strcmp (parent
->name
, "::") == 0
8225 && grandparent_scope
== NULL
)
8227 parent
->scope
= NULL
;
8228 parent
->scope_set
= 1;
8232 /* Nested subroutines in Fortran get a prefix. */
8233 if (pdi
->tag
== DW_TAG_enumerator
)
8234 /* Enumerators should not get the name of the enumeration as a prefix. */
8235 parent
->scope
= grandparent_scope
;
8236 else if (parent
->tag
== DW_TAG_namespace
8237 || parent
->tag
== DW_TAG_module
8238 || parent
->tag
== DW_TAG_structure_type
8239 || parent
->tag
== DW_TAG_class_type
8240 || parent
->tag
== DW_TAG_interface_type
8241 || parent
->tag
== DW_TAG_union_type
8242 || parent
->tag
== DW_TAG_enumeration_type
8243 || (cu
->language
== language_fortran
8244 && parent
->tag
== DW_TAG_subprogram
8245 && pdi
->tag
== DW_TAG_subprogram
))
8247 if (grandparent_scope
== NULL
)
8248 parent
->scope
= parent
->name
;
8250 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8252 parent
->name
, 0, cu
);
8256 /* FIXME drow/2004-04-01: What should we be doing with
8257 function-local names? For partial symbols, we should probably be
8259 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8260 dwarf_tag_name (parent
->tag
),
8261 sect_offset_str (pdi
->sect_off
));
8262 parent
->scope
= grandparent_scope
;
8265 parent
->scope_set
= 1;
8266 return parent
->scope
;
8269 /* Return the fully scoped name associated with PDI, from compilation unit
8270 CU. The result will be allocated with malloc. */
8272 static gdb::unique_xmalloc_ptr
<char>
8273 partial_die_full_name (struct partial_die_info
*pdi
,
8274 struct dwarf2_cu
*cu
)
8276 const char *parent_scope
;
8278 /* If this is a template instantiation, we can not work out the
8279 template arguments from partial DIEs. So, unfortunately, we have
8280 to go through the full DIEs. At least any work we do building
8281 types here will be reused if full symbols are loaded later. */
8282 if (pdi
->has_template_arguments
)
8286 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8288 struct die_info
*die
;
8289 struct attribute attr
;
8290 struct dwarf2_cu
*ref_cu
= cu
;
8292 /* DW_FORM_ref_addr is using section offset. */
8293 attr
.name
= (enum dwarf_attribute
) 0;
8294 attr
.form
= DW_FORM_ref_addr
;
8295 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8296 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8298 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8302 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8303 if (parent_scope
== NULL
)
8306 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8311 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8313 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
8314 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8315 struct gdbarch
*gdbarch
= objfile
->arch ();
8317 const char *actual_name
= NULL
;
8320 baseaddr
= objfile
->text_section_offset ();
8322 gdb::unique_xmalloc_ptr
<char> built_actual_name
8323 = partial_die_full_name (pdi
, cu
);
8324 if (built_actual_name
!= NULL
)
8325 actual_name
= built_actual_name
.get ();
8327 if (actual_name
== NULL
)
8328 actual_name
= pdi
->name
;
8330 partial_symbol psymbol
;
8331 memset (&psymbol
, 0, sizeof (psymbol
));
8332 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8333 psymbol
.ginfo
.section
= -1;
8335 /* The code below indicates that the psymbol should be installed by
8337 gdb::optional
<psymbol_placement
> where
;
8341 case DW_TAG_inlined_subroutine
:
8342 case DW_TAG_subprogram
:
8343 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8345 if (pdi
->is_external
8346 || cu
->language
== language_ada
8347 || (cu
->language
== language_fortran
8348 && pdi
->die_parent
!= NULL
8349 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8351 /* Normally, only "external" DIEs are part of the global scope.
8352 But in Ada and Fortran, we want to be able to access nested
8353 procedures globally. So all Ada and Fortran subprograms are
8354 stored in the global scope. */
8355 where
= psymbol_placement::GLOBAL
;
8358 where
= psymbol_placement::STATIC
;
8360 psymbol
.domain
= VAR_DOMAIN
;
8361 psymbol
.aclass
= LOC_BLOCK
;
8362 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8363 psymbol
.ginfo
.value
.address
= addr
;
8365 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8366 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8368 case DW_TAG_constant
:
8369 psymbol
.domain
= VAR_DOMAIN
;
8370 psymbol
.aclass
= LOC_STATIC
;
8371 where
= (pdi
->is_external
8372 ? psymbol_placement::GLOBAL
8373 : psymbol_placement::STATIC
);
8375 case DW_TAG_variable
:
8377 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8381 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8383 /* A global or static variable may also have been stripped
8384 out by the linker if unused, in which case its address
8385 will be nullified; do not add such variables into partial
8386 symbol table then. */
8388 else if (pdi
->is_external
)
8391 Don't enter into the minimal symbol tables as there is
8392 a minimal symbol table entry from the ELF symbols already.
8393 Enter into partial symbol table if it has a location
8394 descriptor or a type.
8395 If the location descriptor is missing, new_symbol will create
8396 a LOC_UNRESOLVED symbol, the address of the variable will then
8397 be determined from the minimal symbol table whenever the variable
8399 The address for the partial symbol table entry is not
8400 used by GDB, but it comes in handy for debugging partial symbol
8403 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8405 psymbol
.domain
= VAR_DOMAIN
;
8406 psymbol
.aclass
= LOC_STATIC
;
8407 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8408 psymbol
.ginfo
.value
.address
= addr
;
8409 where
= psymbol_placement::GLOBAL
;
8414 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8416 /* Static Variable. Skip symbols whose value we cannot know (those
8417 without location descriptors or constant values). */
8418 if (!has_loc
&& !pdi
->has_const_value
)
8421 psymbol
.domain
= VAR_DOMAIN
;
8422 psymbol
.aclass
= LOC_STATIC
;
8423 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8425 psymbol
.ginfo
.value
.address
= addr
;
8426 where
= psymbol_placement::STATIC
;
8429 case DW_TAG_typedef
:
8430 case DW_TAG_base_type
:
8431 case DW_TAG_subrange_type
:
8432 psymbol
.domain
= VAR_DOMAIN
;
8433 psymbol
.aclass
= LOC_TYPEDEF
;
8434 where
= psymbol_placement::STATIC
;
8436 case DW_TAG_imported_declaration
:
8437 case DW_TAG_namespace
:
8438 psymbol
.domain
= VAR_DOMAIN
;
8439 psymbol
.aclass
= LOC_TYPEDEF
;
8440 where
= psymbol_placement::GLOBAL
;
8443 /* With Fortran 77 there might be a "BLOCK DATA" module
8444 available without any name. If so, we skip the module as it
8445 doesn't bring any value. */
8446 if (actual_name
!= nullptr)
8448 psymbol
.domain
= MODULE_DOMAIN
;
8449 psymbol
.aclass
= LOC_TYPEDEF
;
8450 where
= psymbol_placement::GLOBAL
;
8453 case DW_TAG_class_type
:
8454 case DW_TAG_interface_type
:
8455 case DW_TAG_structure_type
:
8456 case DW_TAG_union_type
:
8457 case DW_TAG_enumeration_type
:
8458 /* Skip external references. The DWARF standard says in the section
8459 about "Structure, Union, and Class Type Entries": "An incomplete
8460 structure, union or class type is represented by a structure,
8461 union or class entry that does not have a byte size attribute
8462 and that has a DW_AT_declaration attribute." */
8463 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8466 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8467 static vs. global. */
8468 psymbol
.domain
= STRUCT_DOMAIN
;
8469 psymbol
.aclass
= LOC_TYPEDEF
;
8470 where
= (cu
->language
== language_cplus
8471 ? psymbol_placement::GLOBAL
8472 : psymbol_placement::STATIC
);
8474 case DW_TAG_enumerator
:
8475 psymbol
.domain
= VAR_DOMAIN
;
8476 psymbol
.aclass
= LOC_CONST
;
8477 where
= (cu
->language
== language_cplus
8478 ? psymbol_placement::GLOBAL
8479 : psymbol_placement::STATIC
);
8485 if (where
.has_value ())
8487 if (built_actual_name
!= nullptr)
8488 actual_name
= objfile
->intern (actual_name
);
8489 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8490 psymbol
.ginfo
.set_linkage_name (actual_name
);
8493 psymbol
.ginfo
.set_demangled_name (actual_name
,
8494 &objfile
->objfile_obstack
);
8495 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8497 add_psymbol_to_list (psymbol
, *where
, objfile
);
8501 /* Read a partial die corresponding to a namespace; also, add a symbol
8502 corresponding to that namespace to the symbol table. NAMESPACE is
8503 the name of the enclosing namespace. */
8506 add_partial_namespace (struct partial_die_info
*pdi
,
8507 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8508 int set_addrmap
, struct dwarf2_cu
*cu
)
8510 /* Add a symbol for the namespace. */
8512 add_partial_symbol (pdi
, cu
);
8514 /* Now scan partial symbols in that namespace. */
8516 if (pdi
->has_children
)
8517 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8520 /* Read a partial die corresponding to a Fortran module. */
8523 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8524 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8526 /* Add a symbol for the namespace. */
8528 add_partial_symbol (pdi
, cu
);
8530 /* Now scan partial symbols in that module. */
8532 if (pdi
->has_children
)
8533 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8536 /* Read a partial die corresponding to a subprogram or an inlined
8537 subprogram and create a partial symbol for that subprogram.
8538 When the CU language allows it, this routine also defines a partial
8539 symbol for each nested subprogram that this subprogram contains.
8540 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8541 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8543 PDI may also be a lexical block, in which case we simply search
8544 recursively for subprograms defined inside that lexical block.
8545 Again, this is only performed when the CU language allows this
8546 type of definitions. */
8549 add_partial_subprogram (struct partial_die_info
*pdi
,
8550 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8551 int set_addrmap
, struct dwarf2_cu
*cu
)
8553 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8555 if (pdi
->has_pc_info
)
8557 if (pdi
->lowpc
< *lowpc
)
8558 *lowpc
= pdi
->lowpc
;
8559 if (pdi
->highpc
> *highpc
)
8560 *highpc
= pdi
->highpc
;
8563 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8564 struct gdbarch
*gdbarch
= objfile
->arch ();
8566 CORE_ADDR this_highpc
;
8567 CORE_ADDR this_lowpc
;
8569 baseaddr
= objfile
->text_section_offset ();
8571 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8572 pdi
->lowpc
+ baseaddr
)
8575 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8576 pdi
->highpc
+ baseaddr
)
8578 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8579 this_lowpc
, this_highpc
- 1,
8580 cu
->per_cu
->v
.psymtab
);
8584 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8586 if (!pdi
->is_declaration
)
8587 /* Ignore subprogram DIEs that do not have a name, they are
8588 illegal. Do not emit a complaint at this point, we will
8589 do so when we convert this psymtab into a symtab. */
8591 add_partial_symbol (pdi
, cu
);
8595 if (! pdi
->has_children
)
8598 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8600 pdi
= pdi
->die_child
;
8604 if (pdi
->tag
== DW_TAG_subprogram
8605 || pdi
->tag
== DW_TAG_inlined_subroutine
8606 || pdi
->tag
== DW_TAG_lexical_block
)
8607 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8608 pdi
= pdi
->die_sibling
;
8613 /* Read a partial die corresponding to an enumeration type. */
8616 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8617 struct dwarf2_cu
*cu
)
8619 struct partial_die_info
*pdi
;
8621 if (enum_pdi
->name
!= NULL
)
8622 add_partial_symbol (enum_pdi
, cu
);
8624 pdi
= enum_pdi
->die_child
;
8627 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8628 complaint (_("malformed enumerator DIE ignored"));
8630 add_partial_symbol (pdi
, cu
);
8631 pdi
= pdi
->die_sibling
;
8635 /* Return the initial uleb128 in the die at INFO_PTR. */
8638 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8640 unsigned int bytes_read
;
8642 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8645 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8646 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8648 Return the corresponding abbrev, or NULL if the number is zero (indicating
8649 an empty DIE). In either case *BYTES_READ will be set to the length of
8650 the initial number. */
8652 static struct abbrev_info
*
8653 peek_die_abbrev (const die_reader_specs
&reader
,
8654 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8656 dwarf2_cu
*cu
= reader
.cu
;
8657 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8658 unsigned int abbrev_number
8659 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8661 if (abbrev_number
== 0)
8664 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8667 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8668 " at offset %s [in module %s]"),
8669 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8670 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8676 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8677 Returns a pointer to the end of a series of DIEs, terminated by an empty
8678 DIE. Any children of the skipped DIEs will also be skipped. */
8680 static const gdb_byte
*
8681 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8685 unsigned int bytes_read
;
8686 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8689 return info_ptr
+ bytes_read
;
8691 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8695 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8696 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8697 abbrev corresponding to that skipped uleb128 should be passed in
8698 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8701 static const gdb_byte
*
8702 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8703 struct abbrev_info
*abbrev
)
8705 unsigned int bytes_read
;
8706 struct attribute attr
;
8707 bfd
*abfd
= reader
->abfd
;
8708 struct dwarf2_cu
*cu
= reader
->cu
;
8709 const gdb_byte
*buffer
= reader
->buffer
;
8710 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8711 unsigned int form
, i
;
8713 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8715 /* The only abbrev we care about is DW_AT_sibling. */
8716 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8719 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8721 if (attr
.form
== DW_FORM_ref_addr
)
8722 complaint (_("ignoring absolute DW_AT_sibling"));
8725 sect_offset off
= attr
.get_ref_die_offset ();
8726 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8728 if (sibling_ptr
< info_ptr
)
8729 complaint (_("DW_AT_sibling points backwards"));
8730 else if (sibling_ptr
> reader
->buffer_end
)
8731 reader
->die_section
->overflow_complaint ();
8737 /* If it isn't DW_AT_sibling, skip this attribute. */
8738 form
= abbrev
->attrs
[i
].form
;
8742 case DW_FORM_ref_addr
:
8743 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8744 and later it is offset sized. */
8745 if (cu
->header
.version
== 2)
8746 info_ptr
+= cu
->header
.addr_size
;
8748 info_ptr
+= cu
->header
.offset_size
;
8750 case DW_FORM_GNU_ref_alt
:
8751 info_ptr
+= cu
->header
.offset_size
;
8754 info_ptr
+= cu
->header
.addr_size
;
8762 case DW_FORM_flag_present
:
8763 case DW_FORM_implicit_const
:
8780 case DW_FORM_ref_sig8
:
8783 case DW_FORM_data16
:
8786 case DW_FORM_string
:
8787 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8788 info_ptr
+= bytes_read
;
8790 case DW_FORM_sec_offset
:
8792 case DW_FORM_GNU_strp_alt
:
8793 info_ptr
+= cu
->header
.offset_size
;
8795 case DW_FORM_exprloc
:
8797 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8798 info_ptr
+= bytes_read
;
8800 case DW_FORM_block1
:
8801 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8803 case DW_FORM_block2
:
8804 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8806 case DW_FORM_block4
:
8807 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8813 case DW_FORM_ref_udata
:
8814 case DW_FORM_GNU_addr_index
:
8815 case DW_FORM_GNU_str_index
:
8816 case DW_FORM_rnglistx
:
8817 case DW_FORM_loclistx
:
8818 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8820 case DW_FORM_indirect
:
8821 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8822 info_ptr
+= bytes_read
;
8823 /* We need to continue parsing from here, so just go back to
8825 goto skip_attribute
;
8828 error (_("Dwarf Error: Cannot handle %s "
8829 "in DWARF reader [in module %s]"),
8830 dwarf_form_name (form
),
8831 bfd_get_filename (abfd
));
8835 if (abbrev
->has_children
)
8836 return skip_children (reader
, info_ptr
);
8841 /* Locate ORIG_PDI's sibling.
8842 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8844 static const gdb_byte
*
8845 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8846 struct partial_die_info
*orig_pdi
,
8847 const gdb_byte
*info_ptr
)
8849 /* Do we know the sibling already? */
8851 if (orig_pdi
->sibling
)
8852 return orig_pdi
->sibling
;
8854 /* Are there any children to deal with? */
8856 if (!orig_pdi
->has_children
)
8859 /* Skip the children the long way. */
8861 return skip_children (reader
, info_ptr
);
8864 /* Expand this partial symbol table into a full symbol table. SELF is
8868 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8870 struct dwarf2_per_objfile
*dwarf2_per_objfile
8871 = get_dwarf2_per_objfile (objfile
);
8873 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8875 /* If this psymtab is constructed from a debug-only objfile, the
8876 has_section_at_zero flag will not necessarily be correct. We
8877 can get the correct value for this flag by looking at the data
8878 associated with the (presumably stripped) associated objfile. */
8879 if (objfile
->separate_debug_objfile_backlink
)
8881 struct dwarf2_per_objfile
*dpo_backlink
8882 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8884 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8885 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8888 expand_psymtab (objfile
);
8890 process_cu_includes (dwarf2_per_objfile
);
8893 /* Reading in full CUs. */
8895 /* Add PER_CU to the queue. */
8898 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8899 dwarf2_per_objfile
*per_objfile
,
8900 enum language pretend_language
)
8903 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
8906 /* If PER_CU is not yet queued, add it to the queue.
8907 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8909 The result is non-zero if PER_CU was queued, otherwise the result is zero
8910 meaning either PER_CU is already queued or it is already loaded.
8912 N.B. There is an invariant here that if a CU is queued then it is loaded.
8913 The caller is required to load PER_CU if we return non-zero. */
8916 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8917 dwarf2_per_cu_data
*per_cu
,
8918 dwarf2_per_objfile
*per_objfile
,
8919 enum language pretend_language
)
8921 /* We may arrive here during partial symbol reading, if we need full
8922 DIEs to process an unusual case (e.g. template arguments). Do
8923 not queue PER_CU, just tell our caller to load its DIEs. */
8924 if (per_cu
->per_bfd
->reading_partial_symbols
)
8926 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8928 if (cu
== NULL
|| cu
->dies
== NULL
)
8933 /* Mark the dependence relation so that we don't flush PER_CU
8935 if (dependent_cu
!= NULL
)
8936 dwarf2_add_dependence (dependent_cu
, per_cu
);
8938 /* If it's already on the queue, we have nothing to do. */
8942 /* If the compilation unit is already loaded, just mark it as
8944 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8951 /* Add it to the queue. */
8952 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8957 /* Process the queue. */
8960 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8962 if (dwarf_read_debug
)
8964 fprintf_unfiltered (gdb_stdlog
,
8965 "Expanding one or more symtabs of objfile %s ...\n",
8966 objfile_name (dwarf2_per_objfile
->objfile
));
8969 /* The queue starts out with one item, but following a DIE reference
8970 may load a new CU, adding it to the end of the queue. */
8971 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
8973 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
8974 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8976 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
8978 dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
8980 /* Skip dummy CUs. */
8983 unsigned int debug_print_threshold
;
8986 if (per_cu
->is_debug_types
)
8988 struct signatured_type
*sig_type
=
8989 (struct signatured_type
*) per_cu
;
8991 sprintf (buf
, "TU %s at offset %s",
8992 hex_string (sig_type
->signature
),
8993 sect_offset_str (per_cu
->sect_off
));
8994 /* There can be 100s of TUs.
8995 Only print them in verbose mode. */
8996 debug_print_threshold
= 2;
9000 sprintf (buf
, "CU at offset %s",
9001 sect_offset_str (per_cu
->sect_off
));
9002 debug_print_threshold
= 1;
9005 if (dwarf_read_debug
>= debug_print_threshold
)
9006 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9008 if (per_cu
->is_debug_types
)
9009 process_full_type_unit (cu
, item
.pretend_language
);
9011 process_full_comp_unit (cu
, item
.pretend_language
);
9013 if (dwarf_read_debug
>= debug_print_threshold
)
9014 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9019 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9022 if (dwarf_read_debug
)
9024 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9025 objfile_name (dwarf2_per_objfile
->objfile
));
9029 /* Read in full symbols for PST, and anything it depends on. */
9032 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9034 gdb_assert (!readin_p (objfile
));
9036 expand_dependencies (objfile
);
9038 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9039 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9040 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9043 /* See psympriv.h. */
9046 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9048 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9049 return per_objfile
->symtab_set_p (per_cu_data
);
9052 /* See psympriv.h. */
9055 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9057 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9058 return per_objfile
->get_symtab (per_cu_data
);
9061 /* Trivial hash function for die_info: the hash value of a DIE
9062 is its offset in .debug_info for this objfile. */
9065 die_hash (const void *item
)
9067 const struct die_info
*die
= (const struct die_info
*) item
;
9069 return to_underlying (die
->sect_off
);
9072 /* Trivial comparison function for die_info structures: two DIEs
9073 are equal if they have the same offset. */
9076 die_eq (const void *item_lhs
, const void *item_rhs
)
9078 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9079 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9081 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9084 /* Load the DIEs associated with PER_CU into memory. */
9087 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9088 dwarf2_per_objfile
*per_objfile
,
9090 enum language pretend_language
)
9092 gdb_assert (! this_cu
->is_debug_types
);
9094 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9095 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9099 struct dwarf2_cu
*cu
= reader
.cu
;
9100 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9102 gdb_assert (cu
->die_hash
== NULL
);
9104 htab_create_alloc_ex (cu
->header
.length
/ 12,
9108 &cu
->comp_unit_obstack
,
9109 hashtab_obstack_allocate
,
9110 dummy_obstack_deallocate
);
9112 if (reader
.comp_unit_die
->has_children
)
9113 reader
.comp_unit_die
->child
9114 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9115 &info_ptr
, reader
.comp_unit_die
);
9116 cu
->dies
= reader
.comp_unit_die
;
9117 /* comp_unit_die is not stored in die_hash, no need. */
9119 /* We try not to read any attributes in this function, because not
9120 all CUs needed for references have been loaded yet, and symbol
9121 table processing isn't initialized. But we have to set the CU language,
9122 or we won't be able to build types correctly.
9123 Similarly, if we do not read the producer, we can not apply
9124 producer-specific interpretation. */
9125 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9130 /* Add a DIE to the delayed physname list. */
9133 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9134 const char *name
, struct die_info
*die
,
9135 struct dwarf2_cu
*cu
)
9137 struct delayed_method_info mi
;
9139 mi
.fnfield_index
= fnfield_index
;
9143 cu
->method_list
.push_back (mi
);
9146 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9147 "const" / "volatile". If so, decrements LEN by the length of the
9148 modifier and return true. Otherwise return false. */
9152 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9154 size_t mod_len
= sizeof (mod
) - 1;
9155 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9163 /* Compute the physnames of any methods on the CU's method list.
9165 The computation of method physnames is delayed in order to avoid the
9166 (bad) condition that one of the method's formal parameters is of an as yet
9170 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9172 /* Only C++ delays computing physnames. */
9173 if (cu
->method_list
.empty ())
9175 gdb_assert (cu
->language
== language_cplus
);
9177 for (const delayed_method_info
&mi
: cu
->method_list
)
9179 const char *physname
;
9180 struct fn_fieldlist
*fn_flp
9181 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9182 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9183 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9184 = physname
? physname
: "";
9186 /* Since there's no tag to indicate whether a method is a
9187 const/volatile overload, extract that information out of the
9189 if (physname
!= NULL
)
9191 size_t len
= strlen (physname
);
9195 if (physname
[len
] == ')') /* shortcut */
9197 else if (check_modifier (physname
, len
, " const"))
9198 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9199 else if (check_modifier (physname
, len
, " volatile"))
9200 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9207 /* The list is no longer needed. */
9208 cu
->method_list
.clear ();
9211 /* Go objects should be embedded in a DW_TAG_module DIE,
9212 and it's not clear if/how imported objects will appear.
9213 To keep Go support simple until that's worked out,
9214 go back through what we've read and create something usable.
9215 We could do this while processing each DIE, and feels kinda cleaner,
9216 but that way is more invasive.
9217 This is to, for example, allow the user to type "p var" or "b main"
9218 without having to specify the package name, and allow lookups
9219 of module.object to work in contexts that use the expression
9223 fixup_go_packaging (struct dwarf2_cu
*cu
)
9225 gdb::unique_xmalloc_ptr
<char> package_name
;
9226 struct pending
*list
;
9229 for (list
= *cu
->get_builder ()->get_global_symbols ();
9233 for (i
= 0; i
< list
->nsyms
; ++i
)
9235 struct symbol
*sym
= list
->symbol
[i
];
9237 if (sym
->language () == language_go
9238 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9240 gdb::unique_xmalloc_ptr
<char> this_package_name
9241 (go_symbol_package_name (sym
));
9243 if (this_package_name
== NULL
)
9245 if (package_name
== NULL
)
9246 package_name
= std::move (this_package_name
);
9249 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9250 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9251 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9252 (symbol_symtab (sym
) != NULL
9253 ? symtab_to_filename_for_display
9254 (symbol_symtab (sym
))
9255 : objfile_name (objfile
)),
9256 this_package_name
.get (), package_name
.get ());
9262 if (package_name
!= NULL
)
9264 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9265 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9266 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9267 saved_package_name
);
9270 sym
= new (&objfile
->objfile_obstack
) symbol
;
9271 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9272 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9273 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9274 e.g., "main" finds the "main" module and not C's main(). */
9275 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9276 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9277 SYMBOL_TYPE (sym
) = type
;
9279 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9283 /* Allocate a fully-qualified name consisting of the two parts on the
9287 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9289 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9292 /* A helper that allocates a variant part to attach to a Rust enum
9293 type. OBSTACK is where the results should be allocated. TYPE is
9294 the type we're processing. DISCRIMINANT_INDEX is the index of the
9295 discriminant. It must be the index of one of the fields of TYPE.
9296 DEFAULT_INDEX is the index of the default field; or -1 if there is
9297 no default. RANGES is indexed by "effective" field number (the
9298 field index, but omitting the discriminant and default fields) and
9299 must hold the discriminant values used by the variants. Note that
9300 RANGES must have a lifetime at least as long as OBSTACK -- either
9301 already allocated on it, or static. */
9304 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9305 int discriminant_index
, int default_index
,
9306 gdb::array_view
<discriminant_range
> ranges
)
9308 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9309 must be handled by the caller. */
9310 gdb_assert (discriminant_index
>= 0
9311 && discriminant_index
< type
->num_fields ());
9312 gdb_assert (default_index
== -1
9313 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9315 /* We have one variant for each non-discriminant field. */
9316 int n_variants
= type
->num_fields () - 1;
9318 variant
*variants
= new (obstack
) variant
[n_variants
];
9321 for (int i
= 0; i
< type
->num_fields (); ++i
)
9323 if (i
== discriminant_index
)
9326 variants
[var_idx
].first_field
= i
;
9327 variants
[var_idx
].last_field
= i
+ 1;
9329 /* The default field does not need a range, but other fields do.
9330 We skipped the discriminant above. */
9331 if (i
!= default_index
)
9333 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9340 gdb_assert (range_idx
== ranges
.size ());
9341 gdb_assert (var_idx
== n_variants
);
9343 variant_part
*part
= new (obstack
) variant_part
;
9344 part
->discriminant_index
= discriminant_index
;
9345 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9346 discriminant_index
));
9347 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9349 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9350 gdb::array_view
<variant_part
> *prop_value
9351 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9353 struct dynamic_prop prop
;
9354 prop
.kind
= PROP_VARIANT_PARTS
;
9355 prop
.data
.variant_parts
= prop_value
;
9357 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9360 /* Some versions of rustc emitted enums in an unusual way.
9362 Ordinary enums were emitted as unions. The first element of each
9363 structure in the union was named "RUST$ENUM$DISR". This element
9364 held the discriminant.
9366 These versions of Rust also implemented the "non-zero"
9367 optimization. When the enum had two values, and one is empty and
9368 the other holds a pointer that cannot be zero, the pointer is used
9369 as the discriminant, with a zero value meaning the empty variant.
9370 Here, the union's first member is of the form
9371 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9372 where the fieldnos are the indices of the fields that should be
9373 traversed in order to find the field (which may be several fields deep)
9374 and the variantname is the name of the variant of the case when the
9377 This function recognizes whether TYPE is of one of these forms,
9378 and, if so, smashes it to be a variant type. */
9381 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9383 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9385 /* We don't need to deal with empty enums. */
9386 if (type
->num_fields () == 0)
9389 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9390 if (type
->num_fields () == 1
9391 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9393 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9395 /* Decode the field name to find the offset of the
9397 ULONGEST bit_offset
= 0;
9398 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9399 while (name
[0] >= '0' && name
[0] <= '9')
9402 unsigned long index
= strtoul (name
, &tail
, 10);
9405 || index
>= field_type
->num_fields ()
9406 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9407 != FIELD_LOC_KIND_BITPOS
))
9409 complaint (_("Could not parse Rust enum encoding string \"%s\""
9411 TYPE_FIELD_NAME (type
, 0),
9412 objfile_name (objfile
));
9417 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9418 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9421 /* Smash this type to be a structure type. We have to do this
9422 because the type has already been recorded. */
9423 type
->set_code (TYPE_CODE_STRUCT
);
9424 type
->set_num_fields (3);
9425 /* Save the field we care about. */
9426 struct field saved_field
= type
->field (0);
9428 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9430 /* Put the discriminant at index 0. */
9431 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9432 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9433 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9434 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9436 /* The order of fields doesn't really matter, so put the real
9437 field at index 1 and the data-less field at index 2. */
9438 type
->field (1) = saved_field
;
9439 TYPE_FIELD_NAME (type
, 1)
9440 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9441 TYPE_FIELD_TYPE (type
, 1)->set_name
9442 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9443 TYPE_FIELD_NAME (type
, 1)));
9445 const char *dataless_name
9446 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9448 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9450 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9451 /* NAME points into the original discriminant name, which
9452 already has the correct lifetime. */
9453 TYPE_FIELD_NAME (type
, 2) = name
;
9454 SET_FIELD_BITPOS (type
->field (2), 0);
9456 /* Indicate that this is a variant type. */
9457 static discriminant_range ranges
[1] = { { 0, 0 } };
9458 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9460 /* A union with a single anonymous field is probably an old-style
9462 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9464 /* Smash this type to be a structure type. We have to do this
9465 because the type has already been recorded. */
9466 type
->set_code (TYPE_CODE_STRUCT
);
9468 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9469 const char *variant_name
9470 = rust_last_path_segment (field_type
->name ());
9471 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9472 field_type
->set_name
9473 (rust_fully_qualify (&objfile
->objfile_obstack
,
9474 type
->name (), variant_name
));
9478 struct type
*disr_type
= nullptr;
9479 for (int i
= 0; i
< type
->num_fields (); ++i
)
9481 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9483 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9485 /* All fields of a true enum will be structs. */
9488 else if (disr_type
->num_fields () == 0)
9490 /* Could be data-less variant, so keep going. */
9491 disr_type
= nullptr;
9493 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9494 "RUST$ENUM$DISR") != 0)
9496 /* Not a Rust enum. */
9506 /* If we got here without a discriminant, then it's probably
9508 if (disr_type
== nullptr)
9511 /* Smash this type to be a structure type. We have to do this
9512 because the type has already been recorded. */
9513 type
->set_code (TYPE_CODE_STRUCT
);
9515 /* Make space for the discriminant field. */
9516 struct field
*disr_field
= &disr_type
->field (0);
9518 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9519 * sizeof (struct field
)));
9520 memcpy (new_fields
+ 1, type
->fields (),
9521 type
->num_fields () * sizeof (struct field
));
9522 type
->set_fields (new_fields
);
9523 type
->set_num_fields (type
->num_fields () + 1);
9525 /* Install the discriminant at index 0 in the union. */
9526 type
->field (0) = *disr_field
;
9527 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9528 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9530 /* We need a way to find the correct discriminant given a
9531 variant name. For convenience we build a map here. */
9532 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9533 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9534 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9536 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9539 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9540 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9544 int n_fields
= type
->num_fields ();
9545 /* We don't need a range entry for the discriminant, but we do
9546 need one for every other field, as there is no default
9548 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9551 /* Skip the discriminant here. */
9552 for (int i
= 1; i
< n_fields
; ++i
)
9554 /* Find the final word in the name of this variant's type.
9555 That name can be used to look up the correct
9557 const char *variant_name
9558 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9560 auto iter
= discriminant_map
.find (variant_name
);
9561 if (iter
!= discriminant_map
.end ())
9563 ranges
[i
].low
= iter
->second
;
9564 ranges
[i
].high
= iter
->second
;
9567 /* Remove the discriminant field, if it exists. */
9568 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9569 if (sub_type
->num_fields () > 0)
9571 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9572 sub_type
->set_fields (sub_type
->fields () + 1);
9574 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9576 (rust_fully_qualify (&objfile
->objfile_obstack
,
9577 type
->name (), variant_name
));
9580 /* Indicate that this is a variant type. */
9581 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9582 gdb::array_view
<discriminant_range
> (ranges
,
9587 /* Rewrite some Rust unions to be structures with variants parts. */
9590 rust_union_quirks (struct dwarf2_cu
*cu
)
9592 gdb_assert (cu
->language
== language_rust
);
9593 for (type
*type_
: cu
->rust_unions
)
9594 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9595 /* We don't need this any more. */
9596 cu
->rust_unions
.clear ();
9601 type_unit_group_unshareable
*
9602 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9604 auto iter
= this->m_type_units
.find (tu_group
);
9605 if (iter
!= this->m_type_units
.end ())
9606 return iter
->second
.get ();
9608 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9609 type_unit_group_unshareable
*result
= uniq
.get ();
9610 this->m_type_units
[tu_group
] = std::move (uniq
);
9615 dwarf2_per_objfile::get_type_for_signatured_type
9616 (signatured_type
*sig_type
) const
9618 auto iter
= this->m_type_map
.find (sig_type
);
9619 if (iter
== this->m_type_map
.end ())
9622 return iter
->second
;
9625 void dwarf2_per_objfile::set_type_for_signatured_type
9626 (signatured_type
*sig_type
, struct type
*type
)
9628 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9630 this->m_type_map
[sig_type
] = type
;
9633 /* A helper function for computing the list of all symbol tables
9634 included by PER_CU. */
9637 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9638 htab_t all_children
, htab_t all_type_symtabs
,
9639 dwarf2_per_cu_data
*per_cu
,
9640 dwarf2_per_objfile
*per_objfile
,
9641 struct compunit_symtab
*immediate_parent
)
9643 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9646 /* This inclusion and its children have been processed. */
9652 /* Only add a CU if it has a symbol table. */
9653 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9656 /* If this is a type unit only add its symbol table if we haven't
9657 seen it yet (type unit per_cu's can share symtabs). */
9658 if (per_cu
->is_debug_types
)
9660 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9664 result
->push_back (cust
);
9665 if (cust
->user
== NULL
)
9666 cust
->user
= immediate_parent
;
9671 result
->push_back (cust
);
9672 if (cust
->user
== NULL
)
9673 cust
->user
= immediate_parent
;
9677 if (!per_cu
->imported_symtabs_empty ())
9678 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9680 recursively_compute_inclusions (result
, all_children
,
9681 all_type_symtabs
, ptr
, per_objfile
,
9686 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9690 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9691 dwarf2_per_objfile
*per_objfile
)
9693 gdb_assert (! per_cu
->is_debug_types
);
9695 if (!per_cu
->imported_symtabs_empty ())
9698 std::vector
<compunit_symtab
*> result_symtabs
;
9699 htab_t all_children
, all_type_symtabs
;
9700 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9702 /* If we don't have a symtab, we can just skip this case. */
9706 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9707 NULL
, xcalloc
, xfree
);
9708 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9709 NULL
, xcalloc
, xfree
);
9711 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9713 recursively_compute_inclusions (&result_symtabs
, all_children
,
9714 all_type_symtabs
, ptr
, per_objfile
,
9718 /* Now we have a transitive closure of all the included symtabs. */
9719 len
= result_symtabs
.size ();
9721 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9722 struct compunit_symtab
*, len
+ 1);
9723 memcpy (cust
->includes
, result_symtabs
.data (),
9724 len
* sizeof (compunit_symtab
*));
9725 cust
->includes
[len
] = NULL
;
9727 htab_delete (all_children
);
9728 htab_delete (all_type_symtabs
);
9732 /* Compute the 'includes' field for the symtabs of all the CUs we just
9736 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9738 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9740 if (! iter
->is_debug_types
)
9741 compute_compunit_symtab_includes (iter
, dwarf2_per_objfile
);
9744 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9747 /* Generate full symbol information for CU, whose DIEs have
9748 already been loaded into memory. */
9751 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9753 dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
9754 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9755 struct gdbarch
*gdbarch
= objfile
->arch ();
9756 CORE_ADDR lowpc
, highpc
;
9757 struct compunit_symtab
*cust
;
9759 struct block
*static_block
;
9762 baseaddr
= objfile
->text_section_offset ();
9764 /* Clear the list here in case something was left over. */
9765 cu
->method_list
.clear ();
9767 cu
->language
= pretend_language
;
9768 cu
->language_defn
= language_def (cu
->language
);
9770 /* Do line number decoding in read_file_scope () */
9771 process_die (cu
->dies
, cu
);
9773 /* For now fudge the Go package. */
9774 if (cu
->language
== language_go
)
9775 fixup_go_packaging (cu
);
9777 /* Now that we have processed all the DIEs in the CU, all the types
9778 should be complete, and it should now be safe to compute all of the
9780 compute_delayed_physnames (cu
);
9782 if (cu
->language
== language_rust
)
9783 rust_union_quirks (cu
);
9785 /* Some compilers don't define a DW_AT_high_pc attribute for the
9786 compilation unit. If the DW_AT_high_pc is missing, synthesize
9787 it, by scanning the DIE's below the compilation unit. */
9788 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9790 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9791 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9793 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9794 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9795 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9796 addrmap to help ensure it has an accurate map of pc values belonging to
9798 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9800 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9801 SECT_OFF_TEXT (objfile
),
9806 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9808 /* Set symtab language to language from DW_AT_language. If the
9809 compilation is from a C file generated by language preprocessors, do
9810 not set the language if it was already deduced by start_subfile. */
9811 if (!(cu
->language
== language_c
9812 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9813 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9815 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9816 produce DW_AT_location with location lists but it can be possibly
9817 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9818 there were bugs in prologue debug info, fixed later in GCC-4.5
9819 by "unwind info for epilogues" patch (which is not directly related).
9821 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9822 needed, it would be wrong due to missing DW_AT_producer there.
9824 Still one can confuse GDB by using non-standard GCC compilation
9825 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9827 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9828 cust
->locations_valid
= 1;
9830 if (gcc_4_minor
>= 5)
9831 cust
->epilogue_unwind_valid
= 1;
9833 cust
->call_site_htab
= cu
->call_site_htab
;
9836 dwarf2_per_objfile
->set_symtab (cu
->per_cu
, cust
);
9838 /* Push it for inclusion processing later. */
9839 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9841 /* Not needed any more. */
9842 cu
->reset_builder ();
9845 /* Generate full symbol information for type unit CU, whose DIEs have
9846 already been loaded into memory. */
9849 process_full_type_unit (dwarf2_cu
*cu
,
9850 enum language pretend_language
)
9852 dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
9853 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9854 struct compunit_symtab
*cust
;
9855 struct signatured_type
*sig_type
;
9857 gdb_assert (cu
->per_cu
->is_debug_types
);
9858 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9860 /* Clear the list here in case something was left over. */
9861 cu
->method_list
.clear ();
9863 cu
->language
= pretend_language
;
9864 cu
->language_defn
= language_def (cu
->language
);
9866 /* The symbol tables are set up in read_type_unit_scope. */
9867 process_die (cu
->dies
, cu
);
9869 /* For now fudge the Go package. */
9870 if (cu
->language
== language_go
)
9871 fixup_go_packaging (cu
);
9873 /* Now that we have processed all the DIEs in the CU, all the types
9874 should be complete, and it should now be safe to compute all of the
9876 compute_delayed_physnames (cu
);
9878 if (cu
->language
== language_rust
)
9879 rust_union_quirks (cu
);
9881 /* TUs share symbol tables.
9882 If this is the first TU to use this symtab, complete the construction
9883 of it with end_expandable_symtab. Otherwise, complete the addition of
9884 this TU's symbols to the existing symtab. */
9885 type_unit_group_unshareable
*tug_unshare
=
9886 dwarf2_per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9887 if (tug_unshare
->compunit_symtab
== NULL
)
9889 buildsym_compunit
*builder
= cu
->get_builder ();
9890 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9891 tug_unshare
->compunit_symtab
= cust
;
9895 /* Set symtab language to language from DW_AT_language. If the
9896 compilation is from a C file generated by language preprocessors,
9897 do not set the language if it was already deduced by
9899 if (!(cu
->language
== language_c
9900 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9901 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9906 cu
->get_builder ()->augment_type_symtab ();
9907 cust
= tug_unshare
->compunit_symtab
;
9910 dwarf2_per_objfile
->set_symtab (cu
->per_cu
, cust
);
9912 /* Not needed any more. */
9913 cu
->reset_builder ();
9916 /* Process an imported unit DIE. */
9919 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9921 struct attribute
*attr
;
9923 /* For now we don't handle imported units in type units. */
9924 if (cu
->per_cu
->is_debug_types
)
9926 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9927 " supported in type units [in module %s]"),
9928 objfile_name (cu
->per_objfile
->objfile
));
9931 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9934 sect_offset sect_off
= attr
->get_ref_die_offset ();
9935 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9936 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9937 dwarf2_per_cu_data
*per_cu
9938 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9940 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9941 into another compilation unit, at root level. Regard this as a hint,
9943 if (die
->parent
&& die
->parent
->parent
== NULL
9944 && per_cu
->unit_type
== DW_UT_compile
9945 && per_cu
->lang
== language_cplus
)
9948 /* If necessary, add it to the queue and load its DIEs. */
9949 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9950 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
9952 cu
->per_cu
->imported_symtabs_push (per_cu
);
9956 /* RAII object that represents a process_die scope: i.e.,
9957 starts/finishes processing a DIE. */
9958 class process_die_scope
9961 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9962 : m_die (die
), m_cu (cu
)
9964 /* We should only be processing DIEs not already in process. */
9965 gdb_assert (!m_die
->in_process
);
9966 m_die
->in_process
= true;
9969 ~process_die_scope ()
9971 m_die
->in_process
= false;
9973 /* If we're done processing the DIE for the CU that owns the line
9974 header, we don't need the line header anymore. */
9975 if (m_cu
->line_header_die_owner
== m_die
)
9977 delete m_cu
->line_header
;
9978 m_cu
->line_header
= NULL
;
9979 m_cu
->line_header_die_owner
= NULL
;
9988 /* Process a die and its children. */
9991 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9993 process_die_scope
scope (die
, cu
);
9997 case DW_TAG_padding
:
9999 case DW_TAG_compile_unit
:
10000 case DW_TAG_partial_unit
:
10001 read_file_scope (die
, cu
);
10003 case DW_TAG_type_unit
:
10004 read_type_unit_scope (die
, cu
);
10006 case DW_TAG_subprogram
:
10007 /* Nested subprograms in Fortran get a prefix. */
10008 if (cu
->language
== language_fortran
10009 && die
->parent
!= NULL
10010 && die
->parent
->tag
== DW_TAG_subprogram
)
10011 cu
->processing_has_namespace_info
= true;
10012 /* Fall through. */
10013 case DW_TAG_inlined_subroutine
:
10014 read_func_scope (die
, cu
);
10016 case DW_TAG_lexical_block
:
10017 case DW_TAG_try_block
:
10018 case DW_TAG_catch_block
:
10019 read_lexical_block_scope (die
, cu
);
10021 case DW_TAG_call_site
:
10022 case DW_TAG_GNU_call_site
:
10023 read_call_site_scope (die
, cu
);
10025 case DW_TAG_class_type
:
10026 case DW_TAG_interface_type
:
10027 case DW_TAG_structure_type
:
10028 case DW_TAG_union_type
:
10029 process_structure_scope (die
, cu
);
10031 case DW_TAG_enumeration_type
:
10032 process_enumeration_scope (die
, cu
);
10035 /* These dies have a type, but processing them does not create
10036 a symbol or recurse to process the children. Therefore we can
10037 read them on-demand through read_type_die. */
10038 case DW_TAG_subroutine_type
:
10039 case DW_TAG_set_type
:
10040 case DW_TAG_array_type
:
10041 case DW_TAG_pointer_type
:
10042 case DW_TAG_ptr_to_member_type
:
10043 case DW_TAG_reference_type
:
10044 case DW_TAG_rvalue_reference_type
:
10045 case DW_TAG_string_type
:
10048 case DW_TAG_base_type
:
10049 case DW_TAG_subrange_type
:
10050 case DW_TAG_typedef
:
10051 /* Add a typedef symbol for the type definition, if it has a
10053 new_symbol (die
, read_type_die (die
, cu
), cu
);
10055 case DW_TAG_common_block
:
10056 read_common_block (die
, cu
);
10058 case DW_TAG_common_inclusion
:
10060 case DW_TAG_namespace
:
10061 cu
->processing_has_namespace_info
= true;
10062 read_namespace (die
, cu
);
10064 case DW_TAG_module
:
10065 cu
->processing_has_namespace_info
= true;
10066 read_module (die
, cu
);
10068 case DW_TAG_imported_declaration
:
10069 cu
->processing_has_namespace_info
= true;
10070 if (read_namespace_alias (die
, cu
))
10072 /* The declaration is not a global namespace alias. */
10073 /* Fall through. */
10074 case DW_TAG_imported_module
:
10075 cu
->processing_has_namespace_info
= true;
10076 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10077 || cu
->language
!= language_fortran
))
10078 complaint (_("Tag '%s' has unexpected children"),
10079 dwarf_tag_name (die
->tag
));
10080 read_import_statement (die
, cu
);
10083 case DW_TAG_imported_unit
:
10084 process_imported_unit_die (die
, cu
);
10087 case DW_TAG_variable
:
10088 read_variable (die
, cu
);
10092 new_symbol (die
, NULL
, cu
);
10097 /* DWARF name computation. */
10099 /* A helper function for dwarf2_compute_name which determines whether DIE
10100 needs to have the name of the scope prepended to the name listed in the
10104 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10106 struct attribute
*attr
;
10110 case DW_TAG_namespace
:
10111 case DW_TAG_typedef
:
10112 case DW_TAG_class_type
:
10113 case DW_TAG_interface_type
:
10114 case DW_TAG_structure_type
:
10115 case DW_TAG_union_type
:
10116 case DW_TAG_enumeration_type
:
10117 case DW_TAG_enumerator
:
10118 case DW_TAG_subprogram
:
10119 case DW_TAG_inlined_subroutine
:
10120 case DW_TAG_member
:
10121 case DW_TAG_imported_declaration
:
10124 case DW_TAG_variable
:
10125 case DW_TAG_constant
:
10126 /* We only need to prefix "globally" visible variables. These include
10127 any variable marked with DW_AT_external or any variable that
10128 lives in a namespace. [Variables in anonymous namespaces
10129 require prefixing, but they are not DW_AT_external.] */
10131 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10133 struct dwarf2_cu
*spec_cu
= cu
;
10135 return die_needs_namespace (die_specification (die
, &spec_cu
),
10139 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10140 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10141 && die
->parent
->tag
!= DW_TAG_module
)
10143 /* A variable in a lexical block of some kind does not need a
10144 namespace, even though in C++ such variables may be external
10145 and have a mangled name. */
10146 if (die
->parent
->tag
== DW_TAG_lexical_block
10147 || die
->parent
->tag
== DW_TAG_try_block
10148 || die
->parent
->tag
== DW_TAG_catch_block
10149 || die
->parent
->tag
== DW_TAG_subprogram
)
10158 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10159 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10160 defined for the given DIE. */
10162 static struct attribute
*
10163 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10165 struct attribute
*attr
;
10167 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10169 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10174 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10175 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10176 defined for the given DIE. */
10178 static const char *
10179 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10181 const char *linkage_name
;
10183 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10184 if (linkage_name
== NULL
)
10185 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10187 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10188 See https://github.com/rust-lang/rust/issues/32925. */
10189 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10190 && strchr (linkage_name
, '{') != NULL
)
10191 linkage_name
= NULL
;
10193 return linkage_name
;
10196 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10197 compute the physname for the object, which include a method's:
10198 - formal parameters (C++),
10199 - receiver type (Go),
10201 The term "physname" is a bit confusing.
10202 For C++, for example, it is the demangled name.
10203 For Go, for example, it's the mangled name.
10205 For Ada, return the DIE's linkage name rather than the fully qualified
10206 name. PHYSNAME is ignored..
10208 The result is allocated on the objfile->per_bfd's obstack and
10211 static const char *
10212 dwarf2_compute_name (const char *name
,
10213 struct die_info
*die
, struct dwarf2_cu
*cu
,
10216 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10219 name
= dwarf2_name (die
, cu
);
10221 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10222 but otherwise compute it by typename_concat inside GDB.
10223 FIXME: Actually this is not really true, or at least not always true.
10224 It's all very confusing. compute_and_set_names doesn't try to demangle
10225 Fortran names because there is no mangling standard. So new_symbol
10226 will set the demangled name to the result of dwarf2_full_name, and it is
10227 the demangled name that GDB uses if it exists. */
10228 if (cu
->language
== language_ada
10229 || (cu
->language
== language_fortran
&& physname
))
10231 /* For Ada unit, we prefer the linkage name over the name, as
10232 the former contains the exported name, which the user expects
10233 to be able to reference. Ideally, we want the user to be able
10234 to reference this entity using either natural or linkage name,
10235 but we haven't started looking at this enhancement yet. */
10236 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10238 if (linkage_name
!= NULL
)
10239 return linkage_name
;
10242 /* These are the only languages we know how to qualify names in. */
10244 && (cu
->language
== language_cplus
10245 || cu
->language
== language_fortran
|| cu
->language
== language_d
10246 || cu
->language
== language_rust
))
10248 if (die_needs_namespace (die
, cu
))
10250 const char *prefix
;
10251 const char *canonical_name
= NULL
;
10255 prefix
= determine_prefix (die
, cu
);
10256 if (*prefix
!= '\0')
10258 gdb::unique_xmalloc_ptr
<char> prefixed_name
10259 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10261 buf
.puts (prefixed_name
.get ());
10266 /* Template parameters may be specified in the DIE's DW_AT_name, or
10267 as children with DW_TAG_template_type_param or
10268 DW_TAG_value_type_param. If the latter, add them to the name
10269 here. If the name already has template parameters, then
10270 skip this step; some versions of GCC emit both, and
10271 it is more efficient to use the pre-computed name.
10273 Something to keep in mind about this process: it is very
10274 unlikely, or in some cases downright impossible, to produce
10275 something that will match the mangled name of a function.
10276 If the definition of the function has the same debug info,
10277 we should be able to match up with it anyway. But fallbacks
10278 using the minimal symbol, for instance to find a method
10279 implemented in a stripped copy of libstdc++, will not work.
10280 If we do not have debug info for the definition, we will have to
10281 match them up some other way.
10283 When we do name matching there is a related problem with function
10284 templates; two instantiated function templates are allowed to
10285 differ only by their return types, which we do not add here. */
10287 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10289 struct attribute
*attr
;
10290 struct die_info
*child
;
10293 die
->building_fullname
= 1;
10295 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10299 const gdb_byte
*bytes
;
10300 struct dwarf2_locexpr_baton
*baton
;
10303 if (child
->tag
!= DW_TAG_template_type_param
10304 && child
->tag
!= DW_TAG_template_value_param
)
10315 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10318 complaint (_("template parameter missing DW_AT_type"));
10319 buf
.puts ("UNKNOWN_TYPE");
10322 type
= die_type (child
, cu
);
10324 if (child
->tag
== DW_TAG_template_type_param
)
10326 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10327 &type_print_raw_options
);
10331 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10334 complaint (_("template parameter missing "
10335 "DW_AT_const_value"));
10336 buf
.puts ("UNKNOWN_VALUE");
10340 dwarf2_const_value_attr (attr
, type
, name
,
10341 &cu
->comp_unit_obstack
, cu
,
10342 &value
, &bytes
, &baton
);
10344 if (TYPE_NOSIGN (type
))
10345 /* GDB prints characters as NUMBER 'CHAR'. If that's
10346 changed, this can use value_print instead. */
10347 c_printchar (value
, type
, &buf
);
10350 struct value_print_options opts
;
10353 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10357 baton
->per_objfile
);
10358 else if (bytes
!= NULL
)
10360 v
= allocate_value (type
);
10361 memcpy (value_contents_writeable (v
), bytes
,
10362 TYPE_LENGTH (type
));
10365 v
= value_from_longest (type
, value
);
10367 /* Specify decimal so that we do not depend on
10369 get_formatted_print_options (&opts
, 'd');
10371 value_print (v
, &buf
, &opts
);
10376 die
->building_fullname
= 0;
10380 /* Close the argument list, with a space if necessary
10381 (nested templates). */
10382 if (!buf
.empty () && buf
.string ().back () == '>')
10389 /* For C++ methods, append formal parameter type
10390 information, if PHYSNAME. */
10392 if (physname
&& die
->tag
== DW_TAG_subprogram
10393 && cu
->language
== language_cplus
)
10395 struct type
*type
= read_type_die (die
, cu
);
10397 c_type_print_args (type
, &buf
, 1, cu
->language
,
10398 &type_print_raw_options
);
10400 if (cu
->language
== language_cplus
)
10402 /* Assume that an artificial first parameter is
10403 "this", but do not crash if it is not. RealView
10404 marks unnamed (and thus unused) parameters as
10405 artificial; there is no way to differentiate
10407 if (type
->num_fields () > 0
10408 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10409 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10410 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10412 buf
.puts (" const");
10416 const std::string
&intermediate_name
= buf
.string ();
10418 if (cu
->language
== language_cplus
)
10420 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10423 /* If we only computed INTERMEDIATE_NAME, or if
10424 INTERMEDIATE_NAME is already canonical, then we need to
10426 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10427 name
= objfile
->intern (intermediate_name
);
10429 name
= canonical_name
;
10436 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10437 If scope qualifiers are appropriate they will be added. The result
10438 will be allocated on the storage_obstack, or NULL if the DIE does
10439 not have a name. NAME may either be from a previous call to
10440 dwarf2_name or NULL.
10442 The output string will be canonicalized (if C++). */
10444 static const char *
10445 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10447 return dwarf2_compute_name (name
, die
, cu
, 0);
10450 /* Construct a physname for the given DIE in CU. NAME may either be
10451 from a previous call to dwarf2_name or NULL. The result will be
10452 allocated on the objfile_objstack or NULL if the DIE does not have a
10455 The output string will be canonicalized (if C++). */
10457 static const char *
10458 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10460 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10461 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10464 /* In this case dwarf2_compute_name is just a shortcut not building anything
10466 if (!die_needs_namespace (die
, cu
))
10467 return dwarf2_compute_name (name
, die
, cu
, 1);
10469 if (cu
->language
!= language_rust
)
10470 mangled
= dw2_linkage_name (die
, cu
);
10472 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10474 gdb::unique_xmalloc_ptr
<char> demangled
;
10475 if (mangled
!= NULL
)
10478 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10480 /* Do nothing (do not demangle the symbol name). */
10482 else if (cu
->language
== language_go
)
10484 /* This is a lie, but we already lie to the caller new_symbol.
10485 new_symbol assumes we return the mangled name.
10486 This just undoes that lie until things are cleaned up. */
10490 /* Use DMGL_RET_DROP for C++ template functions to suppress
10491 their return type. It is easier for GDB users to search
10492 for such functions as `name(params)' than `long name(params)'.
10493 In such case the minimal symbol names do not match the full
10494 symbol names but for template functions there is never a need
10495 to look up their definition from their declaration so
10496 the only disadvantage remains the minimal symbol variant
10497 `long name(params)' does not have the proper inferior type. */
10498 demangled
.reset (gdb_demangle (mangled
,
10499 (DMGL_PARAMS
| DMGL_ANSI
10500 | DMGL_RET_DROP
)));
10503 canon
= demangled
.get ();
10511 if (canon
== NULL
|| check_physname
)
10513 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10515 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10517 /* It may not mean a bug in GDB. The compiler could also
10518 compute DW_AT_linkage_name incorrectly. But in such case
10519 GDB would need to be bug-to-bug compatible. */
10521 complaint (_("Computed physname <%s> does not match demangled <%s> "
10522 "(from linkage <%s>) - DIE at %s [in module %s]"),
10523 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10524 objfile_name (objfile
));
10526 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10527 is available here - over computed PHYSNAME. It is safer
10528 against both buggy GDB and buggy compilers. */
10542 retval
= objfile
->intern (retval
);
10547 /* Inspect DIE in CU for a namespace alias. If one exists, record
10548 a new symbol for it.
10550 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10553 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10555 struct attribute
*attr
;
10557 /* If the die does not have a name, this is not a namespace
10559 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10563 struct die_info
*d
= die
;
10564 struct dwarf2_cu
*imported_cu
= cu
;
10566 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10567 keep inspecting DIEs until we hit the underlying import. */
10568 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10569 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10571 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10575 d
= follow_die_ref (d
, attr
, &imported_cu
);
10576 if (d
->tag
!= DW_TAG_imported_declaration
)
10580 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10582 complaint (_("DIE at %s has too many recursively imported "
10583 "declarations"), sect_offset_str (d
->sect_off
));
10590 sect_offset sect_off
= attr
->get_ref_die_offset ();
10592 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10593 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10595 /* This declaration is a global namespace alias. Add
10596 a symbol for it whose type is the aliased namespace. */
10597 new_symbol (die
, type
, cu
);
10606 /* Return the using directives repository (global or local?) to use in the
10607 current context for CU.
10609 For Ada, imported declarations can materialize renamings, which *may* be
10610 global. However it is impossible (for now?) in DWARF to distinguish
10611 "external" imported declarations and "static" ones. As all imported
10612 declarations seem to be static in all other languages, make them all CU-wide
10613 global only in Ada. */
10615 static struct using_direct
**
10616 using_directives (struct dwarf2_cu
*cu
)
10618 if (cu
->language
== language_ada
10619 && cu
->get_builder ()->outermost_context_p ())
10620 return cu
->get_builder ()->get_global_using_directives ();
10622 return cu
->get_builder ()->get_local_using_directives ();
10625 /* Read the import statement specified by the given die and record it. */
10628 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10630 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10631 struct attribute
*import_attr
;
10632 struct die_info
*imported_die
, *child_die
;
10633 struct dwarf2_cu
*imported_cu
;
10634 const char *imported_name
;
10635 const char *imported_name_prefix
;
10636 const char *canonical_name
;
10637 const char *import_alias
;
10638 const char *imported_declaration
= NULL
;
10639 const char *import_prefix
;
10640 std::vector
<const char *> excludes
;
10642 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10643 if (import_attr
== NULL
)
10645 complaint (_("Tag '%s' has no DW_AT_import"),
10646 dwarf_tag_name (die
->tag
));
10651 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10652 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10653 if (imported_name
== NULL
)
10655 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10657 The import in the following code:
10671 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10672 <52> DW_AT_decl_file : 1
10673 <53> DW_AT_decl_line : 6
10674 <54> DW_AT_import : <0x75>
10675 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10676 <59> DW_AT_name : B
10677 <5b> DW_AT_decl_file : 1
10678 <5c> DW_AT_decl_line : 2
10679 <5d> DW_AT_type : <0x6e>
10681 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10682 <76> DW_AT_byte_size : 4
10683 <77> DW_AT_encoding : 5 (signed)
10685 imports the wrong die ( 0x75 instead of 0x58 ).
10686 This case will be ignored until the gcc bug is fixed. */
10690 /* Figure out the local name after import. */
10691 import_alias
= dwarf2_name (die
, cu
);
10693 /* Figure out where the statement is being imported to. */
10694 import_prefix
= determine_prefix (die
, cu
);
10696 /* Figure out what the scope of the imported die is and prepend it
10697 to the name of the imported die. */
10698 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10700 if (imported_die
->tag
!= DW_TAG_namespace
10701 && imported_die
->tag
!= DW_TAG_module
)
10703 imported_declaration
= imported_name
;
10704 canonical_name
= imported_name_prefix
;
10706 else if (strlen (imported_name_prefix
) > 0)
10707 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10708 imported_name_prefix
,
10709 (cu
->language
== language_d
? "." : "::"),
10710 imported_name
, (char *) NULL
);
10712 canonical_name
= imported_name
;
10714 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10715 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10716 child_die
= child_die
->sibling
)
10718 /* DWARF-4: A Fortran use statement with a “rename list” may be
10719 represented by an imported module entry with an import attribute
10720 referring to the module and owned entries corresponding to those
10721 entities that are renamed as part of being imported. */
10723 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10725 complaint (_("child DW_TAG_imported_declaration expected "
10726 "- DIE at %s [in module %s]"),
10727 sect_offset_str (child_die
->sect_off
),
10728 objfile_name (objfile
));
10732 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10733 if (import_attr
== NULL
)
10735 complaint (_("Tag '%s' has no DW_AT_import"),
10736 dwarf_tag_name (child_die
->tag
));
10741 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10743 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10744 if (imported_name
== NULL
)
10746 complaint (_("child DW_TAG_imported_declaration has unknown "
10747 "imported name - DIE at %s [in module %s]"),
10748 sect_offset_str (child_die
->sect_off
),
10749 objfile_name (objfile
));
10753 excludes
.push_back (imported_name
);
10755 process_die (child_die
, cu
);
10758 add_using_directive (using_directives (cu
),
10762 imported_declaration
,
10765 &objfile
->objfile_obstack
);
10768 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10769 types, but gives them a size of zero. Starting with version 14,
10770 ICC is compatible with GCC. */
10773 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10775 if (!cu
->checked_producer
)
10776 check_producer (cu
);
10778 return cu
->producer_is_icc_lt_14
;
10781 /* ICC generates a DW_AT_type for C void functions. This was observed on
10782 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10783 which says that void functions should not have a DW_AT_type. */
10786 producer_is_icc (struct dwarf2_cu
*cu
)
10788 if (!cu
->checked_producer
)
10789 check_producer (cu
);
10791 return cu
->producer_is_icc
;
10794 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10795 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10796 this, it was first present in GCC release 4.3.0. */
10799 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10801 if (!cu
->checked_producer
)
10802 check_producer (cu
);
10804 return cu
->producer_is_gcc_lt_4_3
;
10807 static file_and_directory
10808 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10810 file_and_directory res
;
10812 /* Find the filename. Do not use dwarf2_name here, since the filename
10813 is not a source language identifier. */
10814 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10815 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10817 if (res
.comp_dir
== NULL
10818 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10819 && IS_ABSOLUTE_PATH (res
.name
))
10821 res
.comp_dir_storage
= ldirname (res
.name
);
10822 if (!res
.comp_dir_storage
.empty ())
10823 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10825 if (res
.comp_dir
!= NULL
)
10827 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10828 directory, get rid of it. */
10829 const char *cp
= strchr (res
.comp_dir
, ':');
10831 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10832 res
.comp_dir
= cp
+ 1;
10835 if (res
.name
== NULL
)
10836 res
.name
= "<unknown>";
10841 /* Handle DW_AT_stmt_list for a compilation unit.
10842 DIE is the DW_TAG_compile_unit die for CU.
10843 COMP_DIR is the compilation directory. LOWPC is passed to
10844 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10847 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10848 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10850 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10851 struct attribute
*attr
;
10852 struct line_header line_header_local
;
10853 hashval_t line_header_local_hash
;
10855 int decode_mapping
;
10857 gdb_assert (! cu
->per_cu
->is_debug_types
);
10859 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10863 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10865 /* The line header hash table is only created if needed (it exists to
10866 prevent redundant reading of the line table for partial_units).
10867 If we're given a partial_unit, we'll need it. If we're given a
10868 compile_unit, then use the line header hash table if it's already
10869 created, but don't create one just yet. */
10871 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
10872 && die
->tag
== DW_TAG_partial_unit
)
10874 dwarf2_per_objfile
->per_bfd
->line_header_hash
10875 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10876 line_header_eq_voidp
,
10877 free_line_header_voidp
,
10881 line_header_local
.sect_off
= line_offset
;
10882 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10883 line_header_local_hash
= line_header_hash (&line_header_local
);
10884 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
!= NULL
)
10886 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10887 &line_header_local
,
10888 line_header_local_hash
, NO_INSERT
);
10890 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10891 is not present in *SLOT (since if there is something in *SLOT then
10892 it will be for a partial_unit). */
10893 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10895 gdb_assert (*slot
!= NULL
);
10896 cu
->line_header
= (struct line_header
*) *slot
;
10901 /* dwarf_decode_line_header does not yet provide sufficient information.
10902 We always have to call also dwarf_decode_lines for it. */
10903 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10907 cu
->line_header
= lh
.release ();
10908 cu
->line_header_die_owner
= die
;
10910 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
)
10914 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10915 &line_header_local
,
10916 line_header_local_hash
, INSERT
);
10917 gdb_assert (slot
!= NULL
);
10919 if (slot
!= NULL
&& *slot
== NULL
)
10921 /* This newly decoded line number information unit will be owned
10922 by line_header_hash hash table. */
10923 *slot
= cu
->line_header
;
10924 cu
->line_header_die_owner
= NULL
;
10928 /* We cannot free any current entry in (*slot) as that struct line_header
10929 may be already used by multiple CUs. Create only temporary decoded
10930 line_header for this CU - it may happen at most once for each line
10931 number information unit. And if we're not using line_header_hash
10932 then this is what we want as well. */
10933 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10935 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10936 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10941 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10944 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10946 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10947 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10948 struct gdbarch
*gdbarch
= objfile
->arch ();
10949 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10950 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10951 struct attribute
*attr
;
10952 struct die_info
*child_die
;
10953 CORE_ADDR baseaddr
;
10955 prepare_one_comp_unit (cu
, die
, cu
->language
);
10956 baseaddr
= objfile
->text_section_offset ();
10958 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10960 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10961 from finish_block. */
10962 if (lowpc
== ((CORE_ADDR
) -1))
10964 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10966 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10968 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10969 standardised yet. As a workaround for the language detection we fall
10970 back to the DW_AT_producer string. */
10971 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10972 cu
->language
= language_opencl
;
10974 /* Similar hack for Go. */
10975 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10976 set_cu_language (DW_LANG_Go
, cu
);
10978 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10980 /* Decode line number information if present. We do this before
10981 processing child DIEs, so that the line header table is available
10982 for DW_AT_decl_file. */
10983 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10985 /* Process all dies in compilation unit. */
10986 if (die
->child
!= NULL
)
10988 child_die
= die
->child
;
10989 while (child_die
&& child_die
->tag
)
10991 process_die (child_die
, cu
);
10992 child_die
= child_die
->sibling
;
10996 /* Decode macro information, if present. Dwarf 2 macro information
10997 refers to information in the line number info statement program
10998 header, so we can only read it if we've read the header
11000 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11002 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11003 if (attr
&& cu
->line_header
)
11005 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11006 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11008 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11012 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11013 if (attr
&& cu
->line_header
)
11015 unsigned int macro_offset
= DW_UNSND (attr
);
11017 dwarf_decode_macros (cu
, macro_offset
, 0);
11023 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11025 struct type_unit_group
*tu_group
;
11027 struct attribute
*attr
;
11029 struct signatured_type
*sig_type
;
11031 gdb_assert (per_cu
->is_debug_types
);
11032 sig_type
= (struct signatured_type
*) per_cu
;
11034 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11036 /* If we're using .gdb_index (includes -readnow) then
11037 per_cu->type_unit_group may not have been set up yet. */
11038 if (sig_type
->type_unit_group
== NULL
)
11039 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11040 tu_group
= sig_type
->type_unit_group
;
11042 /* If we've already processed this stmt_list there's no real need to
11043 do it again, we could fake it and just recreate the part we need
11044 (file name,index -> symtab mapping). If data shows this optimization
11045 is useful we can do it then. */
11046 type_unit_group_unshareable
*tug_unshare
11047 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11048 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11050 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11055 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11056 lh
= dwarf_decode_line_header (line_offset
, this);
11061 start_symtab ("", NULL
, 0);
11064 gdb_assert (tug_unshare
->symtabs
== NULL
);
11065 gdb_assert (m_builder
== nullptr);
11066 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11067 m_builder
.reset (new struct buildsym_compunit
11068 (COMPUNIT_OBJFILE (cust
), "",
11069 COMPUNIT_DIRNAME (cust
),
11070 compunit_language (cust
),
11072 list_in_scope
= get_builder ()->get_file_symbols ();
11077 line_header
= lh
.release ();
11078 line_header_die_owner
= die
;
11082 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11084 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11085 still initializing it, and our caller (a few levels up)
11086 process_full_type_unit still needs to know if this is the first
11089 tug_unshare
->symtabs
11090 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11091 struct symtab
*, line_header
->file_names_size ());
11093 auto &file_names
= line_header
->file_names ();
11094 for (i
= 0; i
< file_names
.size (); ++i
)
11096 file_entry
&fe
= file_names
[i
];
11097 dwarf2_start_subfile (this, fe
.name
,
11098 fe
.include_dir (line_header
));
11099 buildsym_compunit
*b
= get_builder ();
11100 if (b
->get_current_subfile ()->symtab
== NULL
)
11102 /* NOTE: start_subfile will recognize when it's been
11103 passed a file it has already seen. So we can't
11104 assume there's a simple mapping from
11105 cu->line_header->file_names to subfiles, plus
11106 cu->line_header->file_names may contain dups. */
11107 b
->get_current_subfile ()->symtab
11108 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11111 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11112 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11117 gdb_assert (m_builder
== nullptr);
11118 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11119 m_builder
.reset (new struct buildsym_compunit
11120 (COMPUNIT_OBJFILE (cust
), "",
11121 COMPUNIT_DIRNAME (cust
),
11122 compunit_language (cust
),
11124 list_in_scope
= get_builder ()->get_file_symbols ();
11126 auto &file_names
= line_header
->file_names ();
11127 for (i
= 0; i
< file_names
.size (); ++i
)
11129 file_entry
&fe
= file_names
[i
];
11130 fe
.symtab
= tug_unshare
->symtabs
[i
];
11134 /* The main symtab is allocated last. Type units don't have DW_AT_name
11135 so they don't have a "real" (so to speak) symtab anyway.
11136 There is later code that will assign the main symtab to all symbols
11137 that don't have one. We need to handle the case of a symbol with a
11138 missing symtab (DW_AT_decl_file) anyway. */
11141 /* Process DW_TAG_type_unit.
11142 For TUs we want to skip the first top level sibling if it's not the
11143 actual type being defined by this TU. In this case the first top
11144 level sibling is there to provide context only. */
11147 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11149 struct die_info
*child_die
;
11151 prepare_one_comp_unit (cu
, die
, language_minimal
);
11153 /* Initialize (or reinitialize) the machinery for building symtabs.
11154 We do this before processing child DIEs, so that the line header table
11155 is available for DW_AT_decl_file. */
11156 cu
->setup_type_unit_groups (die
);
11158 if (die
->child
!= NULL
)
11160 child_die
= die
->child
;
11161 while (child_die
&& child_die
->tag
)
11163 process_die (child_die
, cu
);
11164 child_die
= child_die
->sibling
;
11171 http://gcc.gnu.org/wiki/DebugFission
11172 http://gcc.gnu.org/wiki/DebugFissionDWP
11174 To simplify handling of both DWO files ("object" files with the DWARF info)
11175 and DWP files (a file with the DWOs packaged up into one file), we treat
11176 DWP files as having a collection of virtual DWO files. */
11179 hash_dwo_file (const void *item
)
11181 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11184 hash
= htab_hash_string (dwo_file
->dwo_name
);
11185 if (dwo_file
->comp_dir
!= NULL
)
11186 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11191 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11193 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11194 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11196 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11198 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11199 return lhs
->comp_dir
== rhs
->comp_dir
;
11200 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11203 /* Allocate a hash table for DWO files. */
11206 allocate_dwo_file_hash_table ()
11208 auto delete_dwo_file
= [] (void *item
)
11210 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11215 return htab_up (htab_create_alloc (41,
11222 /* Lookup DWO file DWO_NAME. */
11225 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11226 const char *dwo_name
,
11227 const char *comp_dir
)
11229 struct dwo_file find_entry
;
11232 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11233 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11235 find_entry
.dwo_name
= dwo_name
;
11236 find_entry
.comp_dir
= comp_dir
;
11237 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11244 hash_dwo_unit (const void *item
)
11246 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11248 /* This drops the top 32 bits of the id, but is ok for a hash. */
11249 return dwo_unit
->signature
;
11253 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11255 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11256 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11258 /* The signature is assumed to be unique within the DWO file.
11259 So while object file CU dwo_id's always have the value zero,
11260 that's OK, assuming each object file DWO file has only one CU,
11261 and that's the rule for now. */
11262 return lhs
->signature
== rhs
->signature
;
11265 /* Allocate a hash table for DWO CUs,TUs.
11266 There is one of these tables for each of CUs,TUs for each DWO file. */
11269 allocate_dwo_unit_table ()
11271 /* Start out with a pretty small number.
11272 Generally DWO files contain only one CU and maybe some TUs. */
11273 return htab_up (htab_create_alloc (3,
11276 NULL
, xcalloc
, xfree
));
11279 /* die_reader_func for create_dwo_cu. */
11282 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11283 const gdb_byte
*info_ptr
,
11284 struct die_info
*comp_unit_die
,
11285 struct dwo_file
*dwo_file
,
11286 struct dwo_unit
*dwo_unit
)
11288 struct dwarf2_cu
*cu
= reader
->cu
;
11289 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11290 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11292 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11293 if (!signature
.has_value ())
11295 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11296 " its dwo_id [in module %s]"),
11297 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11301 dwo_unit
->dwo_file
= dwo_file
;
11302 dwo_unit
->signature
= *signature
;
11303 dwo_unit
->section
= section
;
11304 dwo_unit
->sect_off
= sect_off
;
11305 dwo_unit
->length
= cu
->per_cu
->length
;
11307 if (dwarf_read_debug
)
11308 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11309 sect_offset_str (sect_off
),
11310 hex_string (dwo_unit
->signature
));
11313 /* Create the dwo_units for the CUs in a DWO_FILE.
11314 Note: This function processes DWO files only, not DWP files. */
11317 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11318 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11319 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11321 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11322 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
11323 const gdb_byte
*info_ptr
, *end_ptr
;
11325 section
.read (objfile
);
11326 info_ptr
= section
.buffer
;
11328 if (info_ptr
== NULL
)
11331 if (dwarf_read_debug
)
11333 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11334 section
.get_name (),
11335 section
.get_file_name ());
11338 end_ptr
= info_ptr
+ section
.size
;
11339 while (info_ptr
< end_ptr
)
11341 struct dwarf2_per_cu_data per_cu
;
11342 struct dwo_unit read_unit
{};
11343 struct dwo_unit
*dwo_unit
;
11345 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11347 memset (&per_cu
, 0, sizeof (per_cu
));
11348 per_cu
.per_bfd
= per_bfd
;
11349 per_cu
.is_debug_types
= 0;
11350 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11351 per_cu
.section
= §ion
;
11353 cutu_reader
reader (&per_cu
, dwarf2_per_objfile
, cu
, &dwo_file
);
11354 if (!reader
.dummy_p
)
11355 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11356 &dwo_file
, &read_unit
);
11357 info_ptr
+= per_cu
.length
;
11359 // If the unit could not be parsed, skip it.
11360 if (read_unit
.dwo_file
== NULL
)
11363 if (cus_htab
== NULL
)
11364 cus_htab
= allocate_dwo_unit_table ();
11366 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11368 *dwo_unit
= read_unit
;
11369 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11370 gdb_assert (slot
!= NULL
);
11373 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11374 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11376 complaint (_("debug cu entry at offset %s is duplicate to"
11377 " the entry at offset %s, signature %s"),
11378 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11379 hex_string (dwo_unit
->signature
));
11381 *slot
= (void *)dwo_unit
;
11385 /* DWP file .debug_{cu,tu}_index section format:
11386 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11390 Both index sections have the same format, and serve to map a 64-bit
11391 signature to a set of section numbers. Each section begins with a header,
11392 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11393 indexes, and a pool of 32-bit section numbers. The index sections will be
11394 aligned at 8-byte boundaries in the file.
11396 The index section header consists of:
11398 V, 32 bit version number
11400 N, 32 bit number of compilation units or type units in the index
11401 M, 32 bit number of slots in the hash table
11403 Numbers are recorded using the byte order of the application binary.
11405 The hash table begins at offset 16 in the section, and consists of an array
11406 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11407 order of the application binary). Unused slots in the hash table are 0.
11408 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11410 The parallel table begins immediately after the hash table
11411 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11412 array of 32-bit indexes (using the byte order of the application binary),
11413 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11414 table contains a 32-bit index into the pool of section numbers. For unused
11415 hash table slots, the corresponding entry in the parallel table will be 0.
11417 The pool of section numbers begins immediately following the hash table
11418 (at offset 16 + 12 * M from the beginning of the section). The pool of
11419 section numbers consists of an array of 32-bit words (using the byte order
11420 of the application binary). Each item in the array is indexed starting
11421 from 0. The hash table entry provides the index of the first section
11422 number in the set. Additional section numbers in the set follow, and the
11423 set is terminated by a 0 entry (section number 0 is not used in ELF).
11425 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11426 section must be the first entry in the set, and the .debug_abbrev.dwo must
11427 be the second entry. Other members of the set may follow in any order.
11433 DWP Version 2 combines all the .debug_info, etc. sections into one,
11434 and the entries in the index tables are now offsets into these sections.
11435 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11438 Index Section Contents:
11440 Hash Table of Signatures dwp_hash_table.hash_table
11441 Parallel Table of Indices dwp_hash_table.unit_table
11442 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11443 Table of Section Sizes dwp_hash_table.v2.sizes
11445 The index section header consists of:
11447 V, 32 bit version number
11448 L, 32 bit number of columns in the table of section offsets
11449 N, 32 bit number of compilation units or type units in the index
11450 M, 32 bit number of slots in the hash table
11452 Numbers are recorded using the byte order of the application binary.
11454 The hash table has the same format as version 1.
11455 The parallel table of indices has the same format as version 1,
11456 except that the entries are origin-1 indices into the table of sections
11457 offsets and the table of section sizes.
11459 The table of offsets begins immediately following the parallel table
11460 (at offset 16 + 12 * M from the beginning of the section). The table is
11461 a two-dimensional array of 32-bit words (using the byte order of the
11462 application binary), with L columns and N+1 rows, in row-major order.
11463 Each row in the array is indexed starting from 0. The first row provides
11464 a key to the remaining rows: each column in this row provides an identifier
11465 for a debug section, and the offsets in the same column of subsequent rows
11466 refer to that section. The section identifiers are:
11468 DW_SECT_INFO 1 .debug_info.dwo
11469 DW_SECT_TYPES 2 .debug_types.dwo
11470 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11471 DW_SECT_LINE 4 .debug_line.dwo
11472 DW_SECT_LOC 5 .debug_loc.dwo
11473 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11474 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11475 DW_SECT_MACRO 8 .debug_macro.dwo
11477 The offsets provided by the CU and TU index sections are the base offsets
11478 for the contributions made by each CU or TU to the corresponding section
11479 in the package file. Each CU and TU header contains an abbrev_offset
11480 field, used to find the abbreviations table for that CU or TU within the
11481 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11482 be interpreted as relative to the base offset given in the index section.
11483 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11484 should be interpreted as relative to the base offset for .debug_line.dwo,
11485 and offsets into other debug sections obtained from DWARF attributes should
11486 also be interpreted as relative to the corresponding base offset.
11488 The table of sizes begins immediately following the table of offsets.
11489 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11490 with L columns and N rows, in row-major order. Each row in the array is
11491 indexed starting from 1 (row 0 is shared by the two tables).
11495 Hash table lookup is handled the same in version 1 and 2:
11497 We assume that N and M will not exceed 2^32 - 1.
11498 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11500 Given a 64-bit compilation unit signature or a type signature S, an entry
11501 in the hash table is located as follows:
11503 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11504 the low-order k bits all set to 1.
11506 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11508 3) If the hash table entry at index H matches the signature, use that
11509 entry. If the hash table entry at index H is unused (all zeroes),
11510 terminate the search: the signature is not present in the table.
11512 4) Let H = (H + H') modulo M. Repeat at Step 3.
11514 Because M > N and H' and M are relatively prime, the search is guaranteed
11515 to stop at an unused slot or find the match. */
11517 /* Create a hash table to map DWO IDs to their CU/TU entry in
11518 .debug_{info,types}.dwo in DWP_FILE.
11519 Returns NULL if there isn't one.
11520 Note: This function processes DWP files only, not DWO files. */
11522 static struct dwp_hash_table
*
11523 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11524 struct dwp_file
*dwp_file
, int is_debug_types
)
11526 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11527 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11528 const gdb_byte
*index_ptr
, *index_end
;
11529 struct dwarf2_section_info
*index
;
11530 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11531 struct dwp_hash_table
*htab
;
11533 if (is_debug_types
)
11534 index
= &dwp_file
->sections
.tu_index
;
11536 index
= &dwp_file
->sections
.cu_index
;
11538 if (index
->empty ())
11540 index
->read (objfile
);
11542 index_ptr
= index
->buffer
;
11543 index_end
= index_ptr
+ index
->size
;
11545 version
= read_4_bytes (dbfd
, index_ptr
);
11548 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11552 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11554 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11557 if (version
!= 1 && version
!= 2)
11559 error (_("Dwarf Error: unsupported DWP file version (%s)"
11560 " [in module %s]"),
11561 pulongest (version
), dwp_file
->name
);
11563 if (nr_slots
!= (nr_slots
& -nr_slots
))
11565 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11566 " is not power of 2 [in module %s]"),
11567 pulongest (nr_slots
), dwp_file
->name
);
11570 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11571 htab
->version
= version
;
11572 htab
->nr_columns
= nr_columns
;
11573 htab
->nr_units
= nr_units
;
11574 htab
->nr_slots
= nr_slots
;
11575 htab
->hash_table
= index_ptr
;
11576 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11578 /* Exit early if the table is empty. */
11579 if (nr_slots
== 0 || nr_units
== 0
11580 || (version
== 2 && nr_columns
== 0))
11582 /* All must be zero. */
11583 if (nr_slots
!= 0 || nr_units
!= 0
11584 || (version
== 2 && nr_columns
!= 0))
11586 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11587 " all zero [in modules %s]"),
11595 htab
->section_pool
.v1
.indices
=
11596 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11597 /* It's harder to decide whether the section is too small in v1.
11598 V1 is deprecated anyway so we punt. */
11602 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11603 int *ids
= htab
->section_pool
.v2
.section_ids
;
11604 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11605 /* Reverse map for error checking. */
11606 int ids_seen
[DW_SECT_MAX
+ 1];
11609 if (nr_columns
< 2)
11611 error (_("Dwarf Error: bad DWP hash table, too few columns"
11612 " in section table [in module %s]"),
11615 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11617 error (_("Dwarf Error: bad DWP hash table, too many columns"
11618 " in section table [in module %s]"),
11621 memset (ids
, 255, sizeof_ids
);
11622 memset (ids_seen
, 255, sizeof (ids_seen
));
11623 for (i
= 0; i
< nr_columns
; ++i
)
11625 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11627 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11629 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11630 " in section table [in module %s]"),
11631 id
, dwp_file
->name
);
11633 if (ids_seen
[id
] != -1)
11635 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11636 " id %d in section table [in module %s]"),
11637 id
, dwp_file
->name
);
11642 /* Must have exactly one info or types section. */
11643 if (((ids_seen
[DW_SECT_INFO
] != -1)
11644 + (ids_seen
[DW_SECT_TYPES
] != -1))
11647 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11648 " DWO info/types section [in module %s]"),
11651 /* Must have an abbrev section. */
11652 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11654 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11655 " section [in module %s]"),
11658 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11659 htab
->section_pool
.v2
.sizes
=
11660 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11661 * nr_units
* nr_columns
);
11662 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11663 * nr_units
* nr_columns
))
11666 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11667 " [in module %s]"),
11675 /* Update SECTIONS with the data from SECTP.
11677 This function is like the other "locate" section routines that are
11678 passed to bfd_map_over_sections, but in this context the sections to
11679 read comes from the DWP V1 hash table, not the full ELF section table.
11681 The result is non-zero for success, or zero if an error was found. */
11684 locate_v1_virtual_dwo_sections (asection
*sectp
,
11685 struct virtual_v1_dwo_sections
*sections
)
11687 const struct dwop_section_names
*names
= &dwop_section_names
;
11689 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11691 /* There can be only one. */
11692 if (sections
->abbrev
.s
.section
!= NULL
)
11694 sections
->abbrev
.s
.section
= sectp
;
11695 sections
->abbrev
.size
= bfd_section_size (sectp
);
11697 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11698 || section_is_p (sectp
->name
, &names
->types_dwo
))
11700 /* There can be only one. */
11701 if (sections
->info_or_types
.s
.section
!= NULL
)
11703 sections
->info_or_types
.s
.section
= sectp
;
11704 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11706 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11708 /* There can be only one. */
11709 if (sections
->line
.s
.section
!= NULL
)
11711 sections
->line
.s
.section
= sectp
;
11712 sections
->line
.size
= bfd_section_size (sectp
);
11714 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11716 /* There can be only one. */
11717 if (sections
->loc
.s
.section
!= NULL
)
11719 sections
->loc
.s
.section
= sectp
;
11720 sections
->loc
.size
= bfd_section_size (sectp
);
11722 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11724 /* There can be only one. */
11725 if (sections
->macinfo
.s
.section
!= NULL
)
11727 sections
->macinfo
.s
.section
= sectp
;
11728 sections
->macinfo
.size
= bfd_section_size (sectp
);
11730 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11732 /* There can be only one. */
11733 if (sections
->macro
.s
.section
!= NULL
)
11735 sections
->macro
.s
.section
= sectp
;
11736 sections
->macro
.size
= bfd_section_size (sectp
);
11738 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11740 /* There can be only one. */
11741 if (sections
->str_offsets
.s
.section
!= NULL
)
11743 sections
->str_offsets
.s
.section
= sectp
;
11744 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11748 /* No other kind of section is valid. */
11755 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11756 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11757 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11758 This is for DWP version 1 files. */
11760 static struct dwo_unit
*
11761 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11762 struct dwp_file
*dwp_file
,
11763 uint32_t unit_index
,
11764 const char *comp_dir
,
11765 ULONGEST signature
, int is_debug_types
)
11767 const struct dwp_hash_table
*dwp_htab
=
11768 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11769 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11770 const char *kind
= is_debug_types
? "TU" : "CU";
11771 struct dwo_file
*dwo_file
;
11772 struct dwo_unit
*dwo_unit
;
11773 struct virtual_v1_dwo_sections sections
;
11774 void **dwo_file_slot
;
11777 gdb_assert (dwp_file
->version
== 1);
11779 if (dwarf_read_debug
)
11781 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11783 pulongest (unit_index
), hex_string (signature
),
11787 /* Fetch the sections of this DWO unit.
11788 Put a limit on the number of sections we look for so that bad data
11789 doesn't cause us to loop forever. */
11791 #define MAX_NR_V1_DWO_SECTIONS \
11792 (1 /* .debug_info or .debug_types */ \
11793 + 1 /* .debug_abbrev */ \
11794 + 1 /* .debug_line */ \
11795 + 1 /* .debug_loc */ \
11796 + 1 /* .debug_str_offsets */ \
11797 + 1 /* .debug_macro or .debug_macinfo */ \
11798 + 1 /* trailing zero */)
11800 memset (§ions
, 0, sizeof (sections
));
11802 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11805 uint32_t section_nr
=
11806 read_4_bytes (dbfd
,
11807 dwp_htab
->section_pool
.v1
.indices
11808 + (unit_index
+ i
) * sizeof (uint32_t));
11810 if (section_nr
== 0)
11812 if (section_nr
>= dwp_file
->num_sections
)
11814 error (_("Dwarf Error: bad DWP hash table, section number too large"
11815 " [in module %s]"),
11819 sectp
= dwp_file
->elf_sections
[section_nr
];
11820 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11822 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11823 " [in module %s]"),
11829 || sections
.info_or_types
.empty ()
11830 || sections
.abbrev
.empty ())
11832 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11833 " [in module %s]"),
11836 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11838 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11839 " [in module %s]"),
11843 /* It's easier for the rest of the code if we fake a struct dwo_file and
11844 have dwo_unit "live" in that. At least for now.
11846 The DWP file can be made up of a random collection of CUs and TUs.
11847 However, for each CU + set of TUs that came from the same original DWO
11848 file, we can combine them back into a virtual DWO file to save space
11849 (fewer struct dwo_file objects to allocate). Remember that for really
11850 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11852 std::string virtual_dwo_name
=
11853 string_printf ("virtual-dwo/%d-%d-%d-%d",
11854 sections
.abbrev
.get_id (),
11855 sections
.line
.get_id (),
11856 sections
.loc
.get_id (),
11857 sections
.str_offsets
.get_id ());
11858 /* Can we use an existing virtual DWO file? */
11859 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11860 virtual_dwo_name
.c_str (),
11862 /* Create one if necessary. */
11863 if (*dwo_file_slot
== NULL
)
11865 if (dwarf_read_debug
)
11867 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11868 virtual_dwo_name
.c_str ());
11870 dwo_file
= new struct dwo_file
;
11871 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11872 dwo_file
->comp_dir
= comp_dir
;
11873 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11874 dwo_file
->sections
.line
= sections
.line
;
11875 dwo_file
->sections
.loc
= sections
.loc
;
11876 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11877 dwo_file
->sections
.macro
= sections
.macro
;
11878 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11879 /* The "str" section is global to the entire DWP file. */
11880 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11881 /* The info or types section is assigned below to dwo_unit,
11882 there's no need to record it in dwo_file.
11883 Also, we can't simply record type sections in dwo_file because
11884 we record a pointer into the vector in dwo_unit. As we collect more
11885 types we'll grow the vector and eventually have to reallocate space
11886 for it, invalidating all copies of pointers into the previous
11888 *dwo_file_slot
= dwo_file
;
11892 if (dwarf_read_debug
)
11894 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11895 virtual_dwo_name
.c_str ());
11897 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11900 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11901 dwo_unit
->dwo_file
= dwo_file
;
11902 dwo_unit
->signature
= signature
;
11903 dwo_unit
->section
=
11904 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11905 *dwo_unit
->section
= sections
.info_or_types
;
11906 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11911 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11912 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11913 piece within that section used by a TU/CU, return a virtual section
11914 of just that piece. */
11916 static struct dwarf2_section_info
11917 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11918 struct dwarf2_section_info
*section
,
11919 bfd_size_type offset
, bfd_size_type size
)
11921 struct dwarf2_section_info result
;
11924 gdb_assert (section
!= NULL
);
11925 gdb_assert (!section
->is_virtual
);
11927 memset (&result
, 0, sizeof (result
));
11928 result
.s
.containing_section
= section
;
11929 result
.is_virtual
= true;
11934 sectp
= section
->get_bfd_section ();
11936 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11937 bounds of the real section. This is a pretty-rare event, so just
11938 flag an error (easier) instead of a warning and trying to cope. */
11940 || offset
+ size
> bfd_section_size (sectp
))
11942 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11943 " in section %s [in module %s]"),
11944 sectp
? bfd_section_name (sectp
) : "<unknown>",
11945 objfile_name (dwarf2_per_objfile
->objfile
));
11948 result
.virtual_offset
= offset
;
11949 result
.size
= size
;
11953 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11954 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11955 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11956 This is for DWP version 2 files. */
11958 static struct dwo_unit
*
11959 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11960 struct dwp_file
*dwp_file
,
11961 uint32_t unit_index
,
11962 const char *comp_dir
,
11963 ULONGEST signature
, int is_debug_types
)
11965 const struct dwp_hash_table
*dwp_htab
=
11966 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11967 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11968 const char *kind
= is_debug_types
? "TU" : "CU";
11969 struct dwo_file
*dwo_file
;
11970 struct dwo_unit
*dwo_unit
;
11971 struct virtual_v2_dwo_sections sections
;
11972 void **dwo_file_slot
;
11975 gdb_assert (dwp_file
->version
== 2);
11977 if (dwarf_read_debug
)
11979 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11981 pulongest (unit_index
), hex_string (signature
),
11985 /* Fetch the section offsets of this DWO unit. */
11987 memset (§ions
, 0, sizeof (sections
));
11989 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11991 uint32_t offset
= read_4_bytes (dbfd
,
11992 dwp_htab
->section_pool
.v2
.offsets
11993 + (((unit_index
- 1) * dwp_htab
->nr_columns
11995 * sizeof (uint32_t)));
11996 uint32_t size
= read_4_bytes (dbfd
,
11997 dwp_htab
->section_pool
.v2
.sizes
11998 + (((unit_index
- 1) * dwp_htab
->nr_columns
12000 * sizeof (uint32_t)));
12002 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12005 case DW_SECT_TYPES
:
12006 sections
.info_or_types_offset
= offset
;
12007 sections
.info_or_types_size
= size
;
12009 case DW_SECT_ABBREV
:
12010 sections
.abbrev_offset
= offset
;
12011 sections
.abbrev_size
= size
;
12014 sections
.line_offset
= offset
;
12015 sections
.line_size
= size
;
12018 sections
.loc_offset
= offset
;
12019 sections
.loc_size
= size
;
12021 case DW_SECT_STR_OFFSETS
:
12022 sections
.str_offsets_offset
= offset
;
12023 sections
.str_offsets_size
= size
;
12025 case DW_SECT_MACINFO
:
12026 sections
.macinfo_offset
= offset
;
12027 sections
.macinfo_size
= size
;
12029 case DW_SECT_MACRO
:
12030 sections
.macro_offset
= offset
;
12031 sections
.macro_size
= size
;
12036 /* It's easier for the rest of the code if we fake a struct dwo_file and
12037 have dwo_unit "live" in that. At least for now.
12039 The DWP file can be made up of a random collection of CUs and TUs.
12040 However, for each CU + set of TUs that came from the same original DWO
12041 file, we can combine them back into a virtual DWO file to save space
12042 (fewer struct dwo_file objects to allocate). Remember that for really
12043 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12045 std::string virtual_dwo_name
=
12046 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12047 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12048 (long) (sections
.line_size
? sections
.line_offset
: 0),
12049 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12050 (long) (sections
.str_offsets_size
12051 ? sections
.str_offsets_offset
: 0));
12052 /* Can we use an existing virtual DWO file? */
12053 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12054 virtual_dwo_name
.c_str (),
12056 /* Create one if necessary. */
12057 if (*dwo_file_slot
== NULL
)
12059 if (dwarf_read_debug
)
12061 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12062 virtual_dwo_name
.c_str ());
12064 dwo_file
= new struct dwo_file
;
12065 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12066 dwo_file
->comp_dir
= comp_dir
;
12067 dwo_file
->sections
.abbrev
=
12068 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12069 sections
.abbrev_offset
, sections
.abbrev_size
);
12070 dwo_file
->sections
.line
=
12071 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12072 sections
.line_offset
, sections
.line_size
);
12073 dwo_file
->sections
.loc
=
12074 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12075 sections
.loc_offset
, sections
.loc_size
);
12076 dwo_file
->sections
.macinfo
=
12077 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12078 sections
.macinfo_offset
, sections
.macinfo_size
);
12079 dwo_file
->sections
.macro
=
12080 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12081 sections
.macro_offset
, sections
.macro_size
);
12082 dwo_file
->sections
.str_offsets
=
12083 create_dwp_v2_section (dwarf2_per_objfile
,
12084 &dwp_file
->sections
.str_offsets
,
12085 sections
.str_offsets_offset
,
12086 sections
.str_offsets_size
);
12087 /* The "str" section is global to the entire DWP file. */
12088 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12089 /* The info or types section is assigned below to dwo_unit,
12090 there's no need to record it in dwo_file.
12091 Also, we can't simply record type sections in dwo_file because
12092 we record a pointer into the vector in dwo_unit. As we collect more
12093 types we'll grow the vector and eventually have to reallocate space
12094 for it, invalidating all copies of pointers into the previous
12096 *dwo_file_slot
= dwo_file
;
12100 if (dwarf_read_debug
)
12102 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12103 virtual_dwo_name
.c_str ());
12105 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12108 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12109 dwo_unit
->dwo_file
= dwo_file
;
12110 dwo_unit
->signature
= signature
;
12111 dwo_unit
->section
=
12112 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12113 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12115 ? &dwp_file
->sections
.types
12116 : &dwp_file
->sections
.info
,
12117 sections
.info_or_types_offset
,
12118 sections
.info_or_types_size
);
12119 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12124 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12125 Returns NULL if the signature isn't found. */
12127 static struct dwo_unit
*
12128 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12129 struct dwp_file
*dwp_file
, const char *comp_dir
,
12130 ULONGEST signature
, int is_debug_types
)
12132 const struct dwp_hash_table
*dwp_htab
=
12133 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12134 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12135 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12136 uint32_t hash
= signature
& mask
;
12137 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12140 struct dwo_unit find_dwo_cu
;
12142 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12143 find_dwo_cu
.signature
= signature
;
12144 slot
= htab_find_slot (is_debug_types
12145 ? dwp_file
->loaded_tus
.get ()
12146 : dwp_file
->loaded_cus
.get (),
12147 &find_dwo_cu
, INSERT
);
12150 return (struct dwo_unit
*) *slot
;
12152 /* Use a for loop so that we don't loop forever on bad debug info. */
12153 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12155 ULONGEST signature_in_table
;
12157 signature_in_table
=
12158 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12159 if (signature_in_table
== signature
)
12161 uint32_t unit_index
=
12162 read_4_bytes (dbfd
,
12163 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12165 if (dwp_file
->version
== 1)
12167 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12168 dwp_file
, unit_index
,
12169 comp_dir
, signature
,
12174 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12175 dwp_file
, unit_index
,
12176 comp_dir
, signature
,
12179 return (struct dwo_unit
*) *slot
;
12181 if (signature_in_table
== 0)
12183 hash
= (hash
+ hash2
) & mask
;
12186 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12187 " [in module %s]"),
12191 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12192 Open the file specified by FILE_NAME and hand it off to BFD for
12193 preliminary analysis. Return a newly initialized bfd *, which
12194 includes a canonicalized copy of FILE_NAME.
12195 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12196 SEARCH_CWD is true if the current directory is to be searched.
12197 It will be searched before debug-file-directory.
12198 If successful, the file is added to the bfd include table of the
12199 objfile's bfd (see gdb_bfd_record_inclusion).
12200 If unable to find/open the file, return NULL.
12201 NOTE: This function is derived from symfile_bfd_open. */
12203 static gdb_bfd_ref_ptr
12204 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12205 const char *file_name
, int is_dwp
, int search_cwd
)
12208 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12209 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12210 to debug_file_directory. */
12211 const char *search_path
;
12212 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12214 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12217 if (*debug_file_directory
!= '\0')
12219 search_path_holder
.reset (concat (".", dirname_separator_string
,
12220 debug_file_directory
,
12222 search_path
= search_path_holder
.get ();
12228 search_path
= debug_file_directory
;
12230 openp_flags flags
= OPF_RETURN_REALPATH
;
12232 flags
|= OPF_SEARCH_IN_PATH
;
12234 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12235 desc
= openp (search_path
, flags
, file_name
,
12236 O_RDONLY
| O_BINARY
, &absolute_name
);
12240 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12242 if (sym_bfd
== NULL
)
12244 bfd_set_cacheable (sym_bfd
.get (), 1);
12246 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12249 /* Success. Record the bfd as having been included by the objfile's bfd.
12250 This is important because things like demangled_names_hash lives in the
12251 objfile's per_bfd space and may have references to things like symbol
12252 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12253 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12258 /* Try to open DWO file FILE_NAME.
12259 COMP_DIR is the DW_AT_comp_dir attribute.
12260 The result is the bfd handle of the file.
12261 If there is a problem finding or opening the file, return NULL.
12262 Upon success, the canonicalized path of the file is stored in the bfd,
12263 same as symfile_bfd_open. */
12265 static gdb_bfd_ref_ptr
12266 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12267 const char *file_name
, const char *comp_dir
)
12269 if (IS_ABSOLUTE_PATH (file_name
))
12270 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12271 0 /*is_dwp*/, 0 /*search_cwd*/);
12273 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12275 if (comp_dir
!= NULL
)
12277 gdb::unique_xmalloc_ptr
<char> path_to_try
12278 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12280 /* NOTE: If comp_dir is a relative path, this will also try the
12281 search path, which seems useful. */
12282 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12283 path_to_try
.get (),
12285 1 /*search_cwd*/));
12290 /* That didn't work, try debug-file-directory, which, despite its name,
12291 is a list of paths. */
12293 if (*debug_file_directory
== '\0')
12296 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12297 0 /*is_dwp*/, 1 /*search_cwd*/);
12300 /* This function is mapped across the sections and remembers the offset and
12301 size of each of the DWO debugging sections we are interested in. */
12304 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12306 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12307 const struct dwop_section_names
*names
= &dwop_section_names
;
12309 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12311 dwo_sections
->abbrev
.s
.section
= sectp
;
12312 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12314 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12316 dwo_sections
->info
.s
.section
= sectp
;
12317 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12319 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12321 dwo_sections
->line
.s
.section
= sectp
;
12322 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12324 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12326 dwo_sections
->loc
.s
.section
= sectp
;
12327 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12329 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12331 dwo_sections
->loclists
.s
.section
= sectp
;
12332 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12334 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12336 dwo_sections
->macinfo
.s
.section
= sectp
;
12337 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12339 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12341 dwo_sections
->macro
.s
.section
= sectp
;
12342 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12344 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12346 dwo_sections
->str
.s
.section
= sectp
;
12347 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12349 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12351 dwo_sections
->str_offsets
.s
.section
= sectp
;
12352 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12354 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12356 struct dwarf2_section_info type_section
;
12358 memset (&type_section
, 0, sizeof (type_section
));
12359 type_section
.s
.section
= sectp
;
12360 type_section
.size
= bfd_section_size (sectp
);
12361 dwo_sections
->types
.push_back (type_section
);
12365 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12366 by PER_CU. This is for the non-DWP case.
12367 The result is NULL if DWO_NAME can't be found. */
12369 static struct dwo_file
*
12370 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12371 const char *comp_dir
)
12373 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12375 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12378 if (dwarf_read_debug
)
12379 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12383 dwo_file_up
dwo_file (new struct dwo_file
);
12384 dwo_file
->dwo_name
= dwo_name
;
12385 dwo_file
->comp_dir
= comp_dir
;
12386 dwo_file
->dbfd
= std::move (dbfd
);
12388 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12389 &dwo_file
->sections
);
12391 create_cus_hash_table (dwarf2_per_objfile
, cu
, *dwo_file
,
12392 dwo_file
->sections
.info
, dwo_file
->cus
);
12394 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12395 dwo_file
->sections
.types
, dwo_file
->tus
);
12397 if (dwarf_read_debug
)
12398 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12400 return dwo_file
.release ();
12403 /* This function is mapped across the sections and remembers the offset and
12404 size of each of the DWP debugging sections common to version 1 and 2 that
12405 we are interested in. */
12408 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12409 void *dwp_file_ptr
)
12411 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12412 const struct dwop_section_names
*names
= &dwop_section_names
;
12413 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12415 /* Record the ELF section number for later lookup: this is what the
12416 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12417 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12418 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12420 /* Look for specific sections that we need. */
12421 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12423 dwp_file
->sections
.str
.s
.section
= sectp
;
12424 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12426 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12428 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12429 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12431 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12433 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12434 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12438 /* This function is mapped across the sections and remembers the offset and
12439 size of each of the DWP version 2 debugging sections that we are interested
12440 in. This is split into a separate function because we don't know if we
12441 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12444 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12446 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12447 const struct dwop_section_names
*names
= &dwop_section_names
;
12448 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12450 /* Record the ELF section number for later lookup: this is what the
12451 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12452 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12453 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12455 /* Look for specific sections that we need. */
12456 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12458 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12459 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12461 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12463 dwp_file
->sections
.info
.s
.section
= sectp
;
12464 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12466 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12468 dwp_file
->sections
.line
.s
.section
= sectp
;
12469 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12471 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12473 dwp_file
->sections
.loc
.s
.section
= sectp
;
12474 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12476 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12478 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12479 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12481 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12483 dwp_file
->sections
.macro
.s
.section
= sectp
;
12484 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12486 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12488 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12489 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12491 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12493 dwp_file
->sections
.types
.s
.section
= sectp
;
12494 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12498 /* Hash function for dwp_file loaded CUs/TUs. */
12501 hash_dwp_loaded_cutus (const void *item
)
12503 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12505 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12506 return dwo_unit
->signature
;
12509 /* Equality function for dwp_file loaded CUs/TUs. */
12512 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12514 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12515 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12517 return dua
->signature
== dub
->signature
;
12520 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12523 allocate_dwp_loaded_cutus_table ()
12525 return htab_up (htab_create_alloc (3,
12526 hash_dwp_loaded_cutus
,
12527 eq_dwp_loaded_cutus
,
12528 NULL
, xcalloc
, xfree
));
12531 /* Try to open DWP file FILE_NAME.
12532 The result is the bfd handle of the file.
12533 If there is a problem finding or opening the file, return NULL.
12534 Upon success, the canonicalized path of the file is stored in the bfd,
12535 same as symfile_bfd_open. */
12537 static gdb_bfd_ref_ptr
12538 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12539 const char *file_name
)
12541 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12543 1 /*search_cwd*/));
12547 /* Work around upstream bug 15652.
12548 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12549 [Whether that's a "bug" is debatable, but it is getting in our way.]
12550 We have no real idea where the dwp file is, because gdb's realpath-ing
12551 of the executable's path may have discarded the needed info.
12552 [IWBN if the dwp file name was recorded in the executable, akin to
12553 .gnu_debuglink, but that doesn't exist yet.]
12554 Strip the directory from FILE_NAME and search again. */
12555 if (*debug_file_directory
!= '\0')
12557 /* Don't implicitly search the current directory here.
12558 If the user wants to search "." to handle this case,
12559 it must be added to debug-file-directory. */
12560 return try_open_dwop_file (dwarf2_per_objfile
,
12561 lbasename (file_name
), 1 /*is_dwp*/,
12568 /* Initialize the use of the DWP file for the current objfile.
12569 By convention the name of the DWP file is ${objfile}.dwp.
12570 The result is NULL if it can't be found. */
12572 static std::unique_ptr
<struct dwp_file
>
12573 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12577 /* Try to find first .dwp for the binary file before any symbolic links
12580 /* If the objfile is a debug file, find the name of the real binary
12581 file and get the name of dwp file from there. */
12582 std::string dwp_name
;
12583 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12585 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12586 const char *backlink_basename
= lbasename (backlink
->original_name
);
12588 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12591 dwp_name
= objfile
->original_name
;
12593 dwp_name
+= ".dwp";
12595 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12597 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12599 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12600 dwp_name
= objfile_name (objfile
);
12601 dwp_name
+= ".dwp";
12602 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12607 if (dwarf_read_debug
)
12608 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12609 return std::unique_ptr
<dwp_file
> ();
12612 const char *name
= bfd_get_filename (dbfd
.get ());
12613 std::unique_ptr
<struct dwp_file
> dwp_file
12614 (new struct dwp_file (name
, std::move (dbfd
)));
12616 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12617 dwp_file
->elf_sections
=
12618 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12619 dwp_file
->num_sections
, asection
*);
12621 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12622 dwarf2_locate_common_dwp_sections
,
12625 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12628 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12631 /* The DWP file version is stored in the hash table. Oh well. */
12632 if (dwp_file
->cus
&& dwp_file
->tus
12633 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12635 /* Technically speaking, we should try to limp along, but this is
12636 pretty bizarre. We use pulongest here because that's the established
12637 portability solution (e.g, we cannot use %u for uint32_t). */
12638 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12639 " TU version %s [in DWP file %s]"),
12640 pulongest (dwp_file
->cus
->version
),
12641 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12645 dwp_file
->version
= dwp_file
->cus
->version
;
12646 else if (dwp_file
->tus
)
12647 dwp_file
->version
= dwp_file
->tus
->version
;
12649 dwp_file
->version
= 2;
12651 if (dwp_file
->version
== 2)
12652 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12653 dwarf2_locate_v2_dwp_sections
,
12656 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12657 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12659 if (dwarf_read_debug
)
12661 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12662 fprintf_unfiltered (gdb_stdlog
,
12663 " %s CUs, %s TUs\n",
12664 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12665 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12671 /* Wrapper around open_and_init_dwp_file, only open it once. */
12673 static struct dwp_file
*
12674 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12676 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12678 dwarf2_per_objfile
->per_bfd
->dwp_file
12679 = open_and_init_dwp_file (dwarf2_per_objfile
);
12680 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12682 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12685 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12686 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12687 or in the DWP file for the objfile, referenced by THIS_UNIT.
12688 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12689 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12691 This is called, for example, when wanting to read a variable with a
12692 complex location. Therefore we don't want to do file i/o for every call.
12693 Therefore we don't want to look for a DWO file on every call.
12694 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12695 then we check if we've already seen DWO_NAME, and only THEN do we check
12698 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12699 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12701 static struct dwo_unit
*
12702 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12703 ULONGEST signature
, int is_debug_types
)
12705 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12706 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12707 const char *kind
= is_debug_types
? "TU" : "CU";
12708 void **dwo_file_slot
;
12709 struct dwo_file
*dwo_file
;
12710 struct dwp_file
*dwp_file
;
12712 /* First see if there's a DWP file.
12713 If we have a DWP file but didn't find the DWO inside it, don't
12714 look for the original DWO file. It makes gdb behave differently
12715 depending on whether one is debugging in the build tree. */
12717 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12718 if (dwp_file
!= NULL
)
12720 const struct dwp_hash_table
*dwp_htab
=
12721 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12723 if (dwp_htab
!= NULL
)
12725 struct dwo_unit
*dwo_cutu
=
12726 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12727 signature
, is_debug_types
);
12729 if (dwo_cutu
!= NULL
)
12731 if (dwarf_read_debug
)
12733 fprintf_unfiltered (gdb_stdlog
,
12734 "Virtual DWO %s %s found: @%s\n",
12735 kind
, hex_string (signature
),
12736 host_address_to_string (dwo_cutu
));
12744 /* No DWP file, look for the DWO file. */
12746 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12747 dwo_name
, comp_dir
);
12748 if (*dwo_file_slot
== NULL
)
12750 /* Read in the file and build a table of the CUs/TUs it contains. */
12751 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12753 /* NOTE: This will be NULL if unable to open the file. */
12754 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12756 if (dwo_file
!= NULL
)
12758 struct dwo_unit
*dwo_cutu
= NULL
;
12760 if (is_debug_types
&& dwo_file
->tus
)
12762 struct dwo_unit find_dwo_cutu
;
12764 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12765 find_dwo_cutu
.signature
= signature
;
12767 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12770 else if (!is_debug_types
&& dwo_file
->cus
)
12772 struct dwo_unit find_dwo_cutu
;
12774 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12775 find_dwo_cutu
.signature
= signature
;
12776 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12780 if (dwo_cutu
!= NULL
)
12782 if (dwarf_read_debug
)
12784 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12785 kind
, dwo_name
, hex_string (signature
),
12786 host_address_to_string (dwo_cutu
));
12793 /* We didn't find it. This could mean a dwo_id mismatch, or
12794 someone deleted the DWO/DWP file, or the search path isn't set up
12795 correctly to find the file. */
12797 if (dwarf_read_debug
)
12799 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12800 kind
, dwo_name
, hex_string (signature
));
12803 /* This is a warning and not a complaint because it can be caused by
12804 pilot error (e.g., user accidentally deleting the DWO). */
12806 /* Print the name of the DWP file if we looked there, helps the user
12807 better diagnose the problem. */
12808 std::string dwp_text
;
12810 if (dwp_file
!= NULL
)
12811 dwp_text
= string_printf (" [in DWP file %s]",
12812 lbasename (dwp_file
->name
));
12814 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12815 " [in module %s]"),
12816 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12817 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12822 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12823 See lookup_dwo_cutu_unit for details. */
12825 static struct dwo_unit
*
12826 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12827 ULONGEST signature
)
12829 gdb_assert (!cu
->per_cu
->is_debug_types
);
12831 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12834 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12835 See lookup_dwo_cutu_unit for details. */
12837 static struct dwo_unit
*
12838 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12840 gdb_assert (cu
->per_cu
->is_debug_types
);
12842 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12844 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12847 /* Traversal function for queue_and_load_all_dwo_tus. */
12850 queue_and_load_dwo_tu (void **slot
, void *info
)
12852 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12853 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12854 ULONGEST signature
= dwo_unit
->signature
;
12855 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12857 if (sig_type
!= NULL
)
12859 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12861 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12862 a real dependency of PER_CU on SIG_TYPE. That is detected later
12863 while processing PER_CU. */
12864 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12865 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12866 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12872 /* Queue all TUs contained in the DWO of CU to be read in.
12873 The DWO may have the only definition of the type, though it may not be
12874 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12875 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12878 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12880 struct dwo_unit
*dwo_unit
;
12881 struct dwo_file
*dwo_file
;
12883 gdb_assert (cu
!= nullptr);
12884 gdb_assert (!cu
->per_cu
->is_debug_types
);
12885 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12887 dwo_unit
= cu
->dwo_unit
;
12888 gdb_assert (dwo_unit
!= NULL
);
12890 dwo_file
= dwo_unit
->dwo_file
;
12891 if (dwo_file
->tus
!= NULL
)
12892 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12895 /* Read in various DIEs. */
12897 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12898 Inherit only the children of the DW_AT_abstract_origin DIE not being
12899 already referenced by DW_AT_abstract_origin from the children of the
12903 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12905 struct die_info
*child_die
;
12906 sect_offset
*offsetp
;
12907 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12908 struct die_info
*origin_die
;
12909 /* Iterator of the ORIGIN_DIE children. */
12910 struct die_info
*origin_child_die
;
12911 struct attribute
*attr
;
12912 struct dwarf2_cu
*origin_cu
;
12913 struct pending
**origin_previous_list_in_scope
;
12915 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12919 /* Note that following die references may follow to a die in a
12923 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12925 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12927 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12928 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12930 if (die
->tag
!= origin_die
->tag
12931 && !(die
->tag
== DW_TAG_inlined_subroutine
12932 && origin_die
->tag
== DW_TAG_subprogram
))
12933 complaint (_("DIE %s and its abstract origin %s have different tags"),
12934 sect_offset_str (die
->sect_off
),
12935 sect_offset_str (origin_die
->sect_off
));
12937 std::vector
<sect_offset
> offsets
;
12939 for (child_die
= die
->child
;
12940 child_die
&& child_die
->tag
;
12941 child_die
= child_die
->sibling
)
12943 struct die_info
*child_origin_die
;
12944 struct dwarf2_cu
*child_origin_cu
;
12946 /* We are trying to process concrete instance entries:
12947 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12948 it's not relevant to our analysis here. i.e. detecting DIEs that are
12949 present in the abstract instance but not referenced in the concrete
12951 if (child_die
->tag
== DW_TAG_call_site
12952 || child_die
->tag
== DW_TAG_GNU_call_site
)
12955 /* For each CHILD_DIE, find the corresponding child of
12956 ORIGIN_DIE. If there is more than one layer of
12957 DW_AT_abstract_origin, follow them all; there shouldn't be,
12958 but GCC versions at least through 4.4 generate this (GCC PR
12960 child_origin_die
= child_die
;
12961 child_origin_cu
= cu
;
12964 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12968 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12972 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12973 counterpart may exist. */
12974 if (child_origin_die
!= child_die
)
12976 if (child_die
->tag
!= child_origin_die
->tag
12977 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12978 && child_origin_die
->tag
== DW_TAG_subprogram
))
12979 complaint (_("Child DIE %s and its abstract origin %s have "
12981 sect_offset_str (child_die
->sect_off
),
12982 sect_offset_str (child_origin_die
->sect_off
));
12983 if (child_origin_die
->parent
!= origin_die
)
12984 complaint (_("Child DIE %s and its abstract origin %s have "
12985 "different parents"),
12986 sect_offset_str (child_die
->sect_off
),
12987 sect_offset_str (child_origin_die
->sect_off
));
12989 offsets
.push_back (child_origin_die
->sect_off
);
12992 std::sort (offsets
.begin (), offsets
.end ());
12993 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12994 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12995 if (offsetp
[-1] == *offsetp
)
12996 complaint (_("Multiple children of DIE %s refer "
12997 "to DIE %s as their abstract origin"),
12998 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13000 offsetp
= offsets
.data ();
13001 origin_child_die
= origin_die
->child
;
13002 while (origin_child_die
&& origin_child_die
->tag
)
13004 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13005 while (offsetp
< offsets_end
13006 && *offsetp
< origin_child_die
->sect_off
)
13008 if (offsetp
>= offsets_end
13009 || *offsetp
> origin_child_die
->sect_off
)
13011 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13012 Check whether we're already processing ORIGIN_CHILD_DIE.
13013 This can happen with mutually referenced abstract_origins.
13015 if (!origin_child_die
->in_process
)
13016 process_die (origin_child_die
, origin_cu
);
13018 origin_child_die
= origin_child_die
->sibling
;
13020 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13022 if (cu
!= origin_cu
)
13023 compute_delayed_physnames (origin_cu
);
13027 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13029 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13030 struct gdbarch
*gdbarch
= objfile
->arch ();
13031 struct context_stack
*newobj
;
13034 struct die_info
*child_die
;
13035 struct attribute
*attr
, *call_line
, *call_file
;
13037 CORE_ADDR baseaddr
;
13038 struct block
*block
;
13039 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13040 std::vector
<struct symbol
*> template_args
;
13041 struct template_symbol
*templ_func
= NULL
;
13045 /* If we do not have call site information, we can't show the
13046 caller of this inlined function. That's too confusing, so
13047 only use the scope for local variables. */
13048 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13049 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13050 if (call_line
== NULL
|| call_file
== NULL
)
13052 read_lexical_block_scope (die
, cu
);
13057 baseaddr
= objfile
->text_section_offset ();
13059 name
= dwarf2_name (die
, cu
);
13061 /* Ignore functions with missing or empty names. These are actually
13062 illegal according to the DWARF standard. */
13065 complaint (_("missing name for subprogram DIE at %s"),
13066 sect_offset_str (die
->sect_off
));
13070 /* Ignore functions with missing or invalid low and high pc attributes. */
13071 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13072 <= PC_BOUNDS_INVALID
)
13074 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13075 if (!attr
|| !DW_UNSND (attr
))
13076 complaint (_("cannot get low and high bounds "
13077 "for subprogram DIE at %s"),
13078 sect_offset_str (die
->sect_off
));
13082 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13083 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13085 /* If we have any template arguments, then we must allocate a
13086 different sort of symbol. */
13087 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13089 if (child_die
->tag
== DW_TAG_template_type_param
13090 || child_die
->tag
== DW_TAG_template_value_param
)
13092 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13093 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13098 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13099 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13100 (struct symbol
*) templ_func
);
13102 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13103 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13106 /* If there is a location expression for DW_AT_frame_base, record
13108 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13109 if (attr
!= nullptr)
13110 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13112 /* If there is a location for the static link, record it. */
13113 newobj
->static_link
= NULL
;
13114 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13115 if (attr
!= nullptr)
13117 newobj
->static_link
13118 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13119 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13123 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13125 if (die
->child
!= NULL
)
13127 child_die
= die
->child
;
13128 while (child_die
&& child_die
->tag
)
13130 if (child_die
->tag
== DW_TAG_template_type_param
13131 || child_die
->tag
== DW_TAG_template_value_param
)
13133 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13136 template_args
.push_back (arg
);
13139 process_die (child_die
, cu
);
13140 child_die
= child_die
->sibling
;
13144 inherit_abstract_dies (die
, cu
);
13146 /* If we have a DW_AT_specification, we might need to import using
13147 directives from the context of the specification DIE. See the
13148 comment in determine_prefix. */
13149 if (cu
->language
== language_cplus
13150 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13152 struct dwarf2_cu
*spec_cu
= cu
;
13153 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13157 child_die
= spec_die
->child
;
13158 while (child_die
&& child_die
->tag
)
13160 if (child_die
->tag
== DW_TAG_imported_module
)
13161 process_die (child_die
, spec_cu
);
13162 child_die
= child_die
->sibling
;
13165 /* In some cases, GCC generates specification DIEs that
13166 themselves contain DW_AT_specification attributes. */
13167 spec_die
= die_specification (spec_die
, &spec_cu
);
13171 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13172 /* Make a block for the local symbols within. */
13173 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13174 cstk
.static_link
, lowpc
, highpc
);
13176 /* For C++, set the block's scope. */
13177 if ((cu
->language
== language_cplus
13178 || cu
->language
== language_fortran
13179 || cu
->language
== language_d
13180 || cu
->language
== language_rust
)
13181 && cu
->processing_has_namespace_info
)
13182 block_set_scope (block
, determine_prefix (die
, cu
),
13183 &objfile
->objfile_obstack
);
13185 /* If we have address ranges, record them. */
13186 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13188 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13190 /* Attach template arguments to function. */
13191 if (!template_args
.empty ())
13193 gdb_assert (templ_func
!= NULL
);
13195 templ_func
->n_template_arguments
= template_args
.size ();
13196 templ_func
->template_arguments
13197 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13198 templ_func
->n_template_arguments
);
13199 memcpy (templ_func
->template_arguments
,
13200 template_args
.data (),
13201 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13203 /* Make sure that the symtab is set on the new symbols. Even
13204 though they don't appear in this symtab directly, other parts
13205 of gdb assume that symbols do, and this is reasonably
13207 for (symbol
*sym
: template_args
)
13208 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13211 /* In C++, we can have functions nested inside functions (e.g., when
13212 a function declares a class that has methods). This means that
13213 when we finish processing a function scope, we may need to go
13214 back to building a containing block's symbol lists. */
13215 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13216 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13218 /* If we've finished processing a top-level function, subsequent
13219 symbols go in the file symbol list. */
13220 if (cu
->get_builder ()->outermost_context_p ())
13221 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13224 /* Process all the DIES contained within a lexical block scope. Start
13225 a new scope, process the dies, and then close the scope. */
13228 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13230 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13231 struct gdbarch
*gdbarch
= objfile
->arch ();
13232 CORE_ADDR lowpc
, highpc
;
13233 struct die_info
*child_die
;
13234 CORE_ADDR baseaddr
;
13236 baseaddr
= objfile
->text_section_offset ();
13238 /* Ignore blocks with missing or invalid low and high pc attributes. */
13239 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13240 as multiple lexical blocks? Handling children in a sane way would
13241 be nasty. Might be easier to properly extend generic blocks to
13242 describe ranges. */
13243 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13245 case PC_BOUNDS_NOT_PRESENT
:
13246 /* DW_TAG_lexical_block has no attributes, process its children as if
13247 there was no wrapping by that DW_TAG_lexical_block.
13248 GCC does no longer produces such DWARF since GCC r224161. */
13249 for (child_die
= die
->child
;
13250 child_die
!= NULL
&& child_die
->tag
;
13251 child_die
= child_die
->sibling
)
13253 /* We might already be processing this DIE. This can happen
13254 in an unusual circumstance -- where a subroutine A
13255 appears lexically in another subroutine B, but A actually
13256 inlines B. The recursion is broken here, rather than in
13257 inherit_abstract_dies, because it seems better to simply
13258 drop concrete children here. */
13259 if (!child_die
->in_process
)
13260 process_die (child_die
, cu
);
13263 case PC_BOUNDS_INVALID
:
13266 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13267 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13269 cu
->get_builder ()->push_context (0, lowpc
);
13270 if (die
->child
!= NULL
)
13272 child_die
= die
->child
;
13273 while (child_die
&& child_die
->tag
)
13275 process_die (child_die
, cu
);
13276 child_die
= child_die
->sibling
;
13279 inherit_abstract_dies (die
, cu
);
13280 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13282 if (*cu
->get_builder ()->get_local_symbols () != NULL
13283 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13285 struct block
*block
13286 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13287 cstk
.start_addr
, highpc
);
13289 /* Note that recording ranges after traversing children, as we
13290 do here, means that recording a parent's ranges entails
13291 walking across all its children's ranges as they appear in
13292 the address map, which is quadratic behavior.
13294 It would be nicer to record the parent's ranges before
13295 traversing its children, simply overriding whatever you find
13296 there. But since we don't even decide whether to create a
13297 block until after we've traversed its children, that's hard
13299 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13301 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13302 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13305 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13308 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13310 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13311 struct objfile
*objfile
= per_objfile
->objfile
;
13312 struct gdbarch
*gdbarch
= objfile
->arch ();
13313 CORE_ADDR pc
, baseaddr
;
13314 struct attribute
*attr
;
13315 struct call_site
*call_site
, call_site_local
;
13318 struct die_info
*child_die
;
13320 baseaddr
= objfile
->text_section_offset ();
13322 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13325 /* This was a pre-DWARF-5 GNU extension alias
13326 for DW_AT_call_return_pc. */
13327 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13331 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13332 "DIE %s [in module %s]"),
13333 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13336 pc
= attr
->value_as_address () + baseaddr
;
13337 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13339 if (cu
->call_site_htab
== NULL
)
13340 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13341 NULL
, &objfile
->objfile_obstack
,
13342 hashtab_obstack_allocate
, NULL
);
13343 call_site_local
.pc
= pc
;
13344 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13347 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13348 "DIE %s [in module %s]"),
13349 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13350 objfile_name (objfile
));
13354 /* Count parameters at the caller. */
13357 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13358 child_die
= child_die
->sibling
)
13360 if (child_die
->tag
!= DW_TAG_call_site_parameter
13361 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13363 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13364 "DW_TAG_call_site child DIE %s [in module %s]"),
13365 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13366 objfile_name (objfile
));
13374 = ((struct call_site
*)
13375 obstack_alloc (&objfile
->objfile_obstack
,
13376 sizeof (*call_site
)
13377 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13379 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13380 call_site
->pc
= pc
;
13382 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13383 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13385 struct die_info
*func_die
;
13387 /* Skip also over DW_TAG_inlined_subroutine. */
13388 for (func_die
= die
->parent
;
13389 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13390 && func_die
->tag
!= DW_TAG_subroutine_type
;
13391 func_die
= func_die
->parent
);
13393 /* DW_AT_call_all_calls is a superset
13394 of DW_AT_call_all_tail_calls. */
13396 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13397 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13398 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13399 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13401 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13402 not complete. But keep CALL_SITE for look ups via call_site_htab,
13403 both the initial caller containing the real return address PC and
13404 the final callee containing the current PC of a chain of tail
13405 calls do not need to have the tail call list complete. But any
13406 function candidate for a virtual tail call frame searched via
13407 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13408 determined unambiguously. */
13412 struct type
*func_type
= NULL
;
13415 func_type
= get_die_type (func_die
, cu
);
13416 if (func_type
!= NULL
)
13418 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13420 /* Enlist this call site to the function. */
13421 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13422 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13425 complaint (_("Cannot find function owning DW_TAG_call_site "
13426 "DIE %s [in module %s]"),
13427 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13431 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13433 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13435 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13438 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13439 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13441 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13442 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13443 /* Keep NULL DWARF_BLOCK. */;
13444 else if (attr
->form_is_block ())
13446 struct dwarf2_locexpr_baton
*dlbaton
;
13448 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13449 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13450 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13451 dlbaton
->per_objfile
= per_objfile
;
13452 dlbaton
->per_cu
= cu
->per_cu
;
13454 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13456 else if (attr
->form_is_ref ())
13458 struct dwarf2_cu
*target_cu
= cu
;
13459 struct die_info
*target_die
;
13461 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13462 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13463 if (die_is_declaration (target_die
, target_cu
))
13465 const char *target_physname
;
13467 /* Prefer the mangled name; otherwise compute the demangled one. */
13468 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13469 if (target_physname
== NULL
)
13470 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13471 if (target_physname
== NULL
)
13472 complaint (_("DW_AT_call_target target DIE has invalid "
13473 "physname, for referencing DIE %s [in module %s]"),
13474 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13476 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13482 /* DW_AT_entry_pc should be preferred. */
13483 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13484 <= PC_BOUNDS_INVALID
)
13485 complaint (_("DW_AT_call_target target DIE has invalid "
13486 "low pc, for referencing DIE %s [in module %s]"),
13487 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13490 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13491 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13496 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13497 "block nor reference, for DIE %s [in module %s]"),
13498 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13500 call_site
->per_cu
= cu
->per_cu
;
13501 call_site
->per_objfile
= per_objfile
;
13503 for (child_die
= die
->child
;
13504 child_die
&& child_die
->tag
;
13505 child_die
= child_die
->sibling
)
13507 struct call_site_parameter
*parameter
;
13508 struct attribute
*loc
, *origin
;
13510 if (child_die
->tag
!= DW_TAG_call_site_parameter
13511 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13513 /* Already printed the complaint above. */
13517 gdb_assert (call_site
->parameter_count
< nparams
);
13518 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13520 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13521 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13522 register is contained in DW_AT_call_value. */
13524 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13525 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13526 if (origin
== NULL
)
13528 /* This was a pre-DWARF-5 GNU extension alias
13529 for DW_AT_call_parameter. */
13530 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13532 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13534 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13536 sect_offset sect_off
= origin
->get_ref_die_offset ();
13537 if (!cu
->header
.offset_in_cu_p (sect_off
))
13539 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13540 binding can be done only inside one CU. Such referenced DIE
13541 therefore cannot be even moved to DW_TAG_partial_unit. */
13542 complaint (_("DW_AT_call_parameter offset is not in CU for "
13543 "DW_TAG_call_site child DIE %s [in module %s]"),
13544 sect_offset_str (child_die
->sect_off
),
13545 objfile_name (objfile
));
13548 parameter
->u
.param_cu_off
13549 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13551 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13553 complaint (_("No DW_FORM_block* DW_AT_location for "
13554 "DW_TAG_call_site child DIE %s [in module %s]"),
13555 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13560 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13561 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13562 if (parameter
->u
.dwarf_reg
!= -1)
13563 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13564 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13565 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13566 ¶meter
->u
.fb_offset
))
13567 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13570 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13571 "for DW_FORM_block* DW_AT_location is supported for "
13572 "DW_TAG_call_site child DIE %s "
13574 sect_offset_str (child_die
->sect_off
),
13575 objfile_name (objfile
));
13580 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13582 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13583 if (attr
== NULL
|| !attr
->form_is_block ())
13585 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13586 "DW_TAG_call_site child DIE %s [in module %s]"),
13587 sect_offset_str (child_die
->sect_off
),
13588 objfile_name (objfile
));
13591 parameter
->value
= DW_BLOCK (attr
)->data
;
13592 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13594 /* Parameters are not pre-cleared by memset above. */
13595 parameter
->data_value
= NULL
;
13596 parameter
->data_value_size
= 0;
13597 call_site
->parameter_count
++;
13599 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13601 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13602 if (attr
!= nullptr)
13604 if (!attr
->form_is_block ())
13605 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13606 "DW_TAG_call_site child DIE %s [in module %s]"),
13607 sect_offset_str (child_die
->sect_off
),
13608 objfile_name (objfile
));
13611 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13612 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13618 /* Helper function for read_variable. If DIE represents a virtual
13619 table, then return the type of the concrete object that is
13620 associated with the virtual table. Otherwise, return NULL. */
13622 static struct type
*
13623 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13625 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13629 /* Find the type DIE. */
13630 struct die_info
*type_die
= NULL
;
13631 struct dwarf2_cu
*type_cu
= cu
;
13633 if (attr
->form_is_ref ())
13634 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13635 if (type_die
== NULL
)
13638 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13640 return die_containing_type (type_die
, type_cu
);
13643 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13646 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13648 struct rust_vtable_symbol
*storage
= NULL
;
13650 if (cu
->language
== language_rust
)
13652 struct type
*containing_type
= rust_containing_type (die
, cu
);
13654 if (containing_type
!= NULL
)
13656 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13658 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13659 storage
->concrete_type
= containing_type
;
13660 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13664 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13665 struct attribute
*abstract_origin
13666 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13667 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13668 if (res
== NULL
&& loc
&& abstract_origin
)
13670 /* We have a variable without a name, but with a location and an abstract
13671 origin. This may be a concrete instance of an abstract variable
13672 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13674 struct dwarf2_cu
*origin_cu
= cu
;
13675 struct die_info
*origin_die
13676 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13677 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13678 per_objfile
->per_bfd
->abstract_to_concrete
13679 [origin_die
->sect_off
].push_back (die
->sect_off
);
13683 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13684 reading .debug_rnglists.
13685 Callback's type should be:
13686 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13687 Return true if the attributes are present and valid, otherwise,
13690 template <typename Callback
>
13692 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13693 Callback
&&callback
)
13695 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13696 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13697 bfd
*obfd
= objfile
->obfd
;
13698 /* Base address selection entry. */
13699 gdb::optional
<CORE_ADDR
> base
;
13700 const gdb_byte
*buffer
;
13701 CORE_ADDR baseaddr
;
13702 bool overflow
= false;
13704 base
= cu
->base_address
;
13706 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13707 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13709 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13713 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13715 baseaddr
= objfile
->text_section_offset ();
13719 /* Initialize it due to a false compiler warning. */
13720 CORE_ADDR range_beginning
= 0, range_end
= 0;
13721 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13722 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13723 unsigned int bytes_read
;
13725 if (buffer
== buf_end
)
13730 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13733 case DW_RLE_end_of_list
:
13735 case DW_RLE_base_address
:
13736 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13741 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13742 buffer
+= bytes_read
;
13744 case DW_RLE_start_length
:
13745 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13750 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13752 buffer
+= bytes_read
;
13753 range_end
= (range_beginning
13754 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13755 buffer
+= bytes_read
;
13756 if (buffer
> buf_end
)
13762 case DW_RLE_offset_pair
:
13763 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13764 buffer
+= bytes_read
;
13765 if (buffer
> buf_end
)
13770 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13771 buffer
+= bytes_read
;
13772 if (buffer
> buf_end
)
13778 case DW_RLE_start_end
:
13779 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13784 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13786 buffer
+= bytes_read
;
13787 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13788 buffer
+= bytes_read
;
13791 complaint (_("Invalid .debug_rnglists data (no base address)"));
13794 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13796 if (rlet
== DW_RLE_base_address
)
13799 if (!base
.has_value ())
13801 /* We have no valid base address for the ranges
13803 complaint (_("Invalid .debug_rnglists data (no base address)"));
13807 if (range_beginning
> range_end
)
13809 /* Inverted range entries are invalid. */
13810 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13814 /* Empty range entries have no effect. */
13815 if (range_beginning
== range_end
)
13818 range_beginning
+= *base
;
13819 range_end
+= *base
;
13821 /* A not-uncommon case of bad debug info.
13822 Don't pollute the addrmap with bad data. */
13823 if (range_beginning
+ baseaddr
== 0
13824 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13826 complaint (_(".debug_rnglists entry has start address of zero"
13827 " [in module %s]"), objfile_name (objfile
));
13831 callback (range_beginning
, range_end
);
13836 complaint (_("Offset %d is not terminated "
13837 "for DW_AT_ranges attribute"),
13845 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13846 Callback's type should be:
13847 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13848 Return 1 if the attributes are present and valid, otherwise, return 0. */
13850 template <typename Callback
>
13852 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13853 Callback
&&callback
)
13855 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13856 struct objfile
*objfile
= per_objfile
->objfile
;
13857 struct comp_unit_head
*cu_header
= &cu
->header
;
13858 bfd
*obfd
= objfile
->obfd
;
13859 unsigned int addr_size
= cu_header
->addr_size
;
13860 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13861 /* Base address selection entry. */
13862 gdb::optional
<CORE_ADDR
> base
;
13863 unsigned int dummy
;
13864 const gdb_byte
*buffer
;
13865 CORE_ADDR baseaddr
;
13867 if (cu_header
->version
>= 5)
13868 return dwarf2_rnglists_process (offset
, cu
, callback
);
13870 base
= cu
->base_address
;
13872 per_objfile
->per_bfd
->ranges
.read (objfile
);
13873 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13875 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13879 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13881 baseaddr
= objfile
->text_section_offset ();
13885 CORE_ADDR range_beginning
, range_end
;
13887 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13888 buffer
+= addr_size
;
13889 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13890 buffer
+= addr_size
;
13891 offset
+= 2 * addr_size
;
13893 /* An end of list marker is a pair of zero addresses. */
13894 if (range_beginning
== 0 && range_end
== 0)
13895 /* Found the end of list entry. */
13898 /* Each base address selection entry is a pair of 2 values.
13899 The first is the largest possible address, the second is
13900 the base address. Check for a base address here. */
13901 if ((range_beginning
& mask
) == mask
)
13903 /* If we found the largest possible address, then we already
13904 have the base address in range_end. */
13909 if (!base
.has_value ())
13911 /* We have no valid base address for the ranges
13913 complaint (_("Invalid .debug_ranges data (no base address)"));
13917 if (range_beginning
> range_end
)
13919 /* Inverted range entries are invalid. */
13920 complaint (_("Invalid .debug_ranges data (inverted range)"));
13924 /* Empty range entries have no effect. */
13925 if (range_beginning
== range_end
)
13928 range_beginning
+= *base
;
13929 range_end
+= *base
;
13931 /* A not-uncommon case of bad debug info.
13932 Don't pollute the addrmap with bad data. */
13933 if (range_beginning
+ baseaddr
== 0
13934 && !per_objfile
->per_bfd
->has_section_at_zero
)
13936 complaint (_(".debug_ranges entry has start address of zero"
13937 " [in module %s]"), objfile_name (objfile
));
13941 callback (range_beginning
, range_end
);
13947 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13948 Return 1 if the attributes are present and valid, otherwise, return 0.
13949 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13952 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13953 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13954 dwarf2_psymtab
*ranges_pst
)
13956 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13957 struct gdbarch
*gdbarch
= objfile
->arch ();
13958 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13961 CORE_ADDR high
= 0;
13964 retval
= dwarf2_ranges_process (offset
, cu
,
13965 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13967 if (ranges_pst
!= NULL
)
13972 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13973 range_beginning
+ baseaddr
)
13975 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13976 range_end
+ baseaddr
)
13978 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13979 lowpc
, highpc
- 1, ranges_pst
);
13982 /* FIXME: This is recording everything as a low-high
13983 segment of consecutive addresses. We should have a
13984 data structure for discontiguous block ranges
13988 low
= range_beginning
;
13994 if (range_beginning
< low
)
13995 low
= range_beginning
;
13996 if (range_end
> high
)
14004 /* If the first entry is an end-of-list marker, the range
14005 describes an empty scope, i.e. no instructions. */
14011 *high_return
= high
;
14015 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14016 definition for the return value. *LOWPC and *HIGHPC are set iff
14017 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14019 static enum pc_bounds_kind
14020 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14021 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14022 dwarf2_psymtab
*pst
)
14024 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
14025 struct attribute
*attr
;
14026 struct attribute
*attr_high
;
14028 CORE_ADDR high
= 0;
14029 enum pc_bounds_kind ret
;
14031 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14034 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14035 if (attr
!= nullptr)
14037 low
= attr
->value_as_address ();
14038 high
= attr_high
->value_as_address ();
14039 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14043 /* Found high w/o low attribute. */
14044 return PC_BOUNDS_INVALID
;
14046 /* Found consecutive range of addresses. */
14047 ret
= PC_BOUNDS_HIGH_LOW
;
14051 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14054 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14055 We take advantage of the fact that DW_AT_ranges does not appear
14056 in DW_TAG_compile_unit of DWO files. */
14057 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14058 unsigned int ranges_offset
= (DW_UNSND (attr
)
14059 + (need_ranges_base
14063 /* Value of the DW_AT_ranges attribute is the offset in the
14064 .debug_ranges section. */
14065 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14066 return PC_BOUNDS_INVALID
;
14067 /* Found discontinuous range of addresses. */
14068 ret
= PC_BOUNDS_RANGES
;
14071 return PC_BOUNDS_NOT_PRESENT
;
14074 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14076 return PC_BOUNDS_INVALID
;
14078 /* When using the GNU linker, .gnu.linkonce. sections are used to
14079 eliminate duplicate copies of functions and vtables and such.
14080 The linker will arbitrarily choose one and discard the others.
14081 The AT_*_pc values for such functions refer to local labels in
14082 these sections. If the section from that file was discarded, the
14083 labels are not in the output, so the relocs get a value of 0.
14084 If this is a discarded function, mark the pc bounds as invalid,
14085 so that GDB will ignore it. */
14086 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14087 return PC_BOUNDS_INVALID
;
14095 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14096 its low and high PC addresses. Do nothing if these addresses could not
14097 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14098 and HIGHPC to the high address if greater than HIGHPC. */
14101 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14102 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14103 struct dwarf2_cu
*cu
)
14105 CORE_ADDR low
, high
;
14106 struct die_info
*child
= die
->child
;
14108 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14110 *lowpc
= std::min (*lowpc
, low
);
14111 *highpc
= std::max (*highpc
, high
);
14114 /* If the language does not allow nested subprograms (either inside
14115 subprograms or lexical blocks), we're done. */
14116 if (cu
->language
!= language_ada
)
14119 /* Check all the children of the given DIE. If it contains nested
14120 subprograms, then check their pc bounds. Likewise, we need to
14121 check lexical blocks as well, as they may also contain subprogram
14123 while (child
&& child
->tag
)
14125 if (child
->tag
== DW_TAG_subprogram
14126 || child
->tag
== DW_TAG_lexical_block
)
14127 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14128 child
= child
->sibling
;
14132 /* Get the low and high pc's represented by the scope DIE, and store
14133 them in *LOWPC and *HIGHPC. If the correct values can't be
14134 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14137 get_scope_pc_bounds (struct die_info
*die
,
14138 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14139 struct dwarf2_cu
*cu
)
14141 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14142 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14143 CORE_ADDR current_low
, current_high
;
14145 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14146 >= PC_BOUNDS_RANGES
)
14148 best_low
= current_low
;
14149 best_high
= current_high
;
14153 struct die_info
*child
= die
->child
;
14155 while (child
&& child
->tag
)
14157 switch (child
->tag
) {
14158 case DW_TAG_subprogram
:
14159 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14161 case DW_TAG_namespace
:
14162 case DW_TAG_module
:
14163 /* FIXME: carlton/2004-01-16: Should we do this for
14164 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14165 that current GCC's always emit the DIEs corresponding
14166 to definitions of methods of classes as children of a
14167 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14168 the DIEs giving the declarations, which could be
14169 anywhere). But I don't see any reason why the
14170 standards says that they have to be there. */
14171 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14173 if (current_low
!= ((CORE_ADDR
) -1))
14175 best_low
= std::min (best_low
, current_low
);
14176 best_high
= std::max (best_high
, current_high
);
14184 child
= child
->sibling
;
14189 *highpc
= best_high
;
14192 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14196 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14197 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14199 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14200 struct gdbarch
*gdbarch
= objfile
->arch ();
14201 struct attribute
*attr
;
14202 struct attribute
*attr_high
;
14204 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14207 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14208 if (attr
!= nullptr)
14210 CORE_ADDR low
= attr
->value_as_address ();
14211 CORE_ADDR high
= attr_high
->value_as_address ();
14213 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14216 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14217 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14218 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14222 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14223 if (attr
!= nullptr)
14225 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14226 We take advantage of the fact that DW_AT_ranges does not appear
14227 in DW_TAG_compile_unit of DWO files. */
14228 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14230 /* The value of the DW_AT_ranges attribute is the offset of the
14231 address range list in the .debug_ranges section. */
14232 unsigned long offset
= (DW_UNSND (attr
)
14233 + (need_ranges_base
? cu
->ranges_base
: 0));
14235 std::vector
<blockrange
> blockvec
;
14236 dwarf2_ranges_process (offset
, cu
,
14237 [&] (CORE_ADDR start
, CORE_ADDR end
)
14241 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14242 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14243 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14244 blockvec
.emplace_back (start
, end
);
14247 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14251 /* Check whether the producer field indicates either of GCC < 4.6, or the
14252 Intel C/C++ compiler, and cache the result in CU. */
14255 check_producer (struct dwarf2_cu
*cu
)
14259 if (cu
->producer
== NULL
)
14261 /* For unknown compilers expect their behavior is DWARF version
14264 GCC started to support .debug_types sections by -gdwarf-4 since
14265 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14266 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14267 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14268 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14270 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14272 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14273 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14275 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14277 cu
->producer_is_icc
= true;
14278 cu
->producer_is_icc_lt_14
= major
< 14;
14280 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14281 cu
->producer_is_codewarrior
= true;
14284 /* For other non-GCC compilers, expect their behavior is DWARF version
14288 cu
->checked_producer
= true;
14291 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14292 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14293 during 4.6.0 experimental. */
14296 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14298 if (!cu
->checked_producer
)
14299 check_producer (cu
);
14301 return cu
->producer_is_gxx_lt_4_6
;
14305 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14306 with incorrect is_stmt attributes. */
14309 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14311 if (!cu
->checked_producer
)
14312 check_producer (cu
);
14314 return cu
->producer_is_codewarrior
;
14317 /* Return the default accessibility type if it is not overridden by
14318 DW_AT_accessibility. */
14320 static enum dwarf_access_attribute
14321 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14323 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14325 /* The default DWARF 2 accessibility for members is public, the default
14326 accessibility for inheritance is private. */
14328 if (die
->tag
!= DW_TAG_inheritance
)
14329 return DW_ACCESS_public
;
14331 return DW_ACCESS_private
;
14335 /* DWARF 3+ defines the default accessibility a different way. The same
14336 rules apply now for DW_TAG_inheritance as for the members and it only
14337 depends on the container kind. */
14339 if (die
->parent
->tag
== DW_TAG_class_type
)
14340 return DW_ACCESS_private
;
14342 return DW_ACCESS_public
;
14346 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14347 offset. If the attribute was not found return 0, otherwise return
14348 1. If it was found but could not properly be handled, set *OFFSET
14352 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14355 struct attribute
*attr
;
14357 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14362 /* Note that we do not check for a section offset first here.
14363 This is because DW_AT_data_member_location is new in DWARF 4,
14364 so if we see it, we can assume that a constant form is really
14365 a constant and not a section offset. */
14366 if (attr
->form_is_constant ())
14367 *offset
= attr
->constant_value (0);
14368 else if (attr
->form_is_section_offset ())
14369 dwarf2_complex_location_expr_complaint ();
14370 else if (attr
->form_is_block ())
14371 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14373 dwarf2_complex_location_expr_complaint ();
14381 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14384 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14385 struct field
*field
)
14387 struct attribute
*attr
;
14389 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14392 if (attr
->form_is_constant ())
14394 LONGEST offset
= attr
->constant_value (0);
14395 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14397 else if (attr
->form_is_section_offset ())
14398 dwarf2_complex_location_expr_complaint ();
14399 else if (attr
->form_is_block ())
14402 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14404 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14407 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14408 struct objfile
*objfile
= per_objfile
->objfile
;
14409 struct dwarf2_locexpr_baton
*dlbaton
14410 = XOBNEW (&objfile
->objfile_obstack
,
14411 struct dwarf2_locexpr_baton
);
14412 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14413 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14414 /* When using this baton, we want to compute the address
14415 of the field, not the value. This is why
14416 is_reference is set to false here. */
14417 dlbaton
->is_reference
= false;
14418 dlbaton
->per_objfile
= per_objfile
;
14419 dlbaton
->per_cu
= cu
->per_cu
;
14421 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14425 dwarf2_complex_location_expr_complaint ();
14429 /* Add an aggregate field to the field list. */
14432 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14433 struct dwarf2_cu
*cu
)
14435 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14436 struct gdbarch
*gdbarch
= objfile
->arch ();
14437 struct nextfield
*new_field
;
14438 struct attribute
*attr
;
14440 const char *fieldname
= "";
14442 if (die
->tag
== DW_TAG_inheritance
)
14444 fip
->baseclasses
.emplace_back ();
14445 new_field
= &fip
->baseclasses
.back ();
14449 fip
->fields
.emplace_back ();
14450 new_field
= &fip
->fields
.back ();
14453 new_field
->offset
= die
->sect_off
;
14455 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14456 if (attr
!= nullptr)
14457 new_field
->accessibility
= DW_UNSND (attr
);
14459 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14460 if (new_field
->accessibility
!= DW_ACCESS_public
)
14461 fip
->non_public_fields
= 1;
14463 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14464 if (attr
!= nullptr)
14465 new_field
->virtuality
= DW_UNSND (attr
);
14467 new_field
->virtuality
= DW_VIRTUALITY_none
;
14469 fp
= &new_field
->field
;
14471 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14473 /* Data member other than a C++ static data member. */
14475 /* Get type of field. */
14476 fp
->type
= die_type (die
, cu
);
14478 SET_FIELD_BITPOS (*fp
, 0);
14480 /* Get bit size of field (zero if none). */
14481 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14482 if (attr
!= nullptr)
14484 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14488 FIELD_BITSIZE (*fp
) = 0;
14491 /* Get bit offset of field. */
14492 handle_data_member_location (die
, cu
, fp
);
14493 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14494 if (attr
!= nullptr)
14496 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14498 /* For big endian bits, the DW_AT_bit_offset gives the
14499 additional bit offset from the MSB of the containing
14500 anonymous object to the MSB of the field. We don't
14501 have to do anything special since we don't need to
14502 know the size of the anonymous object. */
14503 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14507 /* For little endian bits, compute the bit offset to the
14508 MSB of the anonymous object, subtract off the number of
14509 bits from the MSB of the field to the MSB of the
14510 object, and then subtract off the number of bits of
14511 the field itself. The result is the bit offset of
14512 the LSB of the field. */
14513 int anonymous_size
;
14514 int bit_offset
= DW_UNSND (attr
);
14516 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14517 if (attr
!= nullptr)
14519 /* The size of the anonymous object containing
14520 the bit field is explicit, so use the
14521 indicated size (in bytes). */
14522 anonymous_size
= DW_UNSND (attr
);
14526 /* The size of the anonymous object containing
14527 the bit field must be inferred from the type
14528 attribute of the data member containing the
14530 anonymous_size
= TYPE_LENGTH (fp
->type
);
14532 SET_FIELD_BITPOS (*fp
,
14533 (FIELD_BITPOS (*fp
)
14534 + anonymous_size
* bits_per_byte
14535 - bit_offset
- FIELD_BITSIZE (*fp
)));
14538 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14540 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14541 + attr
->constant_value (0)));
14543 /* Get name of field. */
14544 fieldname
= dwarf2_name (die
, cu
);
14545 if (fieldname
== NULL
)
14548 /* The name is already allocated along with this objfile, so we don't
14549 need to duplicate it for the type. */
14550 fp
->name
= fieldname
;
14552 /* Change accessibility for artificial fields (e.g. virtual table
14553 pointer or virtual base class pointer) to private. */
14554 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14556 FIELD_ARTIFICIAL (*fp
) = 1;
14557 new_field
->accessibility
= DW_ACCESS_private
;
14558 fip
->non_public_fields
= 1;
14561 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14563 /* C++ static member. */
14565 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14566 is a declaration, but all versions of G++ as of this writing
14567 (so through at least 3.2.1) incorrectly generate
14568 DW_TAG_variable tags. */
14570 const char *physname
;
14572 /* Get name of field. */
14573 fieldname
= dwarf2_name (die
, cu
);
14574 if (fieldname
== NULL
)
14577 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14579 /* Only create a symbol if this is an external value.
14580 new_symbol checks this and puts the value in the global symbol
14581 table, which we want. If it is not external, new_symbol
14582 will try to put the value in cu->list_in_scope which is wrong. */
14583 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14585 /* A static const member, not much different than an enum as far as
14586 we're concerned, except that we can support more types. */
14587 new_symbol (die
, NULL
, cu
);
14590 /* Get physical name. */
14591 physname
= dwarf2_physname (fieldname
, die
, cu
);
14593 /* The name is already allocated along with this objfile, so we don't
14594 need to duplicate it for the type. */
14595 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14596 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14597 FIELD_NAME (*fp
) = fieldname
;
14599 else if (die
->tag
== DW_TAG_inheritance
)
14601 /* C++ base class field. */
14602 handle_data_member_location (die
, cu
, fp
);
14603 FIELD_BITSIZE (*fp
) = 0;
14604 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14605 FIELD_NAME (*fp
) = fp
->type
->name ();
14608 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14611 /* Can the type given by DIE define another type? */
14614 type_can_define_types (const struct die_info
*die
)
14618 case DW_TAG_typedef
:
14619 case DW_TAG_class_type
:
14620 case DW_TAG_structure_type
:
14621 case DW_TAG_union_type
:
14622 case DW_TAG_enumeration_type
:
14630 /* Add a type definition defined in the scope of the FIP's class. */
14633 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14634 struct dwarf2_cu
*cu
)
14636 struct decl_field fp
;
14637 memset (&fp
, 0, sizeof (fp
));
14639 gdb_assert (type_can_define_types (die
));
14641 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14642 fp
.name
= dwarf2_name (die
, cu
);
14643 fp
.type
= read_type_die (die
, cu
);
14645 /* Save accessibility. */
14646 enum dwarf_access_attribute accessibility
;
14647 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14649 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14651 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14652 switch (accessibility
)
14654 case DW_ACCESS_public
:
14655 /* The assumed value if neither private nor protected. */
14657 case DW_ACCESS_private
:
14660 case DW_ACCESS_protected
:
14661 fp
.is_protected
= 1;
14664 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14667 if (die
->tag
== DW_TAG_typedef
)
14668 fip
->typedef_field_list
.push_back (fp
);
14670 fip
->nested_types_list
.push_back (fp
);
14673 /* A convenience typedef that's used when finding the discriminant
14674 field for a variant part. */
14675 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14678 /* Compute the discriminant range for a given variant. OBSTACK is
14679 where the results will be stored. VARIANT is the variant to
14680 process. IS_UNSIGNED indicates whether the discriminant is signed
14683 static const gdb::array_view
<discriminant_range
>
14684 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14687 std::vector
<discriminant_range
> ranges
;
14689 if (variant
.default_branch
)
14692 if (variant
.discr_list_data
== nullptr)
14694 discriminant_range r
14695 = {variant
.discriminant_value
, variant
.discriminant_value
};
14696 ranges
.push_back (r
);
14700 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14701 variant
.discr_list_data
->size
);
14702 while (!data
.empty ())
14704 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14706 complaint (_("invalid discriminant marker: %d"), data
[0]);
14709 bool is_range
= data
[0] == DW_DSC_range
;
14710 data
= data
.slice (1);
14712 ULONGEST low
, high
;
14713 unsigned int bytes_read
;
14717 complaint (_("DW_AT_discr_list missing low value"));
14721 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14723 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14725 data
= data
.slice (bytes_read
);
14731 complaint (_("DW_AT_discr_list missing high value"));
14735 high
= read_unsigned_leb128 (nullptr, data
.data (),
14738 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14740 data
= data
.slice (bytes_read
);
14745 ranges
.push_back ({ low
, high
});
14749 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14751 std::copy (ranges
.begin (), ranges
.end (), result
);
14752 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14755 static const gdb::array_view
<variant_part
> create_variant_parts
14756 (struct obstack
*obstack
,
14757 const offset_map_type
&offset_map
,
14758 struct field_info
*fi
,
14759 const std::vector
<variant_part_builder
> &variant_parts
);
14761 /* Fill in a "struct variant" for a given variant field. RESULT is
14762 the variant to fill in. OBSTACK is where any needed allocations
14763 will be done. OFFSET_MAP holds the mapping from section offsets to
14764 fields for the type. FI describes the fields of the type we're
14765 processing. FIELD is the variant field we're converting. */
14768 create_one_variant (variant
&result
, struct obstack
*obstack
,
14769 const offset_map_type
&offset_map
,
14770 struct field_info
*fi
, const variant_field
&field
)
14772 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14773 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14774 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14775 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14776 field
.variant_parts
);
14779 /* Fill in a "struct variant_part" for a given variant part. RESULT
14780 is the variant part to fill in. OBSTACK is where any needed
14781 allocations will be done. OFFSET_MAP holds the mapping from
14782 section offsets to fields for the type. FI describes the fields of
14783 the type we're processing. BUILDER is the variant part to be
14787 create_one_variant_part (variant_part
&result
,
14788 struct obstack
*obstack
,
14789 const offset_map_type
&offset_map
,
14790 struct field_info
*fi
,
14791 const variant_part_builder
&builder
)
14793 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14794 if (iter
== offset_map
.end ())
14796 result
.discriminant_index
= -1;
14797 /* Doesn't matter. */
14798 result
.is_unsigned
= false;
14802 result
.discriminant_index
= iter
->second
;
14804 = TYPE_UNSIGNED (FIELD_TYPE
14805 (fi
->fields
[result
.discriminant_index
].field
));
14808 size_t n
= builder
.variants
.size ();
14809 variant
*output
= new (obstack
) variant
[n
];
14810 for (size_t i
= 0; i
< n
; ++i
)
14811 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14812 builder
.variants
[i
]);
14814 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14817 /* Create a vector of variant parts that can be attached to a type.
14818 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14819 holds the mapping from section offsets to fields for the type. FI
14820 describes the fields of the type we're processing. VARIANT_PARTS
14821 is the vector to convert. */
14823 static const gdb::array_view
<variant_part
>
14824 create_variant_parts (struct obstack
*obstack
,
14825 const offset_map_type
&offset_map
,
14826 struct field_info
*fi
,
14827 const std::vector
<variant_part_builder
> &variant_parts
)
14829 if (variant_parts
.empty ())
14832 size_t n
= variant_parts
.size ();
14833 variant_part
*result
= new (obstack
) variant_part
[n
];
14834 for (size_t i
= 0; i
< n
; ++i
)
14835 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14838 return gdb::array_view
<variant_part
> (result
, n
);
14841 /* Compute the variant part vector for FIP, attaching it to TYPE when
14845 add_variant_property (struct field_info
*fip
, struct type
*type
,
14846 struct dwarf2_cu
*cu
)
14848 /* Map section offsets of fields to their field index. Note the
14849 field index here does not take the number of baseclasses into
14851 offset_map_type offset_map
;
14852 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14853 offset_map
[fip
->fields
[i
].offset
] = i
;
14855 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14856 gdb::array_view
<variant_part
> parts
14857 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14858 fip
->variant_parts
);
14860 struct dynamic_prop prop
;
14861 prop
.kind
= PROP_VARIANT_PARTS
;
14862 prop
.data
.variant_parts
14863 = ((gdb::array_view
<variant_part
> *)
14864 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14866 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14869 /* Create the vector of fields, and attach it to the type. */
14872 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14873 struct dwarf2_cu
*cu
)
14875 int nfields
= fip
->nfields ();
14877 /* Record the field count, allocate space for the array of fields,
14878 and create blank accessibility bitfields if necessary. */
14879 type
->set_num_fields (nfields
);
14881 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14883 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14885 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14887 TYPE_FIELD_PRIVATE_BITS (type
) =
14888 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14889 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14891 TYPE_FIELD_PROTECTED_BITS (type
) =
14892 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14893 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14895 TYPE_FIELD_IGNORE_BITS (type
) =
14896 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14897 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14900 /* If the type has baseclasses, allocate and clear a bit vector for
14901 TYPE_FIELD_VIRTUAL_BITS. */
14902 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14904 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14905 unsigned char *pointer
;
14907 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14908 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14909 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14910 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14911 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14914 if (!fip
->variant_parts
.empty ())
14915 add_variant_property (fip
, type
, cu
);
14917 /* Copy the saved-up fields into the field vector. */
14918 for (int i
= 0; i
< nfields
; ++i
)
14920 struct nextfield
&field
14921 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14922 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14924 type
->field (i
) = field
.field
;
14925 switch (field
.accessibility
)
14927 case DW_ACCESS_private
:
14928 if (cu
->language
!= language_ada
)
14929 SET_TYPE_FIELD_PRIVATE (type
, i
);
14932 case DW_ACCESS_protected
:
14933 if (cu
->language
!= language_ada
)
14934 SET_TYPE_FIELD_PROTECTED (type
, i
);
14937 case DW_ACCESS_public
:
14941 /* Unknown accessibility. Complain and treat it as public. */
14943 complaint (_("unsupported accessibility %d"),
14944 field
.accessibility
);
14948 if (i
< fip
->baseclasses
.size ())
14950 switch (field
.virtuality
)
14952 case DW_VIRTUALITY_virtual
:
14953 case DW_VIRTUALITY_pure_virtual
:
14954 if (cu
->language
== language_ada
)
14955 error (_("unexpected virtuality in component of Ada type"));
14956 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14963 /* Return true if this member function is a constructor, false
14967 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14969 const char *fieldname
;
14970 const char *type_name
;
14973 if (die
->parent
== NULL
)
14976 if (die
->parent
->tag
!= DW_TAG_structure_type
14977 && die
->parent
->tag
!= DW_TAG_union_type
14978 && die
->parent
->tag
!= DW_TAG_class_type
)
14981 fieldname
= dwarf2_name (die
, cu
);
14982 type_name
= dwarf2_name (die
->parent
, cu
);
14983 if (fieldname
== NULL
|| type_name
== NULL
)
14986 len
= strlen (fieldname
);
14987 return (strncmp (fieldname
, type_name
, len
) == 0
14988 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14991 /* Check if the given VALUE is a recognized enum
14992 dwarf_defaulted_attribute constant according to DWARF5 spec,
14996 is_valid_DW_AT_defaulted (ULONGEST value
)
15000 case DW_DEFAULTED_no
:
15001 case DW_DEFAULTED_in_class
:
15002 case DW_DEFAULTED_out_of_class
:
15006 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15010 /* Add a member function to the proper fieldlist. */
15013 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15014 struct type
*type
, struct dwarf2_cu
*cu
)
15016 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15017 struct attribute
*attr
;
15019 struct fnfieldlist
*flp
= nullptr;
15020 struct fn_field
*fnp
;
15021 const char *fieldname
;
15022 struct type
*this_type
;
15023 enum dwarf_access_attribute accessibility
;
15025 if (cu
->language
== language_ada
)
15026 error (_("unexpected member function in Ada type"));
15028 /* Get name of member function. */
15029 fieldname
= dwarf2_name (die
, cu
);
15030 if (fieldname
== NULL
)
15033 /* Look up member function name in fieldlist. */
15034 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15036 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15038 flp
= &fip
->fnfieldlists
[i
];
15043 /* Create a new fnfieldlist if necessary. */
15044 if (flp
== nullptr)
15046 fip
->fnfieldlists
.emplace_back ();
15047 flp
= &fip
->fnfieldlists
.back ();
15048 flp
->name
= fieldname
;
15049 i
= fip
->fnfieldlists
.size () - 1;
15052 /* Create a new member function field and add it to the vector of
15054 flp
->fnfields
.emplace_back ();
15055 fnp
= &flp
->fnfields
.back ();
15057 /* Delay processing of the physname until later. */
15058 if (cu
->language
== language_cplus
)
15059 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15063 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15064 fnp
->physname
= physname
? physname
: "";
15067 fnp
->type
= alloc_type (objfile
);
15068 this_type
= read_type_die (die
, cu
);
15069 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15071 int nparams
= this_type
->num_fields ();
15073 /* TYPE is the domain of this method, and THIS_TYPE is the type
15074 of the method itself (TYPE_CODE_METHOD). */
15075 smash_to_method_type (fnp
->type
, type
,
15076 TYPE_TARGET_TYPE (this_type
),
15077 this_type
->fields (),
15078 this_type
->num_fields (),
15079 TYPE_VARARGS (this_type
));
15081 /* Handle static member functions.
15082 Dwarf2 has no clean way to discern C++ static and non-static
15083 member functions. G++ helps GDB by marking the first
15084 parameter for non-static member functions (which is the this
15085 pointer) as artificial. We obtain this information from
15086 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15087 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15088 fnp
->voffset
= VOFFSET_STATIC
;
15091 complaint (_("member function type missing for '%s'"),
15092 dwarf2_full_name (fieldname
, die
, cu
));
15094 /* Get fcontext from DW_AT_containing_type if present. */
15095 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15096 fnp
->fcontext
= die_containing_type (die
, cu
);
15098 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15099 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15101 /* Get accessibility. */
15102 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15103 if (attr
!= nullptr)
15104 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15106 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15107 switch (accessibility
)
15109 case DW_ACCESS_private
:
15110 fnp
->is_private
= 1;
15112 case DW_ACCESS_protected
:
15113 fnp
->is_protected
= 1;
15117 /* Check for artificial methods. */
15118 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15119 if (attr
&& DW_UNSND (attr
) != 0)
15120 fnp
->is_artificial
= 1;
15122 /* Check for defaulted methods. */
15123 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15124 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15125 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15127 /* Check for deleted methods. */
15128 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15129 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15130 fnp
->is_deleted
= 1;
15132 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15134 /* Get index in virtual function table if it is a virtual member
15135 function. For older versions of GCC, this is an offset in the
15136 appropriate virtual table, as specified by DW_AT_containing_type.
15137 For everyone else, it is an expression to be evaluated relative
15138 to the object address. */
15140 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15141 if (attr
!= nullptr)
15143 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15145 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15147 /* Old-style GCC. */
15148 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15150 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15151 || (DW_BLOCK (attr
)->size
> 1
15152 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15153 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15155 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15156 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15157 dwarf2_complex_location_expr_complaint ();
15159 fnp
->voffset
/= cu
->header
.addr_size
;
15163 dwarf2_complex_location_expr_complaint ();
15165 if (!fnp
->fcontext
)
15167 /* If there is no `this' field and no DW_AT_containing_type,
15168 we cannot actually find a base class context for the
15170 if (this_type
->num_fields () == 0
15171 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15173 complaint (_("cannot determine context for virtual member "
15174 "function \"%s\" (offset %s)"),
15175 fieldname
, sect_offset_str (die
->sect_off
));
15180 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15184 else if (attr
->form_is_section_offset ())
15186 dwarf2_complex_location_expr_complaint ();
15190 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15196 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15197 if (attr
&& DW_UNSND (attr
))
15199 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15200 complaint (_("Member function \"%s\" (offset %s) is virtual "
15201 "but the vtable offset is not specified"),
15202 fieldname
, sect_offset_str (die
->sect_off
));
15203 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15204 TYPE_CPLUS_DYNAMIC (type
) = 1;
15209 /* Create the vector of member function fields, and attach it to the type. */
15212 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15213 struct dwarf2_cu
*cu
)
15215 if (cu
->language
== language_ada
)
15216 error (_("unexpected member functions in Ada type"));
15218 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15219 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15221 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15223 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15225 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15226 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15228 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15229 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15230 fn_flp
->fn_fields
= (struct fn_field
*)
15231 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15233 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15234 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15237 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15240 /* Returns non-zero if NAME is the name of a vtable member in CU's
15241 language, zero otherwise. */
15243 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15245 static const char vptr
[] = "_vptr";
15247 /* Look for the C++ form of the vtable. */
15248 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15254 /* GCC outputs unnamed structures that are really pointers to member
15255 functions, with the ABI-specified layout. If TYPE describes
15256 such a structure, smash it into a member function type.
15258 GCC shouldn't do this; it should just output pointer to member DIEs.
15259 This is GCC PR debug/28767. */
15262 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15264 struct type
*pfn_type
, *self_type
, *new_type
;
15266 /* Check for a structure with no name and two children. */
15267 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15270 /* Check for __pfn and __delta members. */
15271 if (TYPE_FIELD_NAME (type
, 0) == NULL
15272 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15273 || TYPE_FIELD_NAME (type
, 1) == NULL
15274 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15277 /* Find the type of the method. */
15278 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15279 if (pfn_type
== NULL
15280 || pfn_type
->code () != TYPE_CODE_PTR
15281 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15284 /* Look for the "this" argument. */
15285 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15286 if (pfn_type
->num_fields () == 0
15287 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15288 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15291 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15292 new_type
= alloc_type (objfile
);
15293 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15294 pfn_type
->fields (), pfn_type
->num_fields (),
15295 TYPE_VARARGS (pfn_type
));
15296 smash_to_methodptr_type (type
, new_type
);
15299 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15300 appropriate error checking and issuing complaints if there is a
15304 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15306 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15308 if (attr
== nullptr)
15311 if (!attr
->form_is_constant ())
15313 complaint (_("DW_AT_alignment must have constant form"
15314 " - DIE at %s [in module %s]"),
15315 sect_offset_str (die
->sect_off
),
15316 objfile_name (cu
->per_objfile
->objfile
));
15321 if (attr
->form
== DW_FORM_sdata
)
15323 LONGEST val
= DW_SND (attr
);
15326 complaint (_("DW_AT_alignment value must not be negative"
15327 " - DIE at %s [in module %s]"),
15328 sect_offset_str (die
->sect_off
),
15329 objfile_name (cu
->per_objfile
->objfile
));
15335 align
= DW_UNSND (attr
);
15339 complaint (_("DW_AT_alignment value must not be zero"
15340 " - DIE at %s [in module %s]"),
15341 sect_offset_str (die
->sect_off
),
15342 objfile_name (cu
->per_objfile
->objfile
));
15345 if ((align
& (align
- 1)) != 0)
15347 complaint (_("DW_AT_alignment value must be a power of 2"
15348 " - DIE at %s [in module %s]"),
15349 sect_offset_str (die
->sect_off
),
15350 objfile_name (cu
->per_objfile
->objfile
));
15357 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15358 the alignment for TYPE. */
15361 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15364 if (!set_type_align (type
, get_alignment (cu
, die
)))
15365 complaint (_("DW_AT_alignment value too large"
15366 " - DIE at %s [in module %s]"),
15367 sect_offset_str (die
->sect_off
),
15368 objfile_name (cu
->per_objfile
->objfile
));
15371 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15372 constant for a type, according to DWARF5 spec, Table 5.5. */
15375 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15380 case DW_CC_pass_by_reference
:
15381 case DW_CC_pass_by_value
:
15385 complaint (_("unrecognized DW_AT_calling_convention value "
15386 "(%s) for a type"), pulongest (value
));
15391 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15392 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15393 also according to GNU-specific values (see include/dwarf2.h). */
15396 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15401 case DW_CC_program
:
15405 case DW_CC_GNU_renesas_sh
:
15406 case DW_CC_GNU_borland_fastcall_i386
:
15407 case DW_CC_GDB_IBM_OpenCL
:
15411 complaint (_("unrecognized DW_AT_calling_convention value "
15412 "(%s) for a subroutine"), pulongest (value
));
15417 /* Called when we find the DIE that starts a structure or union scope
15418 (definition) to create a type for the structure or union. Fill in
15419 the type's name and general properties; the members will not be
15420 processed until process_structure_scope. A symbol table entry for
15421 the type will also not be done until process_structure_scope (assuming
15422 the type has a name).
15424 NOTE: we need to call these functions regardless of whether or not the
15425 DIE has a DW_AT_name attribute, since it might be an anonymous
15426 structure or union. This gets the type entered into our set of
15427 user defined types. */
15429 static struct type
*
15430 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15432 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15434 struct attribute
*attr
;
15437 /* If the definition of this type lives in .debug_types, read that type.
15438 Don't follow DW_AT_specification though, that will take us back up
15439 the chain and we want to go down. */
15440 attr
= die
->attr (DW_AT_signature
);
15441 if (attr
!= nullptr)
15443 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15445 /* The type's CU may not be the same as CU.
15446 Ensure TYPE is recorded with CU in die_type_hash. */
15447 return set_die_type (die
, type
, cu
);
15450 type
= alloc_type (objfile
);
15451 INIT_CPLUS_SPECIFIC (type
);
15453 name
= dwarf2_name (die
, cu
);
15456 if (cu
->language
== language_cplus
15457 || cu
->language
== language_d
15458 || cu
->language
== language_rust
)
15460 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15462 /* dwarf2_full_name might have already finished building the DIE's
15463 type. If so, there is no need to continue. */
15464 if (get_die_type (die
, cu
) != NULL
)
15465 return get_die_type (die
, cu
);
15467 type
->set_name (full_name
);
15471 /* The name is already allocated along with this objfile, so
15472 we don't need to duplicate it for the type. */
15473 type
->set_name (name
);
15477 if (die
->tag
== DW_TAG_structure_type
)
15479 type
->set_code (TYPE_CODE_STRUCT
);
15481 else if (die
->tag
== DW_TAG_union_type
)
15483 type
->set_code (TYPE_CODE_UNION
);
15487 type
->set_code (TYPE_CODE_STRUCT
);
15490 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15491 TYPE_DECLARED_CLASS (type
) = 1;
15493 /* Store the calling convention in the type if it's available in
15494 the die. Otherwise the calling convention remains set to
15495 the default value DW_CC_normal. */
15496 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15497 if (attr
!= nullptr
15498 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15500 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15501 TYPE_CPLUS_CALLING_CONVENTION (type
)
15502 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15505 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15506 if (attr
!= nullptr)
15508 if (attr
->form_is_constant ())
15509 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15512 struct dynamic_prop prop
;
15513 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15514 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15515 TYPE_LENGTH (type
) = 0;
15520 TYPE_LENGTH (type
) = 0;
15523 maybe_set_alignment (cu
, die
, type
);
15525 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15527 /* ICC<14 does not output the required DW_AT_declaration on
15528 incomplete types, but gives them a size of zero. */
15529 TYPE_STUB (type
) = 1;
15532 TYPE_STUB_SUPPORTED (type
) = 1;
15534 if (die_is_declaration (die
, cu
))
15535 TYPE_STUB (type
) = 1;
15536 else if (attr
== NULL
&& die
->child
== NULL
15537 && producer_is_realview (cu
->producer
))
15538 /* RealView does not output the required DW_AT_declaration
15539 on incomplete types. */
15540 TYPE_STUB (type
) = 1;
15542 /* We need to add the type field to the die immediately so we don't
15543 infinitely recurse when dealing with pointers to the structure
15544 type within the structure itself. */
15545 set_die_type (die
, type
, cu
);
15547 /* set_die_type should be already done. */
15548 set_descriptive_type (type
, die
, cu
);
15553 static void handle_struct_member_die
15554 (struct die_info
*child_die
,
15556 struct field_info
*fi
,
15557 std::vector
<struct symbol
*> *template_args
,
15558 struct dwarf2_cu
*cu
);
15560 /* A helper for handle_struct_member_die that handles
15561 DW_TAG_variant_part. */
15564 handle_variant_part (struct die_info
*die
, struct type
*type
,
15565 struct field_info
*fi
,
15566 std::vector
<struct symbol
*> *template_args
,
15567 struct dwarf2_cu
*cu
)
15569 variant_part_builder
*new_part
;
15570 if (fi
->current_variant_part
== nullptr)
15572 fi
->variant_parts
.emplace_back ();
15573 new_part
= &fi
->variant_parts
.back ();
15575 else if (!fi
->current_variant_part
->processing_variant
)
15577 complaint (_("nested DW_TAG_variant_part seen "
15578 "- DIE at %s [in module %s]"),
15579 sect_offset_str (die
->sect_off
),
15580 objfile_name (cu
->per_objfile
->objfile
));
15585 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15586 current
.variant_parts
.emplace_back ();
15587 new_part
= ¤t
.variant_parts
.back ();
15590 /* When we recurse, we want callees to add to this new variant
15592 scoped_restore save_current_variant_part
15593 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15595 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15598 /* It's a univariant form, an extension we support. */
15600 else if (discr
->form_is_ref ())
15602 struct dwarf2_cu
*target_cu
= cu
;
15603 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15605 new_part
->discriminant_offset
= target_die
->sect_off
;
15609 complaint (_("DW_AT_discr does not have DIE reference form"
15610 " - DIE at %s [in module %s]"),
15611 sect_offset_str (die
->sect_off
),
15612 objfile_name (cu
->per_objfile
->objfile
));
15615 for (die_info
*child_die
= die
->child
;
15617 child_die
= child_die
->sibling
)
15618 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15621 /* A helper for handle_struct_member_die that handles
15625 handle_variant (struct die_info
*die
, struct type
*type
,
15626 struct field_info
*fi
,
15627 std::vector
<struct symbol
*> *template_args
,
15628 struct dwarf2_cu
*cu
)
15630 if (fi
->current_variant_part
== nullptr)
15632 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15633 "- DIE at %s [in module %s]"),
15634 sect_offset_str (die
->sect_off
),
15635 objfile_name (cu
->per_objfile
->objfile
));
15638 if (fi
->current_variant_part
->processing_variant
)
15640 complaint (_("nested DW_TAG_variant seen "
15641 "- DIE at %s [in module %s]"),
15642 sect_offset_str (die
->sect_off
),
15643 objfile_name (cu
->per_objfile
->objfile
));
15647 scoped_restore save_processing_variant
15648 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15651 fi
->current_variant_part
->variants
.emplace_back ();
15652 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15653 variant
.first_field
= fi
->fields
.size ();
15655 /* In a variant we want to get the discriminant and also add a
15656 field for our sole member child. */
15657 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15658 if (discr
== nullptr)
15660 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15661 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15662 variant
.default_branch
= true;
15664 variant
.discr_list_data
= DW_BLOCK (discr
);
15667 variant
.discriminant_value
= DW_UNSND (discr
);
15669 for (die_info
*variant_child
= die
->child
;
15670 variant_child
!= NULL
;
15671 variant_child
= variant_child
->sibling
)
15672 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15674 variant
.last_field
= fi
->fields
.size ();
15677 /* A helper for process_structure_scope that handles a single member
15681 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15682 struct field_info
*fi
,
15683 std::vector
<struct symbol
*> *template_args
,
15684 struct dwarf2_cu
*cu
)
15686 if (child_die
->tag
== DW_TAG_member
15687 || child_die
->tag
== DW_TAG_variable
)
15689 /* NOTE: carlton/2002-11-05: A C++ static data member
15690 should be a DW_TAG_member that is a declaration, but
15691 all versions of G++ as of this writing (so through at
15692 least 3.2.1) incorrectly generate DW_TAG_variable
15693 tags for them instead. */
15694 dwarf2_add_field (fi
, child_die
, cu
);
15696 else if (child_die
->tag
== DW_TAG_subprogram
)
15698 /* Rust doesn't have member functions in the C++ sense.
15699 However, it does emit ordinary functions as children
15700 of a struct DIE. */
15701 if (cu
->language
== language_rust
)
15702 read_func_scope (child_die
, cu
);
15705 /* C++ member function. */
15706 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15709 else if (child_die
->tag
== DW_TAG_inheritance
)
15711 /* C++ base class field. */
15712 dwarf2_add_field (fi
, child_die
, cu
);
15714 else if (type_can_define_types (child_die
))
15715 dwarf2_add_type_defn (fi
, child_die
, cu
);
15716 else if (child_die
->tag
== DW_TAG_template_type_param
15717 || child_die
->tag
== DW_TAG_template_value_param
)
15719 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15722 template_args
->push_back (arg
);
15724 else if (child_die
->tag
== DW_TAG_variant_part
)
15725 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15726 else if (child_die
->tag
== DW_TAG_variant
)
15727 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15730 /* Finish creating a structure or union type, including filling in
15731 its members and creating a symbol for it. */
15734 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15736 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15737 struct die_info
*child_die
;
15740 type
= get_die_type (die
, cu
);
15742 type
= read_structure_type (die
, cu
);
15744 bool has_template_parameters
= false;
15745 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15747 struct field_info fi
;
15748 std::vector
<struct symbol
*> template_args
;
15750 child_die
= die
->child
;
15752 while (child_die
&& child_die
->tag
)
15754 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15755 child_die
= child_die
->sibling
;
15758 /* Attach template arguments to type. */
15759 if (!template_args
.empty ())
15761 has_template_parameters
= true;
15762 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15763 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15764 TYPE_TEMPLATE_ARGUMENTS (type
)
15765 = XOBNEWVEC (&objfile
->objfile_obstack
,
15767 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15768 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15769 template_args
.data (),
15770 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15771 * sizeof (struct symbol
*)));
15774 /* Attach fields and member functions to the type. */
15775 if (fi
.nfields () > 0)
15776 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15777 if (!fi
.fnfieldlists
.empty ())
15779 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15781 /* Get the type which refers to the base class (possibly this
15782 class itself) which contains the vtable pointer for the current
15783 class from the DW_AT_containing_type attribute. This use of
15784 DW_AT_containing_type is a GNU extension. */
15786 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15788 struct type
*t
= die_containing_type (die
, cu
);
15790 set_type_vptr_basetype (type
, t
);
15795 /* Our own class provides vtbl ptr. */
15796 for (i
= t
->num_fields () - 1;
15797 i
>= TYPE_N_BASECLASSES (t
);
15800 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15802 if (is_vtable_name (fieldname
, cu
))
15804 set_type_vptr_fieldno (type
, i
);
15809 /* Complain if virtual function table field not found. */
15810 if (i
< TYPE_N_BASECLASSES (t
))
15811 complaint (_("virtual function table pointer "
15812 "not found when defining class '%s'"),
15813 type
->name () ? type
->name () : "");
15817 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15820 else if (cu
->producer
15821 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15823 /* The IBM XLC compiler does not provide direct indication
15824 of the containing type, but the vtable pointer is
15825 always named __vfp. */
15829 for (i
= type
->num_fields () - 1;
15830 i
>= TYPE_N_BASECLASSES (type
);
15833 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15835 set_type_vptr_fieldno (type
, i
);
15836 set_type_vptr_basetype (type
, type
);
15843 /* Copy fi.typedef_field_list linked list elements content into the
15844 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15845 if (!fi
.typedef_field_list
.empty ())
15847 int count
= fi
.typedef_field_list
.size ();
15849 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15850 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15851 = ((struct decl_field
*)
15853 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15854 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15856 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15857 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15860 /* Copy fi.nested_types_list linked list elements content into the
15861 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15862 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15864 int count
= fi
.nested_types_list
.size ();
15866 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15867 TYPE_NESTED_TYPES_ARRAY (type
)
15868 = ((struct decl_field
*)
15869 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15870 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15872 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15873 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15877 quirk_gcc_member_function_pointer (type
, objfile
);
15878 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15879 cu
->rust_unions
.push_back (type
);
15881 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15882 snapshots) has been known to create a die giving a declaration
15883 for a class that has, as a child, a die giving a definition for a
15884 nested class. So we have to process our children even if the
15885 current die is a declaration. Normally, of course, a declaration
15886 won't have any children at all. */
15888 child_die
= die
->child
;
15890 while (child_die
!= NULL
&& child_die
->tag
)
15892 if (child_die
->tag
== DW_TAG_member
15893 || child_die
->tag
== DW_TAG_variable
15894 || child_die
->tag
== DW_TAG_inheritance
15895 || child_die
->tag
== DW_TAG_template_value_param
15896 || child_die
->tag
== DW_TAG_template_type_param
)
15901 process_die (child_die
, cu
);
15903 child_die
= child_die
->sibling
;
15906 /* Do not consider external references. According to the DWARF standard,
15907 these DIEs are identified by the fact that they have no byte_size
15908 attribute, and a declaration attribute. */
15909 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15910 || !die_is_declaration (die
, cu
)
15911 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15913 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15915 if (has_template_parameters
)
15917 struct symtab
*symtab
;
15918 if (sym
!= nullptr)
15919 symtab
= symbol_symtab (sym
);
15920 else if (cu
->line_header
!= nullptr)
15922 /* Any related symtab will do. */
15924 = cu
->line_header
->file_names ()[0].symtab
;
15929 complaint (_("could not find suitable "
15930 "symtab for template parameter"
15931 " - DIE at %s [in module %s]"),
15932 sect_offset_str (die
->sect_off
),
15933 objfile_name (objfile
));
15936 if (symtab
!= nullptr)
15938 /* Make sure that the symtab is set on the new symbols.
15939 Even though they don't appear in this symtab directly,
15940 other parts of gdb assume that symbols do, and this is
15941 reasonably true. */
15942 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15943 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15949 /* Assuming DIE is an enumeration type, and TYPE is its associated
15950 type, update TYPE using some information only available in DIE's
15951 children. In particular, the fields are computed. */
15954 update_enumeration_type_from_children (struct die_info
*die
,
15956 struct dwarf2_cu
*cu
)
15958 struct die_info
*child_die
;
15959 int unsigned_enum
= 1;
15962 auto_obstack obstack
;
15963 std::vector
<struct field
> fields
;
15965 for (child_die
= die
->child
;
15966 child_die
!= NULL
&& child_die
->tag
;
15967 child_die
= child_die
->sibling
)
15969 struct attribute
*attr
;
15971 const gdb_byte
*bytes
;
15972 struct dwarf2_locexpr_baton
*baton
;
15975 if (child_die
->tag
!= DW_TAG_enumerator
)
15978 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15982 name
= dwarf2_name (child_die
, cu
);
15984 name
= "<anonymous enumerator>";
15986 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15987 &value
, &bytes
, &baton
);
15995 if (count_one_bits_ll (value
) >= 2)
15999 fields
.emplace_back ();
16000 struct field
&field
= fields
.back ();
16001 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16002 SET_FIELD_ENUMVAL (field
, value
);
16005 if (!fields
.empty ())
16007 type
->set_num_fields (fields
.size ());
16010 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16011 memcpy (type
->fields (), fields
.data (),
16012 sizeof (struct field
) * fields
.size ());
16016 TYPE_UNSIGNED (type
) = 1;
16018 TYPE_FLAG_ENUM (type
) = 1;
16021 /* Given a DW_AT_enumeration_type die, set its type. We do not
16022 complete the type's fields yet, or create any symbols. */
16024 static struct type
*
16025 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16027 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16029 struct attribute
*attr
;
16032 /* If the definition of this type lives in .debug_types, read that type.
16033 Don't follow DW_AT_specification though, that will take us back up
16034 the chain and we want to go down. */
16035 attr
= die
->attr (DW_AT_signature
);
16036 if (attr
!= nullptr)
16038 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16040 /* The type's CU may not be the same as CU.
16041 Ensure TYPE is recorded with CU in die_type_hash. */
16042 return set_die_type (die
, type
, cu
);
16045 type
= alloc_type (objfile
);
16047 type
->set_code (TYPE_CODE_ENUM
);
16048 name
= dwarf2_full_name (NULL
, die
, cu
);
16050 type
->set_name (name
);
16052 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16055 struct type
*underlying_type
= die_type (die
, cu
);
16057 TYPE_TARGET_TYPE (type
) = underlying_type
;
16060 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16061 if (attr
!= nullptr)
16063 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16067 TYPE_LENGTH (type
) = 0;
16070 maybe_set_alignment (cu
, die
, type
);
16072 /* The enumeration DIE can be incomplete. In Ada, any type can be
16073 declared as private in the package spec, and then defined only
16074 inside the package body. Such types are known as Taft Amendment
16075 Types. When another package uses such a type, an incomplete DIE
16076 may be generated by the compiler. */
16077 if (die_is_declaration (die
, cu
))
16078 TYPE_STUB (type
) = 1;
16080 /* If this type has an underlying type that is not a stub, then we
16081 may use its attributes. We always use the "unsigned" attribute
16082 in this situation, because ordinarily we guess whether the type
16083 is unsigned -- but the guess can be wrong and the underlying type
16084 can tell us the reality. However, we defer to a local size
16085 attribute if one exists, because this lets the compiler override
16086 the underlying type if needed. */
16087 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16089 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16090 underlying_type
= check_typedef (underlying_type
);
16091 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16092 if (TYPE_LENGTH (type
) == 0)
16093 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16094 if (TYPE_RAW_ALIGN (type
) == 0
16095 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16096 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16099 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16101 set_die_type (die
, type
, cu
);
16103 /* Finish the creation of this type by using the enum's children.
16104 Note that, as usual, this must come after set_die_type to avoid
16105 infinite recursion when trying to compute the names of the
16107 update_enumeration_type_from_children (die
, type
, cu
);
16112 /* Given a pointer to a die which begins an enumeration, process all
16113 the dies that define the members of the enumeration, and create the
16114 symbol for the enumeration type.
16116 NOTE: We reverse the order of the element list. */
16119 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16121 struct type
*this_type
;
16123 this_type
= get_die_type (die
, cu
);
16124 if (this_type
== NULL
)
16125 this_type
= read_enumeration_type (die
, cu
);
16127 if (die
->child
!= NULL
)
16129 struct die_info
*child_die
;
16132 child_die
= die
->child
;
16133 while (child_die
&& child_die
->tag
)
16135 if (child_die
->tag
!= DW_TAG_enumerator
)
16137 process_die (child_die
, cu
);
16141 name
= dwarf2_name (child_die
, cu
);
16143 new_symbol (child_die
, this_type
, cu
);
16146 child_die
= child_die
->sibling
;
16150 /* If we are reading an enum from a .debug_types unit, and the enum
16151 is a declaration, and the enum is not the signatured type in the
16152 unit, then we do not want to add a symbol for it. Adding a
16153 symbol would in some cases obscure the true definition of the
16154 enum, giving users an incomplete type when the definition is
16155 actually available. Note that we do not want to do this for all
16156 enums which are just declarations, because C++0x allows forward
16157 enum declarations. */
16158 if (cu
->per_cu
->is_debug_types
16159 && die_is_declaration (die
, cu
))
16161 struct signatured_type
*sig_type
;
16163 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16164 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16165 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16169 new_symbol (die
, this_type
, cu
);
16172 /* Extract all information from a DW_TAG_array_type DIE and put it in
16173 the DIE's type field. For now, this only handles one dimensional
16176 static struct type
*
16177 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16179 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16180 struct die_info
*child_die
;
16182 struct type
*element_type
, *range_type
, *index_type
;
16183 struct attribute
*attr
;
16185 struct dynamic_prop
*byte_stride_prop
= NULL
;
16186 unsigned int bit_stride
= 0;
16188 element_type
= die_type (die
, cu
);
16190 /* The die_type call above may have already set the type for this DIE. */
16191 type
= get_die_type (die
, cu
);
16195 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16199 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16202 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16203 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16207 complaint (_("unable to read array DW_AT_byte_stride "
16208 " - DIE at %s [in module %s]"),
16209 sect_offset_str (die
->sect_off
),
16210 objfile_name (cu
->per_objfile
->objfile
));
16211 /* Ignore this attribute. We will likely not be able to print
16212 arrays of this type correctly, but there is little we can do
16213 to help if we cannot read the attribute's value. */
16214 byte_stride_prop
= NULL
;
16218 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16220 bit_stride
= DW_UNSND (attr
);
16222 /* Irix 6.2 native cc creates array types without children for
16223 arrays with unspecified length. */
16224 if (die
->child
== NULL
)
16226 index_type
= objfile_type (objfile
)->builtin_int
;
16227 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16228 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16229 byte_stride_prop
, bit_stride
);
16230 return set_die_type (die
, type
, cu
);
16233 std::vector
<struct type
*> range_types
;
16234 child_die
= die
->child
;
16235 while (child_die
&& child_die
->tag
)
16237 if (child_die
->tag
== DW_TAG_subrange_type
)
16239 struct type
*child_type
= read_type_die (child_die
, cu
);
16241 if (child_type
!= NULL
)
16243 /* The range type was succesfully read. Save it for the
16244 array type creation. */
16245 range_types
.push_back (child_type
);
16248 child_die
= child_die
->sibling
;
16251 /* Dwarf2 dimensions are output from left to right, create the
16252 necessary array types in backwards order. */
16254 type
= element_type
;
16256 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16260 while (i
< range_types
.size ())
16261 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16262 byte_stride_prop
, bit_stride
);
16266 size_t ndim
= range_types
.size ();
16268 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16269 byte_stride_prop
, bit_stride
);
16272 /* Understand Dwarf2 support for vector types (like they occur on
16273 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16274 array type. This is not part of the Dwarf2/3 standard yet, but a
16275 custom vendor extension. The main difference between a regular
16276 array and the vector variant is that vectors are passed by value
16278 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16279 if (attr
!= nullptr)
16280 make_vector_type (type
);
16282 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16283 implementation may choose to implement triple vectors using this
16285 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16286 if (attr
!= nullptr)
16288 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16289 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16291 complaint (_("DW_AT_byte_size for array type smaller "
16292 "than the total size of elements"));
16295 name
= dwarf2_name (die
, cu
);
16297 type
->set_name (name
);
16299 maybe_set_alignment (cu
, die
, type
);
16301 /* Install the type in the die. */
16302 set_die_type (die
, type
, cu
);
16304 /* set_die_type should be already done. */
16305 set_descriptive_type (type
, die
, cu
);
16310 static enum dwarf_array_dim_ordering
16311 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16313 struct attribute
*attr
;
16315 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16317 if (attr
!= nullptr)
16318 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16320 /* GNU F77 is a special case, as at 08/2004 array type info is the
16321 opposite order to the dwarf2 specification, but data is still
16322 laid out as per normal fortran.
16324 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16325 version checking. */
16327 if (cu
->language
== language_fortran
16328 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16330 return DW_ORD_row_major
;
16333 switch (cu
->language_defn
->la_array_ordering
)
16335 case array_column_major
:
16336 return DW_ORD_col_major
;
16337 case array_row_major
:
16339 return DW_ORD_row_major
;
16343 /* Extract all information from a DW_TAG_set_type DIE and put it in
16344 the DIE's type field. */
16346 static struct type
*
16347 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16349 struct type
*domain_type
, *set_type
;
16350 struct attribute
*attr
;
16352 domain_type
= die_type (die
, cu
);
16354 /* The die_type call above may have already set the type for this DIE. */
16355 set_type
= get_die_type (die
, cu
);
16359 set_type
= create_set_type (NULL
, domain_type
);
16361 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16362 if (attr
!= nullptr)
16363 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16365 maybe_set_alignment (cu
, die
, set_type
);
16367 return set_die_type (die
, set_type
, cu
);
16370 /* A helper for read_common_block that creates a locexpr baton.
16371 SYM is the symbol which we are marking as computed.
16372 COMMON_DIE is the DIE for the common block.
16373 COMMON_LOC is the location expression attribute for the common
16375 MEMBER_LOC is the location expression attribute for the particular
16376 member of the common block that we are processing.
16377 CU is the CU from which the above come. */
16380 mark_common_block_symbol_computed (struct symbol
*sym
,
16381 struct die_info
*common_die
,
16382 struct attribute
*common_loc
,
16383 struct attribute
*member_loc
,
16384 struct dwarf2_cu
*cu
)
16386 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16387 struct objfile
*objfile
= per_objfile
->objfile
;
16388 struct dwarf2_locexpr_baton
*baton
;
16390 unsigned int cu_off
;
16391 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16392 LONGEST offset
= 0;
16394 gdb_assert (common_loc
&& member_loc
);
16395 gdb_assert (common_loc
->form_is_block ());
16396 gdb_assert (member_loc
->form_is_block ()
16397 || member_loc
->form_is_constant ());
16399 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16400 baton
->per_objfile
= per_objfile
;
16401 baton
->per_cu
= cu
->per_cu
;
16402 gdb_assert (baton
->per_cu
);
16404 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16406 if (member_loc
->form_is_constant ())
16408 offset
= member_loc
->constant_value (0);
16409 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16412 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16414 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16417 *ptr
++ = DW_OP_call4
;
16418 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16419 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16422 if (member_loc
->form_is_constant ())
16424 *ptr
++ = DW_OP_addr
;
16425 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16426 ptr
+= cu
->header
.addr_size
;
16430 /* We have to copy the data here, because DW_OP_call4 will only
16431 use a DW_AT_location attribute. */
16432 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16433 ptr
+= DW_BLOCK (member_loc
)->size
;
16436 *ptr
++ = DW_OP_plus
;
16437 gdb_assert (ptr
- baton
->data
== baton
->size
);
16439 SYMBOL_LOCATION_BATON (sym
) = baton
;
16440 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16443 /* Create appropriate locally-scoped variables for all the
16444 DW_TAG_common_block entries. Also create a struct common_block
16445 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16446 is used to separate the common blocks name namespace from regular
16450 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16452 struct attribute
*attr
;
16454 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16455 if (attr
!= nullptr)
16457 /* Support the .debug_loc offsets. */
16458 if (attr
->form_is_block ())
16462 else if (attr
->form_is_section_offset ())
16464 dwarf2_complex_location_expr_complaint ();
16469 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16470 "common block member");
16475 if (die
->child
!= NULL
)
16477 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16478 struct die_info
*child_die
;
16479 size_t n_entries
= 0, size
;
16480 struct common_block
*common_block
;
16481 struct symbol
*sym
;
16483 for (child_die
= die
->child
;
16484 child_die
&& child_die
->tag
;
16485 child_die
= child_die
->sibling
)
16488 size
= (sizeof (struct common_block
)
16489 + (n_entries
- 1) * sizeof (struct symbol
*));
16491 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16493 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16494 common_block
->n_entries
= 0;
16496 for (child_die
= die
->child
;
16497 child_die
&& child_die
->tag
;
16498 child_die
= child_die
->sibling
)
16500 /* Create the symbol in the DW_TAG_common_block block in the current
16502 sym
= new_symbol (child_die
, NULL
, cu
);
16505 struct attribute
*member_loc
;
16507 common_block
->contents
[common_block
->n_entries
++] = sym
;
16509 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16513 /* GDB has handled this for a long time, but it is
16514 not specified by DWARF. It seems to have been
16515 emitted by gfortran at least as recently as:
16516 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16517 complaint (_("Variable in common block has "
16518 "DW_AT_data_member_location "
16519 "- DIE at %s [in module %s]"),
16520 sect_offset_str (child_die
->sect_off
),
16521 objfile_name (objfile
));
16523 if (member_loc
->form_is_section_offset ())
16524 dwarf2_complex_location_expr_complaint ();
16525 else if (member_loc
->form_is_constant ()
16526 || member_loc
->form_is_block ())
16528 if (attr
!= nullptr)
16529 mark_common_block_symbol_computed (sym
, die
, attr
,
16533 dwarf2_complex_location_expr_complaint ();
16538 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16539 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16543 /* Create a type for a C++ namespace. */
16545 static struct type
*
16546 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16548 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16549 const char *previous_prefix
, *name
;
16553 /* For extensions, reuse the type of the original namespace. */
16554 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16556 struct die_info
*ext_die
;
16557 struct dwarf2_cu
*ext_cu
= cu
;
16559 ext_die
= dwarf2_extension (die
, &ext_cu
);
16560 type
= read_type_die (ext_die
, ext_cu
);
16562 /* EXT_CU may not be the same as CU.
16563 Ensure TYPE is recorded with CU in die_type_hash. */
16564 return set_die_type (die
, type
, cu
);
16567 name
= namespace_name (die
, &is_anonymous
, cu
);
16569 /* Now build the name of the current namespace. */
16571 previous_prefix
= determine_prefix (die
, cu
);
16572 if (previous_prefix
[0] != '\0')
16573 name
= typename_concat (&objfile
->objfile_obstack
,
16574 previous_prefix
, name
, 0, cu
);
16576 /* Create the type. */
16577 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16579 return set_die_type (die
, type
, cu
);
16582 /* Read a namespace scope. */
16585 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16587 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16590 /* Add a symbol associated to this if we haven't seen the namespace
16591 before. Also, add a using directive if it's an anonymous
16594 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16598 type
= read_type_die (die
, cu
);
16599 new_symbol (die
, type
, cu
);
16601 namespace_name (die
, &is_anonymous
, cu
);
16604 const char *previous_prefix
= determine_prefix (die
, cu
);
16606 std::vector
<const char *> excludes
;
16607 add_using_directive (using_directives (cu
),
16608 previous_prefix
, type
->name (), NULL
,
16609 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16613 if (die
->child
!= NULL
)
16615 struct die_info
*child_die
= die
->child
;
16617 while (child_die
&& child_die
->tag
)
16619 process_die (child_die
, cu
);
16620 child_die
= child_die
->sibling
;
16625 /* Read a Fortran module as type. This DIE can be only a declaration used for
16626 imported module. Still we need that type as local Fortran "use ... only"
16627 declaration imports depend on the created type in determine_prefix. */
16629 static struct type
*
16630 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16632 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16633 const char *module_name
;
16636 module_name
= dwarf2_name (die
, cu
);
16637 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16639 return set_die_type (die
, type
, cu
);
16642 /* Read a Fortran module. */
16645 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16647 struct die_info
*child_die
= die
->child
;
16650 type
= read_type_die (die
, cu
);
16651 new_symbol (die
, type
, cu
);
16653 while (child_die
&& child_die
->tag
)
16655 process_die (child_die
, cu
);
16656 child_die
= child_die
->sibling
;
16660 /* Return the name of the namespace represented by DIE. Set
16661 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16664 static const char *
16665 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16667 struct die_info
*current_die
;
16668 const char *name
= NULL
;
16670 /* Loop through the extensions until we find a name. */
16672 for (current_die
= die
;
16673 current_die
!= NULL
;
16674 current_die
= dwarf2_extension (die
, &cu
))
16676 /* We don't use dwarf2_name here so that we can detect the absence
16677 of a name -> anonymous namespace. */
16678 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16684 /* Is it an anonymous namespace? */
16686 *is_anonymous
= (name
== NULL
);
16688 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16693 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16694 the user defined type vector. */
16696 static struct type
*
16697 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16699 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16700 struct comp_unit_head
*cu_header
= &cu
->header
;
16702 struct attribute
*attr_byte_size
;
16703 struct attribute
*attr_address_class
;
16704 int byte_size
, addr_class
;
16705 struct type
*target_type
;
16707 target_type
= die_type (die
, cu
);
16709 /* The die_type call above may have already set the type for this DIE. */
16710 type
= get_die_type (die
, cu
);
16714 type
= lookup_pointer_type (target_type
);
16716 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16717 if (attr_byte_size
)
16718 byte_size
= DW_UNSND (attr_byte_size
);
16720 byte_size
= cu_header
->addr_size
;
16722 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16723 if (attr_address_class
)
16724 addr_class
= DW_UNSND (attr_address_class
);
16726 addr_class
= DW_ADDR_none
;
16728 ULONGEST alignment
= get_alignment (cu
, die
);
16730 /* If the pointer size, alignment, or address class is different
16731 than the default, create a type variant marked as such and set
16732 the length accordingly. */
16733 if (TYPE_LENGTH (type
) != byte_size
16734 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16735 && alignment
!= TYPE_RAW_ALIGN (type
))
16736 || addr_class
!= DW_ADDR_none
)
16738 if (gdbarch_address_class_type_flags_p (gdbarch
))
16742 type_flags
= gdbarch_address_class_type_flags
16743 (gdbarch
, byte_size
, addr_class
);
16744 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16746 type
= make_type_with_address_space (type
, type_flags
);
16748 else if (TYPE_LENGTH (type
) != byte_size
)
16750 complaint (_("invalid pointer size %d"), byte_size
);
16752 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16754 complaint (_("Invalid DW_AT_alignment"
16755 " - DIE at %s [in module %s]"),
16756 sect_offset_str (die
->sect_off
),
16757 objfile_name (cu
->per_objfile
->objfile
));
16761 /* Should we also complain about unhandled address classes? */
16765 TYPE_LENGTH (type
) = byte_size
;
16766 set_type_align (type
, alignment
);
16767 return set_die_type (die
, type
, cu
);
16770 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16771 the user defined type vector. */
16773 static struct type
*
16774 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16777 struct type
*to_type
;
16778 struct type
*domain
;
16780 to_type
= die_type (die
, cu
);
16781 domain
= die_containing_type (die
, cu
);
16783 /* The calls above may have already set the type for this DIE. */
16784 type
= get_die_type (die
, cu
);
16788 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16789 type
= lookup_methodptr_type (to_type
);
16790 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16792 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16794 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16795 to_type
->fields (), to_type
->num_fields (),
16796 TYPE_VARARGS (to_type
));
16797 type
= lookup_methodptr_type (new_type
);
16800 type
= lookup_memberptr_type (to_type
, domain
);
16802 return set_die_type (die
, type
, cu
);
16805 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16806 the user defined type vector. */
16808 static struct type
*
16809 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16810 enum type_code refcode
)
16812 struct comp_unit_head
*cu_header
= &cu
->header
;
16813 struct type
*type
, *target_type
;
16814 struct attribute
*attr
;
16816 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16818 target_type
= die_type (die
, cu
);
16820 /* The die_type call above may have already set the type for this DIE. */
16821 type
= get_die_type (die
, cu
);
16825 type
= lookup_reference_type (target_type
, refcode
);
16826 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16827 if (attr
!= nullptr)
16829 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16833 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16835 maybe_set_alignment (cu
, die
, type
);
16836 return set_die_type (die
, type
, cu
);
16839 /* Add the given cv-qualifiers to the element type of the array. GCC
16840 outputs DWARF type qualifiers that apply to an array, not the
16841 element type. But GDB relies on the array element type to carry
16842 the cv-qualifiers. This mimics section 6.7.3 of the C99
16845 static struct type
*
16846 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16847 struct type
*base_type
, int cnst
, int voltl
)
16849 struct type
*el_type
, *inner_array
;
16851 base_type
= copy_type (base_type
);
16852 inner_array
= base_type
;
16854 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16856 TYPE_TARGET_TYPE (inner_array
) =
16857 copy_type (TYPE_TARGET_TYPE (inner_array
));
16858 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16861 el_type
= TYPE_TARGET_TYPE (inner_array
);
16862 cnst
|= TYPE_CONST (el_type
);
16863 voltl
|= TYPE_VOLATILE (el_type
);
16864 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16866 return set_die_type (die
, base_type
, cu
);
16869 static struct type
*
16870 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16872 struct type
*base_type
, *cv_type
;
16874 base_type
= die_type (die
, cu
);
16876 /* The die_type call above may have already set the type for this DIE. */
16877 cv_type
= get_die_type (die
, cu
);
16881 /* In case the const qualifier is applied to an array type, the element type
16882 is so qualified, not the array type (section 6.7.3 of C99). */
16883 if (base_type
->code () == TYPE_CODE_ARRAY
)
16884 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16886 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16887 return set_die_type (die
, cv_type
, cu
);
16890 static struct type
*
16891 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16893 struct type
*base_type
, *cv_type
;
16895 base_type
= die_type (die
, cu
);
16897 /* The die_type call above may have already set the type for this DIE. */
16898 cv_type
= get_die_type (die
, cu
);
16902 /* In case the volatile qualifier is applied to an array type, the
16903 element type is so qualified, not the array type (section 6.7.3
16905 if (base_type
->code () == TYPE_CODE_ARRAY
)
16906 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16908 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16909 return set_die_type (die
, cv_type
, cu
);
16912 /* Handle DW_TAG_restrict_type. */
16914 static struct type
*
16915 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16917 struct type
*base_type
, *cv_type
;
16919 base_type
= die_type (die
, cu
);
16921 /* The die_type call above may have already set the type for this DIE. */
16922 cv_type
= get_die_type (die
, cu
);
16926 cv_type
= make_restrict_type (base_type
);
16927 return set_die_type (die
, cv_type
, cu
);
16930 /* Handle DW_TAG_atomic_type. */
16932 static struct type
*
16933 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16935 struct type
*base_type
, *cv_type
;
16937 base_type
= die_type (die
, cu
);
16939 /* The die_type call above may have already set the type for this DIE. */
16940 cv_type
= get_die_type (die
, cu
);
16944 cv_type
= make_atomic_type (base_type
);
16945 return set_die_type (die
, cv_type
, cu
);
16948 /* Extract all information from a DW_TAG_string_type DIE and add to
16949 the user defined type vector. It isn't really a user defined type,
16950 but it behaves like one, with other DIE's using an AT_user_def_type
16951 attribute to reference it. */
16953 static struct type
*
16954 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16956 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16957 struct gdbarch
*gdbarch
= objfile
->arch ();
16958 struct type
*type
, *range_type
, *index_type
, *char_type
;
16959 struct attribute
*attr
;
16960 struct dynamic_prop prop
;
16961 bool length_is_constant
= true;
16964 /* There are a couple of places where bit sizes might be made use of
16965 when parsing a DW_TAG_string_type, however, no producer that we know
16966 of make use of these. Handling bit sizes that are a multiple of the
16967 byte size is easy enough, but what about other bit sizes? Lets deal
16968 with that problem when we have to. Warn about these attributes being
16969 unsupported, then parse the type and ignore them like we always
16971 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16972 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16974 static bool warning_printed
= false;
16975 if (!warning_printed
)
16977 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16978 "currently supported on DW_TAG_string_type."));
16979 warning_printed
= true;
16983 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16984 if (attr
!= nullptr && !attr
->form_is_constant ())
16986 /* The string length describes the location at which the length of
16987 the string can be found. The size of the length field can be
16988 specified with one of the attributes below. */
16989 struct type
*prop_type
;
16990 struct attribute
*len
16991 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16992 if (len
== nullptr)
16993 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16994 if (len
!= nullptr && len
->form_is_constant ())
16996 /* Pass 0 as the default as we know this attribute is constant
16997 and the default value will not be returned. */
16998 LONGEST sz
= len
->constant_value (0);
16999 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17003 /* If the size is not specified then we assume it is the size of
17004 an address on this target. */
17005 prop_type
= cu
->addr_sized_int_type (true);
17008 /* Convert the attribute into a dynamic property. */
17009 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17012 length_is_constant
= false;
17014 else if (attr
!= nullptr)
17016 /* This DW_AT_string_length just contains the length with no
17017 indirection. There's no need to create a dynamic property in this
17018 case. Pass 0 for the default value as we know it will not be
17019 returned in this case. */
17020 length
= attr
->constant_value (0);
17022 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17024 /* We don't currently support non-constant byte sizes for strings. */
17025 length
= attr
->constant_value (1);
17029 /* Use 1 as a fallback length if we have nothing else. */
17033 index_type
= objfile_type (objfile
)->builtin_int
;
17034 if (length_is_constant
)
17035 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17038 struct dynamic_prop low_bound
;
17040 low_bound
.kind
= PROP_CONST
;
17041 low_bound
.data
.const_val
= 1;
17042 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17044 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17045 type
= create_string_type (NULL
, char_type
, range_type
);
17047 return set_die_type (die
, type
, cu
);
17050 /* Assuming that DIE corresponds to a function, returns nonzero
17051 if the function is prototyped. */
17054 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17056 struct attribute
*attr
;
17058 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17059 if (attr
&& (DW_UNSND (attr
) != 0))
17062 /* The DWARF standard implies that the DW_AT_prototyped attribute
17063 is only meaningful for C, but the concept also extends to other
17064 languages that allow unprototyped functions (Eg: Objective C).
17065 For all other languages, assume that functions are always
17067 if (cu
->language
!= language_c
17068 && cu
->language
!= language_objc
17069 && cu
->language
!= language_opencl
)
17072 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17073 prototyped and unprototyped functions; default to prototyped,
17074 since that is more common in modern code (and RealView warns
17075 about unprototyped functions). */
17076 if (producer_is_realview (cu
->producer
))
17082 /* Handle DIES due to C code like:
17086 int (*funcp)(int a, long l);
17090 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17092 static struct type
*
17093 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17095 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17096 struct type
*type
; /* Type that this function returns. */
17097 struct type
*ftype
; /* Function that returns above type. */
17098 struct attribute
*attr
;
17100 type
= die_type (die
, cu
);
17102 /* The die_type call above may have already set the type for this DIE. */
17103 ftype
= get_die_type (die
, cu
);
17107 ftype
= lookup_function_type (type
);
17109 if (prototyped_function_p (die
, cu
))
17110 TYPE_PROTOTYPED (ftype
) = 1;
17112 /* Store the calling convention in the type if it's available in
17113 the subroutine die. Otherwise set the calling convention to
17114 the default value DW_CC_normal. */
17115 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17116 if (attr
!= nullptr
17117 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17118 TYPE_CALLING_CONVENTION (ftype
)
17119 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17120 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17121 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17123 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17125 /* Record whether the function returns normally to its caller or not
17126 if the DWARF producer set that information. */
17127 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17128 if (attr
&& (DW_UNSND (attr
) != 0))
17129 TYPE_NO_RETURN (ftype
) = 1;
17131 /* We need to add the subroutine type to the die immediately so
17132 we don't infinitely recurse when dealing with parameters
17133 declared as the same subroutine type. */
17134 set_die_type (die
, ftype
, cu
);
17136 if (die
->child
!= NULL
)
17138 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17139 struct die_info
*child_die
;
17140 int nparams
, iparams
;
17142 /* Count the number of parameters.
17143 FIXME: GDB currently ignores vararg functions, but knows about
17144 vararg member functions. */
17146 child_die
= die
->child
;
17147 while (child_die
&& child_die
->tag
)
17149 if (child_die
->tag
== DW_TAG_formal_parameter
)
17151 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17152 TYPE_VARARGS (ftype
) = 1;
17153 child_die
= child_die
->sibling
;
17156 /* Allocate storage for parameters and fill them in. */
17157 ftype
->set_num_fields (nparams
);
17159 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17161 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17162 even if we error out during the parameters reading below. */
17163 for (iparams
= 0; iparams
< nparams
; iparams
++)
17164 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17167 child_die
= die
->child
;
17168 while (child_die
&& child_die
->tag
)
17170 if (child_die
->tag
== DW_TAG_formal_parameter
)
17172 struct type
*arg_type
;
17174 /* DWARF version 2 has no clean way to discern C++
17175 static and non-static member functions. G++ helps
17176 GDB by marking the first parameter for non-static
17177 member functions (which is the this pointer) as
17178 artificial. We pass this information to
17179 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17181 DWARF version 3 added DW_AT_object_pointer, which GCC
17182 4.5 does not yet generate. */
17183 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17184 if (attr
!= nullptr)
17185 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17187 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17188 arg_type
= die_type (child_die
, cu
);
17190 /* RealView does not mark THIS as const, which the testsuite
17191 expects. GCC marks THIS as const in method definitions,
17192 but not in the class specifications (GCC PR 43053). */
17193 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17194 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17197 struct dwarf2_cu
*arg_cu
= cu
;
17198 const char *name
= dwarf2_name (child_die
, cu
);
17200 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17201 if (attr
!= nullptr)
17203 /* If the compiler emits this, use it. */
17204 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17207 else if (name
&& strcmp (name
, "this") == 0)
17208 /* Function definitions will have the argument names. */
17210 else if (name
== NULL
&& iparams
== 0)
17211 /* Declarations may not have the names, so like
17212 elsewhere in GDB, assume an artificial first
17213 argument is "this". */
17217 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17221 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17224 child_die
= child_die
->sibling
;
17231 static struct type
*
17232 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17234 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17235 const char *name
= NULL
;
17236 struct type
*this_type
, *target_type
;
17238 name
= dwarf2_full_name (NULL
, die
, cu
);
17239 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17240 TYPE_TARGET_STUB (this_type
) = 1;
17241 set_die_type (die
, this_type
, cu
);
17242 target_type
= die_type (die
, cu
);
17243 if (target_type
!= this_type
)
17244 TYPE_TARGET_TYPE (this_type
) = target_type
;
17247 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17248 spec and cause infinite loops in GDB. */
17249 complaint (_("Self-referential DW_TAG_typedef "
17250 "- DIE at %s [in module %s]"),
17251 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17252 TYPE_TARGET_TYPE (this_type
) = NULL
;
17256 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17257 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17258 Handle these by just returning the target type, rather than
17259 constructing an anonymous typedef type and trying to handle this
17261 set_die_type (die
, target_type
, cu
);
17262 return target_type
;
17267 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17268 (which may be different from NAME) to the architecture back-end to allow
17269 it to guess the correct format if necessary. */
17271 static struct type
*
17272 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17273 const char *name_hint
, enum bfd_endian byte_order
)
17275 struct gdbarch
*gdbarch
= objfile
->arch ();
17276 const struct floatformat
**format
;
17279 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17281 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17283 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17288 /* Allocate an integer type of size BITS and name NAME. */
17290 static struct type
*
17291 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17292 int bits
, int unsigned_p
, const char *name
)
17296 /* Versions of Intel's C Compiler generate an integer type called "void"
17297 instead of using DW_TAG_unspecified_type. This has been seen on
17298 at least versions 14, 17, and 18. */
17299 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17300 && strcmp (name
, "void") == 0)
17301 type
= objfile_type (objfile
)->builtin_void
;
17303 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17308 /* Initialise and return a floating point type of size BITS suitable for
17309 use as a component of a complex number. The NAME_HINT is passed through
17310 when initialising the floating point type and is the name of the complex
17313 As DWARF doesn't currently provide an explicit name for the components
17314 of a complex number, but it can be helpful to have these components
17315 named, we try to select a suitable name based on the size of the
17317 static struct type
*
17318 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17319 struct objfile
*objfile
,
17320 int bits
, const char *name_hint
,
17321 enum bfd_endian byte_order
)
17323 gdbarch
*gdbarch
= objfile
->arch ();
17324 struct type
*tt
= nullptr;
17326 /* Try to find a suitable floating point builtin type of size BITS.
17327 We're going to use the name of this type as the name for the complex
17328 target type that we are about to create. */
17329 switch (cu
->language
)
17331 case language_fortran
:
17335 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17338 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17340 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17342 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17350 tt
= builtin_type (gdbarch
)->builtin_float
;
17353 tt
= builtin_type (gdbarch
)->builtin_double
;
17355 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17357 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17363 /* If the type we found doesn't match the size we were looking for, then
17364 pretend we didn't find a type at all, the complex target type we
17365 create will then be nameless. */
17366 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17369 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17370 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17373 /* Find a representation of a given base type and install
17374 it in the TYPE field of the die. */
17376 static struct type
*
17377 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17379 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17381 struct attribute
*attr
;
17382 int encoding
= 0, bits
= 0;
17386 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17387 if (attr
!= nullptr)
17388 encoding
= DW_UNSND (attr
);
17389 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17390 if (attr
!= nullptr)
17391 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17392 name
= dwarf2_name (die
, cu
);
17394 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17396 arch
= objfile
->arch ();
17397 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17399 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17402 int endianity
= DW_UNSND (attr
);
17407 byte_order
= BFD_ENDIAN_BIG
;
17409 case DW_END_little
:
17410 byte_order
= BFD_ENDIAN_LITTLE
;
17413 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17420 case DW_ATE_address
:
17421 /* Turn DW_ATE_address into a void * pointer. */
17422 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17423 type
= init_pointer_type (objfile
, bits
, name
, type
);
17425 case DW_ATE_boolean
:
17426 type
= init_boolean_type (objfile
, bits
, 1, name
);
17428 case DW_ATE_complex_float
:
17429 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17431 if (type
->code () == TYPE_CODE_ERROR
)
17433 if (name
== nullptr)
17435 struct obstack
*obstack
17436 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17437 name
= obconcat (obstack
, "_Complex ", type
->name (),
17440 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17443 type
= init_complex_type (name
, type
);
17445 case DW_ATE_decimal_float
:
17446 type
= init_decfloat_type (objfile
, bits
, name
);
17449 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17451 case DW_ATE_signed
:
17452 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17454 case DW_ATE_unsigned
:
17455 if (cu
->language
== language_fortran
17457 && startswith (name
, "character("))
17458 type
= init_character_type (objfile
, bits
, 1, name
);
17460 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17462 case DW_ATE_signed_char
:
17463 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17464 || cu
->language
== language_pascal
17465 || cu
->language
== language_fortran
)
17466 type
= init_character_type (objfile
, bits
, 0, name
);
17468 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17470 case DW_ATE_unsigned_char
:
17471 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17472 || cu
->language
== language_pascal
17473 || cu
->language
== language_fortran
17474 || cu
->language
== language_rust
)
17475 type
= init_character_type (objfile
, bits
, 1, name
);
17477 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17482 type
= builtin_type (arch
)->builtin_char16
;
17483 else if (bits
== 32)
17484 type
= builtin_type (arch
)->builtin_char32
;
17487 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17489 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17491 return set_die_type (die
, type
, cu
);
17496 complaint (_("unsupported DW_AT_encoding: '%s'"),
17497 dwarf_type_encoding_name (encoding
));
17498 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17502 if (name
&& strcmp (name
, "char") == 0)
17503 TYPE_NOSIGN (type
) = 1;
17505 maybe_set_alignment (cu
, die
, type
);
17507 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17509 return set_die_type (die
, type
, cu
);
17512 /* Parse dwarf attribute if it's a block, reference or constant and put the
17513 resulting value of the attribute into struct bound_prop.
17514 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17517 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17518 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17519 struct type
*default_type
)
17521 struct dwarf2_property_baton
*baton
;
17522 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17523 struct objfile
*objfile
= per_objfile
->objfile
;
17524 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17526 gdb_assert (default_type
!= NULL
);
17528 if (attr
== NULL
|| prop
== NULL
)
17531 if (attr
->form_is_block ())
17533 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17534 baton
->property_type
= default_type
;
17535 baton
->locexpr
.per_cu
= cu
->per_cu
;
17536 baton
->locexpr
.per_objfile
= per_objfile
;
17537 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17538 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17539 switch (attr
->name
)
17541 case DW_AT_string_length
:
17542 baton
->locexpr
.is_reference
= true;
17545 baton
->locexpr
.is_reference
= false;
17548 prop
->data
.baton
= baton
;
17549 prop
->kind
= PROP_LOCEXPR
;
17550 gdb_assert (prop
->data
.baton
!= NULL
);
17552 else if (attr
->form_is_ref ())
17554 struct dwarf2_cu
*target_cu
= cu
;
17555 struct die_info
*target_die
;
17556 struct attribute
*target_attr
;
17558 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17559 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17560 if (target_attr
== NULL
)
17561 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17563 if (target_attr
== NULL
)
17566 switch (target_attr
->name
)
17568 case DW_AT_location
:
17569 if (target_attr
->form_is_section_offset ())
17571 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17572 baton
->property_type
= die_type (target_die
, target_cu
);
17573 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17574 prop
->data
.baton
= baton
;
17575 prop
->kind
= PROP_LOCLIST
;
17576 gdb_assert (prop
->data
.baton
!= NULL
);
17578 else if (target_attr
->form_is_block ())
17580 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17581 baton
->property_type
= die_type (target_die
, target_cu
);
17582 baton
->locexpr
.per_cu
= cu
->per_cu
;
17583 baton
->locexpr
.per_objfile
= per_objfile
;
17584 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17585 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17586 baton
->locexpr
.is_reference
= true;
17587 prop
->data
.baton
= baton
;
17588 prop
->kind
= PROP_LOCEXPR
;
17589 gdb_assert (prop
->data
.baton
!= NULL
);
17593 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17594 "dynamic property");
17598 case DW_AT_data_member_location
:
17602 if (!handle_data_member_location (target_die
, target_cu
,
17606 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17607 baton
->property_type
= read_type_die (target_die
->parent
,
17609 baton
->offset_info
.offset
= offset
;
17610 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17611 prop
->data
.baton
= baton
;
17612 prop
->kind
= PROP_ADDR_OFFSET
;
17617 else if (attr
->form_is_constant ())
17619 prop
->data
.const_val
= attr
->constant_value (0);
17620 prop
->kind
= PROP_CONST
;
17624 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17625 dwarf2_name (die
, cu
));
17635 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17637 struct type
*int_type
;
17639 /* Helper macro to examine the various builtin types. */
17640 #define TRY_TYPE(F) \
17641 int_type = (unsigned_p \
17642 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17643 : objfile_type (objfile)->builtin_ ## F); \
17644 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17651 TRY_TYPE (long_long
);
17655 gdb_assert_not_reached ("unable to find suitable integer type");
17661 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17663 int addr_size
= this->per_cu
->addr_size ();
17664 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17667 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17668 present (which is valid) then compute the default type based on the
17669 compilation units address size. */
17671 static struct type
*
17672 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17674 struct type
*index_type
= die_type (die
, cu
);
17676 /* Dwarf-2 specifications explicitly allows to create subrange types
17677 without specifying a base type.
17678 In that case, the base type must be set to the type of
17679 the lower bound, upper bound or count, in that order, if any of these
17680 three attributes references an object that has a type.
17681 If no base type is found, the Dwarf-2 specifications say that
17682 a signed integer type of size equal to the size of an address should
17684 For the following C code: `extern char gdb_int [];'
17685 GCC produces an empty range DIE.
17686 FIXME: muller/2010-05-28: Possible references to object for low bound,
17687 high bound or count are not yet handled by this code. */
17688 if (index_type
->code () == TYPE_CODE_VOID
)
17689 index_type
= cu
->addr_sized_int_type (false);
17694 /* Read the given DW_AT_subrange DIE. */
17696 static struct type
*
17697 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17699 struct type
*base_type
, *orig_base_type
;
17700 struct type
*range_type
;
17701 struct attribute
*attr
;
17702 struct dynamic_prop low
, high
;
17703 int low_default_is_valid
;
17704 int high_bound_is_count
= 0;
17706 ULONGEST negative_mask
;
17708 orig_base_type
= read_subrange_index_type (die
, cu
);
17710 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17711 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17712 creating the range type, but we use the result of check_typedef
17713 when examining properties of the type. */
17714 base_type
= check_typedef (orig_base_type
);
17716 /* The die_type call above may have already set the type for this DIE. */
17717 range_type
= get_die_type (die
, cu
);
17721 low
.kind
= PROP_CONST
;
17722 high
.kind
= PROP_CONST
;
17723 high
.data
.const_val
= 0;
17725 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17726 omitting DW_AT_lower_bound. */
17727 switch (cu
->language
)
17730 case language_cplus
:
17731 low
.data
.const_val
= 0;
17732 low_default_is_valid
= 1;
17734 case language_fortran
:
17735 low
.data
.const_val
= 1;
17736 low_default_is_valid
= 1;
17739 case language_objc
:
17740 case language_rust
:
17741 low
.data
.const_val
= 0;
17742 low_default_is_valid
= (cu
->header
.version
>= 4);
17746 case language_pascal
:
17747 low
.data
.const_val
= 1;
17748 low_default_is_valid
= (cu
->header
.version
>= 4);
17751 low
.data
.const_val
= 0;
17752 low_default_is_valid
= 0;
17756 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17757 if (attr
!= nullptr)
17758 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17759 else if (!low_default_is_valid
)
17760 complaint (_("Missing DW_AT_lower_bound "
17761 "- DIE at %s [in module %s]"),
17762 sect_offset_str (die
->sect_off
),
17763 objfile_name (cu
->per_objfile
->objfile
));
17765 struct attribute
*attr_ub
, *attr_count
;
17766 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17767 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17769 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17770 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17772 /* If bounds are constant do the final calculation here. */
17773 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17774 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17776 high_bound_is_count
= 1;
17780 if (attr_ub
!= NULL
)
17781 complaint (_("Unresolved DW_AT_upper_bound "
17782 "- DIE at %s [in module %s]"),
17783 sect_offset_str (die
->sect_off
),
17784 objfile_name (cu
->per_objfile
->objfile
));
17785 if (attr_count
!= NULL
)
17786 complaint (_("Unresolved DW_AT_count "
17787 "- DIE at %s [in module %s]"),
17788 sect_offset_str (die
->sect_off
),
17789 objfile_name (cu
->per_objfile
->objfile
));
17794 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17795 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17796 bias
= bias_attr
->constant_value (0);
17798 /* Normally, the DWARF producers are expected to use a signed
17799 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17800 But this is unfortunately not always the case, as witnessed
17801 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17802 is used instead. To work around that ambiguity, we treat
17803 the bounds as signed, and thus sign-extend their values, when
17804 the base type is signed. */
17806 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17807 if (low
.kind
== PROP_CONST
17808 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17809 low
.data
.const_val
|= negative_mask
;
17810 if (high
.kind
== PROP_CONST
17811 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17812 high
.data
.const_val
|= negative_mask
;
17814 /* Check for bit and byte strides. */
17815 struct dynamic_prop byte_stride_prop
;
17816 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17817 if (attr_byte_stride
!= nullptr)
17819 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17820 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17824 struct dynamic_prop bit_stride_prop
;
17825 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17826 if (attr_bit_stride
!= nullptr)
17828 /* It only makes sense to have either a bit or byte stride. */
17829 if (attr_byte_stride
!= nullptr)
17831 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17832 "- DIE at %s [in module %s]"),
17833 sect_offset_str (die
->sect_off
),
17834 objfile_name (cu
->per_objfile
->objfile
));
17835 attr_bit_stride
= nullptr;
17839 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17840 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17845 if (attr_byte_stride
!= nullptr
17846 || attr_bit_stride
!= nullptr)
17848 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17849 struct dynamic_prop
*stride
17850 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17853 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17854 &high
, bias
, stride
, byte_stride_p
);
17857 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17859 if (high_bound_is_count
)
17860 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17862 /* Ada expects an empty array on no boundary attributes. */
17863 if (attr
== NULL
&& cu
->language
!= language_ada
)
17864 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17866 name
= dwarf2_name (die
, cu
);
17868 range_type
->set_name (name
);
17870 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17871 if (attr
!= nullptr)
17872 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17874 maybe_set_alignment (cu
, die
, range_type
);
17876 set_die_type (die
, range_type
, cu
);
17878 /* set_die_type should be already done. */
17879 set_descriptive_type (range_type
, die
, cu
);
17884 static struct type
*
17885 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17889 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17890 type
->set_name (dwarf2_name (die
, cu
));
17892 /* In Ada, an unspecified type is typically used when the description
17893 of the type is deferred to a different unit. When encountering
17894 such a type, we treat it as a stub, and try to resolve it later on,
17896 if (cu
->language
== language_ada
)
17897 TYPE_STUB (type
) = 1;
17899 return set_die_type (die
, type
, cu
);
17902 /* Read a single die and all its descendents. Set the die's sibling
17903 field to NULL; set other fields in the die correctly, and set all
17904 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17905 location of the info_ptr after reading all of those dies. PARENT
17906 is the parent of the die in question. */
17908 static struct die_info
*
17909 read_die_and_children (const struct die_reader_specs
*reader
,
17910 const gdb_byte
*info_ptr
,
17911 const gdb_byte
**new_info_ptr
,
17912 struct die_info
*parent
)
17914 struct die_info
*die
;
17915 const gdb_byte
*cur_ptr
;
17917 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17920 *new_info_ptr
= cur_ptr
;
17923 store_in_ref_table (die
, reader
->cu
);
17925 if (die
->has_children
)
17926 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17930 *new_info_ptr
= cur_ptr
;
17933 die
->sibling
= NULL
;
17934 die
->parent
= parent
;
17938 /* Read a die, all of its descendents, and all of its siblings; set
17939 all of the fields of all of the dies correctly. Arguments are as
17940 in read_die_and_children. */
17942 static struct die_info
*
17943 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17944 const gdb_byte
*info_ptr
,
17945 const gdb_byte
**new_info_ptr
,
17946 struct die_info
*parent
)
17948 struct die_info
*first_die
, *last_sibling
;
17949 const gdb_byte
*cur_ptr
;
17951 cur_ptr
= info_ptr
;
17952 first_die
= last_sibling
= NULL
;
17956 struct die_info
*die
17957 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17961 *new_info_ptr
= cur_ptr
;
17968 last_sibling
->sibling
= die
;
17970 last_sibling
= die
;
17974 /* Read a die, all of its descendents, and all of its siblings; set
17975 all of the fields of all of the dies correctly. Arguments are as
17976 in read_die_and_children.
17977 This the main entry point for reading a DIE and all its children. */
17979 static struct die_info
*
17980 read_die_and_siblings (const struct die_reader_specs
*reader
,
17981 const gdb_byte
*info_ptr
,
17982 const gdb_byte
**new_info_ptr
,
17983 struct die_info
*parent
)
17985 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17986 new_info_ptr
, parent
);
17988 if (dwarf_die_debug
)
17990 fprintf_unfiltered (gdb_stdlog
,
17991 "Read die from %s@0x%x of %s:\n",
17992 reader
->die_section
->get_name (),
17993 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17994 bfd_get_filename (reader
->abfd
));
17995 dump_die (die
, dwarf_die_debug
);
18001 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18003 The caller is responsible for filling in the extra attributes
18004 and updating (*DIEP)->num_attrs.
18005 Set DIEP to point to a newly allocated die with its information,
18006 except for its child, sibling, and parent fields. */
18008 static const gdb_byte
*
18009 read_full_die_1 (const struct die_reader_specs
*reader
,
18010 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18011 int num_extra_attrs
)
18013 unsigned int abbrev_number
, bytes_read
, i
;
18014 struct abbrev_info
*abbrev
;
18015 struct die_info
*die
;
18016 struct dwarf2_cu
*cu
= reader
->cu
;
18017 bfd
*abfd
= reader
->abfd
;
18019 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18020 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18021 info_ptr
+= bytes_read
;
18022 if (!abbrev_number
)
18028 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18030 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18032 bfd_get_filename (abfd
));
18034 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18035 die
->sect_off
= sect_off
;
18036 die
->tag
= abbrev
->tag
;
18037 die
->abbrev
= abbrev_number
;
18038 die
->has_children
= abbrev
->has_children
;
18040 /* Make the result usable.
18041 The caller needs to update num_attrs after adding the extra
18043 die
->num_attrs
= abbrev
->num_attrs
;
18045 std::vector
<int> indexes_that_need_reprocess
;
18046 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18048 bool need_reprocess
;
18050 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18051 info_ptr
, &need_reprocess
);
18052 if (need_reprocess
)
18053 indexes_that_need_reprocess
.push_back (i
);
18056 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18057 if (attr
!= nullptr)
18058 cu
->str_offsets_base
= DW_UNSND (attr
);
18060 attr
= die
->attr (DW_AT_loclists_base
);
18061 if (attr
!= nullptr)
18062 cu
->loclist_base
= DW_UNSND (attr
);
18064 auto maybe_addr_base
= die
->addr_base ();
18065 if (maybe_addr_base
.has_value ())
18066 cu
->addr_base
= *maybe_addr_base
;
18067 for (int index
: indexes_that_need_reprocess
)
18068 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18073 /* Read a die and all its attributes.
18074 Set DIEP to point to a newly allocated die with its information,
18075 except for its child, sibling, and parent fields. */
18077 static const gdb_byte
*
18078 read_full_die (const struct die_reader_specs
*reader
,
18079 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18081 const gdb_byte
*result
;
18083 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18085 if (dwarf_die_debug
)
18087 fprintf_unfiltered (gdb_stdlog
,
18088 "Read die from %s@0x%x of %s:\n",
18089 reader
->die_section
->get_name (),
18090 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18091 bfd_get_filename (reader
->abfd
));
18092 dump_die (*diep
, dwarf_die_debug
);
18099 /* Returns nonzero if TAG represents a type that we might generate a partial
18103 is_type_tag_for_partial (int tag
)
18108 /* Some types that would be reasonable to generate partial symbols for,
18109 that we don't at present. */
18110 case DW_TAG_array_type
:
18111 case DW_TAG_file_type
:
18112 case DW_TAG_ptr_to_member_type
:
18113 case DW_TAG_set_type
:
18114 case DW_TAG_string_type
:
18115 case DW_TAG_subroutine_type
:
18117 case DW_TAG_base_type
:
18118 case DW_TAG_class_type
:
18119 case DW_TAG_interface_type
:
18120 case DW_TAG_enumeration_type
:
18121 case DW_TAG_structure_type
:
18122 case DW_TAG_subrange_type
:
18123 case DW_TAG_typedef
:
18124 case DW_TAG_union_type
:
18131 /* Load all DIEs that are interesting for partial symbols into memory. */
18133 static struct partial_die_info
*
18134 load_partial_dies (const struct die_reader_specs
*reader
,
18135 const gdb_byte
*info_ptr
, int building_psymtab
)
18137 struct dwarf2_cu
*cu
= reader
->cu
;
18138 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18139 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18140 unsigned int bytes_read
;
18141 unsigned int load_all
= 0;
18142 int nesting_level
= 1;
18147 gdb_assert (cu
->per_cu
!= NULL
);
18148 if (cu
->per_cu
->load_all_dies
)
18152 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18156 &cu
->comp_unit_obstack
,
18157 hashtab_obstack_allocate
,
18158 dummy_obstack_deallocate
);
18162 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18164 /* A NULL abbrev means the end of a series of children. */
18165 if (abbrev
== NULL
)
18167 if (--nesting_level
== 0)
18170 info_ptr
+= bytes_read
;
18171 last_die
= parent_die
;
18172 parent_die
= parent_die
->die_parent
;
18176 /* Check for template arguments. We never save these; if
18177 they're seen, we just mark the parent, and go on our way. */
18178 if (parent_die
!= NULL
18179 && cu
->language
== language_cplus
18180 && (abbrev
->tag
== DW_TAG_template_type_param
18181 || abbrev
->tag
== DW_TAG_template_value_param
))
18183 parent_die
->has_template_arguments
= 1;
18187 /* We don't need a partial DIE for the template argument. */
18188 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18193 /* We only recurse into c++ subprograms looking for template arguments.
18194 Skip their other children. */
18196 && cu
->language
== language_cplus
18197 && parent_die
!= NULL
18198 && parent_die
->tag
== DW_TAG_subprogram
)
18200 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18204 /* Check whether this DIE is interesting enough to save. Normally
18205 we would not be interested in members here, but there may be
18206 later variables referencing them via DW_AT_specification (for
18207 static members). */
18209 && !is_type_tag_for_partial (abbrev
->tag
)
18210 && abbrev
->tag
!= DW_TAG_constant
18211 && abbrev
->tag
!= DW_TAG_enumerator
18212 && abbrev
->tag
!= DW_TAG_subprogram
18213 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18214 && abbrev
->tag
!= DW_TAG_lexical_block
18215 && abbrev
->tag
!= DW_TAG_variable
18216 && abbrev
->tag
!= DW_TAG_namespace
18217 && abbrev
->tag
!= DW_TAG_module
18218 && abbrev
->tag
!= DW_TAG_member
18219 && abbrev
->tag
!= DW_TAG_imported_unit
18220 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18222 /* Otherwise we skip to the next sibling, if any. */
18223 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18227 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18230 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18232 /* This two-pass algorithm for processing partial symbols has a
18233 high cost in cache pressure. Thus, handle some simple cases
18234 here which cover the majority of C partial symbols. DIEs
18235 which neither have specification tags in them, nor could have
18236 specification tags elsewhere pointing at them, can simply be
18237 processed and discarded.
18239 This segment is also optional; scan_partial_symbols and
18240 add_partial_symbol will handle these DIEs if we chain
18241 them in normally. When compilers which do not emit large
18242 quantities of duplicate debug information are more common,
18243 this code can probably be removed. */
18245 /* Any complete simple types at the top level (pretty much all
18246 of them, for a language without namespaces), can be processed
18248 if (parent_die
== NULL
18249 && pdi
.has_specification
== 0
18250 && pdi
.is_declaration
== 0
18251 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18252 || pdi
.tag
== DW_TAG_base_type
18253 || pdi
.tag
== DW_TAG_subrange_type
))
18255 if (building_psymtab
&& pdi
.name
!= NULL
)
18256 add_psymbol_to_list (pdi
.name
, false,
18257 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18258 psymbol_placement::STATIC
,
18259 0, cu
->language
, objfile
);
18260 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18264 /* The exception for DW_TAG_typedef with has_children above is
18265 a workaround of GCC PR debug/47510. In the case of this complaint
18266 type_name_or_error will error on such types later.
18268 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18269 it could not find the child DIEs referenced later, this is checked
18270 above. In correct DWARF DW_TAG_typedef should have no children. */
18272 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18273 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18274 "- DIE at %s [in module %s]"),
18275 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18277 /* If we're at the second level, and we're an enumerator, and
18278 our parent has no specification (meaning possibly lives in a
18279 namespace elsewhere), then we can add the partial symbol now
18280 instead of queueing it. */
18281 if (pdi
.tag
== DW_TAG_enumerator
18282 && parent_die
!= NULL
18283 && parent_die
->die_parent
== NULL
18284 && parent_die
->tag
== DW_TAG_enumeration_type
18285 && parent_die
->has_specification
== 0)
18287 if (pdi
.name
== NULL
)
18288 complaint (_("malformed enumerator DIE ignored"));
18289 else if (building_psymtab
)
18290 add_psymbol_to_list (pdi
.name
, false,
18291 VAR_DOMAIN
, LOC_CONST
, -1,
18292 cu
->language
== language_cplus
18293 ? psymbol_placement::GLOBAL
18294 : psymbol_placement::STATIC
,
18295 0, cu
->language
, objfile
);
18297 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18301 struct partial_die_info
*part_die
18302 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18304 /* We'll save this DIE so link it in. */
18305 part_die
->die_parent
= parent_die
;
18306 part_die
->die_sibling
= NULL
;
18307 part_die
->die_child
= NULL
;
18309 if (last_die
&& last_die
== parent_die
)
18310 last_die
->die_child
= part_die
;
18312 last_die
->die_sibling
= part_die
;
18314 last_die
= part_die
;
18316 if (first_die
== NULL
)
18317 first_die
= part_die
;
18319 /* Maybe add the DIE to the hash table. Not all DIEs that we
18320 find interesting need to be in the hash table, because we
18321 also have the parent/sibling/child chains; only those that we
18322 might refer to by offset later during partial symbol reading.
18324 For now this means things that might have be the target of a
18325 DW_AT_specification, DW_AT_abstract_origin, or
18326 DW_AT_extension. DW_AT_extension will refer only to
18327 namespaces; DW_AT_abstract_origin refers to functions (and
18328 many things under the function DIE, but we do not recurse
18329 into function DIEs during partial symbol reading) and
18330 possibly variables as well; DW_AT_specification refers to
18331 declarations. Declarations ought to have the DW_AT_declaration
18332 flag. It happens that GCC forgets to put it in sometimes, but
18333 only for functions, not for types.
18335 Adding more things than necessary to the hash table is harmless
18336 except for the performance cost. Adding too few will result in
18337 wasted time in find_partial_die, when we reread the compilation
18338 unit with load_all_dies set. */
18341 || abbrev
->tag
== DW_TAG_constant
18342 || abbrev
->tag
== DW_TAG_subprogram
18343 || abbrev
->tag
== DW_TAG_variable
18344 || abbrev
->tag
== DW_TAG_namespace
18345 || part_die
->is_declaration
)
18349 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18350 to_underlying (part_die
->sect_off
),
18355 /* For some DIEs we want to follow their children (if any). For C
18356 we have no reason to follow the children of structures; for other
18357 languages we have to, so that we can get at method physnames
18358 to infer fully qualified class names, for DW_AT_specification,
18359 and for C++ template arguments. For C++, we also look one level
18360 inside functions to find template arguments (if the name of the
18361 function does not already contain the template arguments).
18363 For Ada and Fortran, we need to scan the children of subprograms
18364 and lexical blocks as well because these languages allow the
18365 definition of nested entities that could be interesting for the
18366 debugger, such as nested subprograms for instance. */
18367 if (last_die
->has_children
18369 || last_die
->tag
== DW_TAG_namespace
18370 || last_die
->tag
== DW_TAG_module
18371 || last_die
->tag
== DW_TAG_enumeration_type
18372 || (cu
->language
== language_cplus
18373 && last_die
->tag
== DW_TAG_subprogram
18374 && (last_die
->name
== NULL
18375 || strchr (last_die
->name
, '<') == NULL
))
18376 || (cu
->language
!= language_c
18377 && (last_die
->tag
== DW_TAG_class_type
18378 || last_die
->tag
== DW_TAG_interface_type
18379 || last_die
->tag
== DW_TAG_structure_type
18380 || last_die
->tag
== DW_TAG_union_type
))
18381 || ((cu
->language
== language_ada
18382 || cu
->language
== language_fortran
)
18383 && (last_die
->tag
== DW_TAG_subprogram
18384 || last_die
->tag
== DW_TAG_lexical_block
))))
18387 parent_die
= last_die
;
18391 /* Otherwise we skip to the next sibling, if any. */
18392 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18394 /* Back to the top, do it again. */
18398 partial_die_info::partial_die_info (sect_offset sect_off_
,
18399 struct abbrev_info
*abbrev
)
18400 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18404 /* Read a minimal amount of information into the minimal die structure.
18405 INFO_PTR should point just after the initial uleb128 of a DIE. */
18408 partial_die_info::read (const struct die_reader_specs
*reader
,
18409 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18411 struct dwarf2_cu
*cu
= reader
->cu
;
18412 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18414 int has_low_pc_attr
= 0;
18415 int has_high_pc_attr
= 0;
18416 int high_pc_relative
= 0;
18418 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18421 bool need_reprocess
;
18422 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18423 info_ptr
, &need_reprocess
);
18424 /* String and address offsets that need to do the reprocessing have
18425 already been read at this point, so there is no need to wait until
18426 the loop terminates to do the reprocessing. */
18427 if (need_reprocess
)
18428 read_attribute_reprocess (reader
, &attr
);
18429 /* Store the data if it is of an attribute we want to keep in a
18430 partial symbol table. */
18436 case DW_TAG_compile_unit
:
18437 case DW_TAG_partial_unit
:
18438 case DW_TAG_type_unit
:
18439 /* Compilation units have a DW_AT_name that is a filename, not
18440 a source language identifier. */
18441 case DW_TAG_enumeration_type
:
18442 case DW_TAG_enumerator
:
18443 /* These tags always have simple identifiers already; no need
18444 to canonicalize them. */
18445 name
= DW_STRING (&attr
);
18449 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18452 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18457 case DW_AT_linkage_name
:
18458 case DW_AT_MIPS_linkage_name
:
18459 /* Note that both forms of linkage name might appear. We
18460 assume they will be the same, and we only store the last
18462 linkage_name
= attr
.value_as_string ();
18463 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18464 See https://github.com/rust-lang/rust/issues/32925. */
18465 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18466 && strchr (linkage_name
, '{') != NULL
)
18467 linkage_name
= NULL
;
18470 has_low_pc_attr
= 1;
18471 lowpc
= attr
.value_as_address ();
18473 case DW_AT_high_pc
:
18474 has_high_pc_attr
= 1;
18475 highpc
= attr
.value_as_address ();
18476 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18477 high_pc_relative
= 1;
18479 case DW_AT_location
:
18480 /* Support the .debug_loc offsets. */
18481 if (attr
.form_is_block ())
18483 d
.locdesc
= DW_BLOCK (&attr
);
18485 else if (attr
.form_is_section_offset ())
18487 dwarf2_complex_location_expr_complaint ();
18491 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18492 "partial symbol information");
18495 case DW_AT_external
:
18496 is_external
= DW_UNSND (&attr
);
18498 case DW_AT_declaration
:
18499 is_declaration
= DW_UNSND (&attr
);
18504 case DW_AT_abstract_origin
:
18505 case DW_AT_specification
:
18506 case DW_AT_extension
:
18507 has_specification
= 1;
18508 spec_offset
= attr
.get_ref_die_offset ();
18509 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18510 || cu
->per_cu
->is_dwz
);
18512 case DW_AT_sibling
:
18513 /* Ignore absolute siblings, they might point outside of
18514 the current compile unit. */
18515 if (attr
.form
== DW_FORM_ref_addr
)
18516 complaint (_("ignoring absolute DW_AT_sibling"));
18519 const gdb_byte
*buffer
= reader
->buffer
;
18520 sect_offset off
= attr
.get_ref_die_offset ();
18521 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18523 if (sibling_ptr
< info_ptr
)
18524 complaint (_("DW_AT_sibling points backwards"));
18525 else if (sibling_ptr
> reader
->buffer_end
)
18526 reader
->die_section
->overflow_complaint ();
18528 sibling
= sibling_ptr
;
18531 case DW_AT_byte_size
:
18534 case DW_AT_const_value
:
18535 has_const_value
= 1;
18537 case DW_AT_calling_convention
:
18538 /* DWARF doesn't provide a way to identify a program's source-level
18539 entry point. DW_AT_calling_convention attributes are only meant
18540 to describe functions' calling conventions.
18542 However, because it's a necessary piece of information in
18543 Fortran, and before DWARF 4 DW_CC_program was the only
18544 piece of debugging information whose definition refers to
18545 a 'main program' at all, several compilers marked Fortran
18546 main programs with DW_CC_program --- even when those
18547 functions use the standard calling conventions.
18549 Although DWARF now specifies a way to provide this
18550 information, we support this practice for backward
18552 if (DW_UNSND (&attr
) == DW_CC_program
18553 && cu
->language
== language_fortran
)
18554 main_subprogram
= 1;
18557 if (DW_UNSND (&attr
) == DW_INL_inlined
18558 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18559 may_be_inlined
= 1;
18563 if (tag
== DW_TAG_imported_unit
)
18565 d
.sect_off
= attr
.get_ref_die_offset ();
18566 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18567 || cu
->per_cu
->is_dwz
);
18571 case DW_AT_main_subprogram
:
18572 main_subprogram
= DW_UNSND (&attr
);
18577 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18578 but that requires a full DIE, so instead we just
18580 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18581 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18582 + (need_ranges_base
18586 /* Value of the DW_AT_ranges attribute is the offset in the
18587 .debug_ranges section. */
18588 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18599 /* For Ada, if both the name and the linkage name appear, we prefer
18600 the latter. This lets "catch exception" work better, regardless
18601 of the order in which the name and linkage name were emitted.
18602 Really, though, this is just a workaround for the fact that gdb
18603 doesn't store both the name and the linkage name. */
18604 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18605 name
= linkage_name
;
18607 if (high_pc_relative
)
18610 if (has_low_pc_attr
&& has_high_pc_attr
)
18612 /* When using the GNU linker, .gnu.linkonce. sections are used to
18613 eliminate duplicate copies of functions and vtables and such.
18614 The linker will arbitrarily choose one and discard the others.
18615 The AT_*_pc values for such functions refer to local labels in
18616 these sections. If the section from that file was discarded, the
18617 labels are not in the output, so the relocs get a value of 0.
18618 If this is a discarded function, mark the pc bounds as invalid,
18619 so that GDB will ignore it. */
18620 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18622 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18623 struct gdbarch
*gdbarch
= objfile
->arch ();
18625 complaint (_("DW_AT_low_pc %s is zero "
18626 "for DIE at %s [in module %s]"),
18627 paddress (gdbarch
, lowpc
),
18628 sect_offset_str (sect_off
),
18629 objfile_name (objfile
));
18631 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18632 else if (lowpc
>= highpc
)
18634 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18635 struct gdbarch
*gdbarch
= objfile
->arch ();
18637 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18638 "for DIE at %s [in module %s]"),
18639 paddress (gdbarch
, lowpc
),
18640 paddress (gdbarch
, highpc
),
18641 sect_offset_str (sect_off
),
18642 objfile_name (objfile
));
18651 /* Find a cached partial DIE at OFFSET in CU. */
18653 struct partial_die_info
*
18654 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18656 struct partial_die_info
*lookup_die
= NULL
;
18657 struct partial_die_info
part_die (sect_off
);
18659 lookup_die
= ((struct partial_die_info
*)
18660 htab_find_with_hash (partial_dies
, &part_die
,
18661 to_underlying (sect_off
)));
18666 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18667 except in the case of .debug_types DIEs which do not reference
18668 outside their CU (they do however referencing other types via
18669 DW_FORM_ref_sig8). */
18671 static const struct cu_partial_die_info
18672 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18674 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18675 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18676 struct partial_die_info
*pd
= NULL
;
18678 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18679 && cu
->header
.offset_in_cu_p (sect_off
))
18681 pd
= cu
->find_partial_die (sect_off
);
18684 /* We missed recording what we needed.
18685 Load all dies and try again. */
18689 /* TUs don't reference other CUs/TUs (except via type signatures). */
18690 if (cu
->per_cu
->is_debug_types
)
18692 error (_("Dwarf Error: Type Unit at offset %s contains"
18693 " external reference to offset %s [in module %s].\n"),
18694 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18695 bfd_get_filename (objfile
->obfd
));
18697 dwarf2_per_cu_data
*per_cu
18698 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18699 dwarf2_per_objfile
);
18701 cu
= dwarf2_per_objfile
->get_cu (per_cu
);
18702 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18703 load_partial_comp_unit (per_cu
, dwarf2_per_objfile
, nullptr);
18705 cu
= dwarf2_per_objfile
->get_cu (per_cu
);
18708 pd
= cu
->find_partial_die (sect_off
);
18711 /* If we didn't find it, and not all dies have been loaded,
18712 load them all and try again. */
18714 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18716 cu
->per_cu
->load_all_dies
= 1;
18718 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18719 THIS_CU->cu may already be in use. So we can't just free it and
18720 replace its DIEs with the ones we read in. Instead, we leave those
18721 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18722 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18724 load_partial_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, cu
);
18726 pd
= cu
->find_partial_die (sect_off
);
18730 internal_error (__FILE__
, __LINE__
,
18731 _("could not find partial DIE %s "
18732 "in cache [from module %s]\n"),
18733 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18737 /* See if we can figure out if the class lives in a namespace. We do
18738 this by looking for a member function; its demangled name will
18739 contain namespace info, if there is any. */
18742 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18743 struct dwarf2_cu
*cu
)
18745 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18746 what template types look like, because the demangler
18747 frequently doesn't give the same name as the debug info. We
18748 could fix this by only using the demangled name to get the
18749 prefix (but see comment in read_structure_type). */
18751 struct partial_die_info
*real_pdi
;
18752 struct partial_die_info
*child_pdi
;
18754 /* If this DIE (this DIE's specification, if any) has a parent, then
18755 we should not do this. We'll prepend the parent's fully qualified
18756 name when we create the partial symbol. */
18758 real_pdi
= struct_pdi
;
18759 while (real_pdi
->has_specification
)
18761 auto res
= find_partial_die (real_pdi
->spec_offset
,
18762 real_pdi
->spec_is_dwz
, cu
);
18763 real_pdi
= res
.pdi
;
18767 if (real_pdi
->die_parent
!= NULL
)
18770 for (child_pdi
= struct_pdi
->die_child
;
18772 child_pdi
= child_pdi
->die_sibling
)
18774 if (child_pdi
->tag
== DW_TAG_subprogram
18775 && child_pdi
->linkage_name
!= NULL
)
18777 gdb::unique_xmalloc_ptr
<char> actual_class_name
18778 (language_class_name_from_physname (cu
->language_defn
,
18779 child_pdi
->linkage_name
));
18780 if (actual_class_name
!= NULL
)
18782 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18783 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18790 /* Return true if a DIE with TAG may have the DW_AT_const_value
18794 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18798 case DW_TAG_constant
:
18799 case DW_TAG_enumerator
:
18800 case DW_TAG_formal_parameter
:
18801 case DW_TAG_template_value_param
:
18802 case DW_TAG_variable
:
18810 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18812 /* Once we've fixed up a die, there's no point in doing so again.
18813 This also avoids a memory leak if we were to call
18814 guess_partial_die_structure_name multiple times. */
18818 /* If we found a reference attribute and the DIE has no name, try
18819 to find a name in the referred to DIE. */
18821 if (name
== NULL
&& has_specification
)
18823 struct partial_die_info
*spec_die
;
18825 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18826 spec_die
= res
.pdi
;
18829 spec_die
->fixup (cu
);
18831 if (spec_die
->name
)
18833 name
= spec_die
->name
;
18835 /* Copy DW_AT_external attribute if it is set. */
18836 if (spec_die
->is_external
)
18837 is_external
= spec_die
->is_external
;
18841 if (!has_const_value
&& has_specification
18842 && can_have_DW_AT_const_value_p (tag
))
18844 struct partial_die_info
*spec_die
;
18846 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18847 spec_die
= res
.pdi
;
18850 spec_die
->fixup (cu
);
18852 if (spec_die
->has_const_value
)
18854 /* Copy DW_AT_const_value attribute if it is set. */
18855 has_const_value
= spec_die
->has_const_value
;
18859 /* Set default names for some unnamed DIEs. */
18861 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18862 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18864 /* If there is no parent die to provide a namespace, and there are
18865 children, see if we can determine the namespace from their linkage
18867 if (cu
->language
== language_cplus
18868 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18869 && die_parent
== NULL
18871 && (tag
== DW_TAG_class_type
18872 || tag
== DW_TAG_structure_type
18873 || tag
== DW_TAG_union_type
))
18874 guess_partial_die_structure_name (this, cu
);
18876 /* GCC might emit a nameless struct or union that has a linkage
18877 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18879 && (tag
== DW_TAG_class_type
18880 || tag
== DW_TAG_interface_type
18881 || tag
== DW_TAG_structure_type
18882 || tag
== DW_TAG_union_type
)
18883 && linkage_name
!= NULL
)
18885 gdb::unique_xmalloc_ptr
<char> demangled
18886 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18887 if (demangled
!= nullptr)
18891 /* Strip any leading namespaces/classes, keep only the base name.
18892 DW_AT_name for named DIEs does not contain the prefixes. */
18893 base
= strrchr (demangled
.get (), ':');
18894 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18897 base
= demangled
.get ();
18899 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18900 name
= objfile
->intern (base
);
18907 /* Read the .debug_loclists header contents from the given SECTION in the
18910 read_loclist_header (struct loclist_header
*header
,
18911 struct dwarf2_section_info
*section
)
18913 unsigned int bytes_read
;
18914 bfd
*abfd
= section
->get_bfd_owner ();
18915 const gdb_byte
*info_ptr
= section
->buffer
;
18916 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18917 info_ptr
+= bytes_read
;
18918 header
->version
= read_2_bytes (abfd
, info_ptr
);
18920 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18922 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18924 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18927 /* Return the DW_AT_loclists_base value for the CU. */
18929 lookup_loclist_base (struct dwarf2_cu
*cu
)
18931 /* For the .dwo unit, the loclist_base points to the first offset following
18932 the header. The header consists of the following entities-
18933 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18935 2. version (2 bytes)
18936 3. address size (1 byte)
18937 4. segment selector size (1 byte)
18938 5. offset entry count (4 bytes)
18939 These sizes are derived as per the DWARFv5 standard. */
18940 if (cu
->dwo_unit
!= nullptr)
18942 if (cu
->header
.initial_length_size
== 4)
18943 return LOCLIST_HEADER_SIZE32
;
18944 return LOCLIST_HEADER_SIZE64
;
18946 return cu
->loclist_base
;
18949 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18950 array of offsets in the .debug_loclists section. */
18952 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18954 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18955 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18956 bfd
*abfd
= objfile
->obfd
;
18957 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18958 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18960 section
->read (objfile
);
18961 if (section
->buffer
== NULL
)
18962 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18963 "section [in module %s]"), objfile_name (objfile
));
18964 struct loclist_header header
;
18965 read_loclist_header (&header
, section
);
18966 if (loclist_index
>= header
.offset_entry_count
)
18967 complaint (_("DW_FORM_loclistx pointing outside of "
18968 ".debug_loclists offset array [in module %s]"),
18969 objfile_name (objfile
));
18970 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18972 complaint (_("DW_FORM_loclistx pointing outside of "
18973 ".debug_loclists section [in module %s]"),
18974 objfile_name (objfile
));
18975 const gdb_byte
*info_ptr
18976 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18978 if (cu
->header
.offset_size
== 4)
18979 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18981 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18984 /* Process the attributes that had to be skipped in the first round. These
18985 attributes are the ones that need str_offsets_base or addr_base attributes.
18986 They could not have been processed in the first round, because at the time
18987 the values of str_offsets_base or addr_base may not have been known. */
18989 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18990 struct attribute
*attr
)
18992 struct dwarf2_cu
*cu
= reader
->cu
;
18993 switch (attr
->form
)
18995 case DW_FORM_addrx
:
18996 case DW_FORM_GNU_addr_index
:
18997 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18999 case DW_FORM_loclistx
:
19000 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19003 case DW_FORM_strx1
:
19004 case DW_FORM_strx2
:
19005 case DW_FORM_strx3
:
19006 case DW_FORM_strx4
:
19007 case DW_FORM_GNU_str_index
:
19009 unsigned int str_index
= DW_UNSND (attr
);
19010 if (reader
->dwo_file
!= NULL
)
19012 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19013 DW_STRING_IS_CANONICAL (attr
) = 0;
19017 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19018 DW_STRING_IS_CANONICAL (attr
) = 0;
19023 gdb_assert_not_reached (_("Unexpected DWARF form."));
19027 /* Read an attribute value described by an attribute form. */
19029 static const gdb_byte
*
19030 read_attribute_value (const struct die_reader_specs
*reader
,
19031 struct attribute
*attr
, unsigned form
,
19032 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19033 bool *need_reprocess
)
19035 struct dwarf2_cu
*cu
= reader
->cu
;
19036 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19037 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19038 bfd
*abfd
= reader
->abfd
;
19039 struct comp_unit_head
*cu_header
= &cu
->header
;
19040 unsigned int bytes_read
;
19041 struct dwarf_block
*blk
;
19042 *need_reprocess
= false;
19044 attr
->form
= (enum dwarf_form
) form
;
19047 case DW_FORM_ref_addr
:
19048 if (cu
->header
.version
== 2)
19049 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19052 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19054 info_ptr
+= bytes_read
;
19056 case DW_FORM_GNU_ref_alt
:
19057 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19058 info_ptr
+= bytes_read
;
19062 struct gdbarch
*gdbarch
= objfile
->arch ();
19063 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19064 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19065 info_ptr
+= bytes_read
;
19068 case DW_FORM_block2
:
19069 blk
= dwarf_alloc_block (cu
);
19070 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19072 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19073 info_ptr
+= blk
->size
;
19074 DW_BLOCK (attr
) = blk
;
19076 case DW_FORM_block4
:
19077 blk
= dwarf_alloc_block (cu
);
19078 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19080 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19081 info_ptr
+= blk
->size
;
19082 DW_BLOCK (attr
) = blk
;
19084 case DW_FORM_data2
:
19085 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19088 case DW_FORM_data4
:
19089 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19092 case DW_FORM_data8
:
19093 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19096 case DW_FORM_data16
:
19097 blk
= dwarf_alloc_block (cu
);
19099 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19101 DW_BLOCK (attr
) = blk
;
19103 case DW_FORM_sec_offset
:
19104 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19105 info_ptr
+= bytes_read
;
19107 case DW_FORM_loclistx
:
19109 *need_reprocess
= true;
19110 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19111 info_ptr
+= bytes_read
;
19114 case DW_FORM_string
:
19115 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19116 DW_STRING_IS_CANONICAL (attr
) = 0;
19117 info_ptr
+= bytes_read
;
19120 if (!cu
->per_cu
->is_dwz
)
19122 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19123 abfd
, info_ptr
, cu_header
,
19125 DW_STRING_IS_CANONICAL (attr
) = 0;
19126 info_ptr
+= bytes_read
;
19130 case DW_FORM_line_strp
:
19131 if (!cu
->per_cu
->is_dwz
)
19134 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19136 DW_STRING_IS_CANONICAL (attr
) = 0;
19137 info_ptr
+= bytes_read
;
19141 case DW_FORM_GNU_strp_alt
:
19143 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19144 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19147 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19148 DW_STRING_IS_CANONICAL (attr
) = 0;
19149 info_ptr
+= bytes_read
;
19152 case DW_FORM_exprloc
:
19153 case DW_FORM_block
:
19154 blk
= dwarf_alloc_block (cu
);
19155 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19156 info_ptr
+= bytes_read
;
19157 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19158 info_ptr
+= blk
->size
;
19159 DW_BLOCK (attr
) = blk
;
19161 case DW_FORM_block1
:
19162 blk
= dwarf_alloc_block (cu
);
19163 blk
->size
= read_1_byte (abfd
, info_ptr
);
19165 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19166 info_ptr
+= blk
->size
;
19167 DW_BLOCK (attr
) = blk
;
19169 case DW_FORM_data1
:
19170 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19174 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19177 case DW_FORM_flag_present
:
19178 DW_UNSND (attr
) = 1;
19180 case DW_FORM_sdata
:
19181 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19182 info_ptr
+= bytes_read
;
19184 case DW_FORM_udata
:
19185 case DW_FORM_rnglistx
:
19186 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19187 info_ptr
+= bytes_read
;
19190 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19191 + read_1_byte (abfd
, info_ptr
));
19195 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19196 + read_2_bytes (abfd
, info_ptr
));
19200 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19201 + read_4_bytes (abfd
, info_ptr
));
19205 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19206 + read_8_bytes (abfd
, info_ptr
));
19209 case DW_FORM_ref_sig8
:
19210 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19213 case DW_FORM_ref_udata
:
19214 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19215 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19216 info_ptr
+= bytes_read
;
19218 case DW_FORM_indirect
:
19219 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19220 info_ptr
+= bytes_read
;
19221 if (form
== DW_FORM_implicit_const
)
19223 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19224 info_ptr
+= bytes_read
;
19226 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19227 info_ptr
, need_reprocess
);
19229 case DW_FORM_implicit_const
:
19230 DW_SND (attr
) = implicit_const
;
19232 case DW_FORM_addrx
:
19233 case DW_FORM_GNU_addr_index
:
19234 *need_reprocess
= true;
19235 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19236 info_ptr
+= bytes_read
;
19239 case DW_FORM_strx1
:
19240 case DW_FORM_strx2
:
19241 case DW_FORM_strx3
:
19242 case DW_FORM_strx4
:
19243 case DW_FORM_GNU_str_index
:
19245 ULONGEST str_index
;
19246 if (form
== DW_FORM_strx1
)
19248 str_index
= read_1_byte (abfd
, info_ptr
);
19251 else if (form
== DW_FORM_strx2
)
19253 str_index
= read_2_bytes (abfd
, info_ptr
);
19256 else if (form
== DW_FORM_strx3
)
19258 str_index
= read_3_bytes (abfd
, info_ptr
);
19261 else if (form
== DW_FORM_strx4
)
19263 str_index
= read_4_bytes (abfd
, info_ptr
);
19268 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19269 info_ptr
+= bytes_read
;
19271 *need_reprocess
= true;
19272 DW_UNSND (attr
) = str_index
;
19276 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19277 dwarf_form_name (form
),
19278 bfd_get_filename (abfd
));
19282 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19283 attr
->form
= DW_FORM_GNU_ref_alt
;
19285 /* We have seen instances where the compiler tried to emit a byte
19286 size attribute of -1 which ended up being encoded as an unsigned
19287 0xffffffff. Although 0xffffffff is technically a valid size value,
19288 an object of this size seems pretty unlikely so we can relatively
19289 safely treat these cases as if the size attribute was invalid and
19290 treat them as zero by default. */
19291 if (attr
->name
== DW_AT_byte_size
19292 && form
== DW_FORM_data4
19293 && DW_UNSND (attr
) >= 0xffffffff)
19296 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19297 hex_string (DW_UNSND (attr
)));
19298 DW_UNSND (attr
) = 0;
19304 /* Read an attribute described by an abbreviated attribute. */
19306 static const gdb_byte
*
19307 read_attribute (const struct die_reader_specs
*reader
,
19308 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19309 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19311 attr
->name
= abbrev
->name
;
19312 return read_attribute_value (reader
, attr
, abbrev
->form
,
19313 abbrev
->implicit_const
, info_ptr
,
19317 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19319 static const char *
19320 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19321 LONGEST str_offset
)
19323 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19324 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19327 /* Return pointer to string at .debug_str offset as read from BUF.
19328 BUF is assumed to be in a compilation unit described by CU_HEADER.
19329 Return *BYTES_READ_PTR count of bytes read from BUF. */
19331 static const char *
19332 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19333 const gdb_byte
*buf
,
19334 const struct comp_unit_head
*cu_header
,
19335 unsigned int *bytes_read_ptr
)
19337 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19339 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19345 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19346 const struct comp_unit_head
*cu_header
,
19347 unsigned int *bytes_read_ptr
)
19349 bfd
*abfd
= objfile
->obfd
;
19350 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19352 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19355 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19356 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19357 ADDR_SIZE is the size of addresses from the CU header. */
19360 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19361 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19364 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19365 bfd
*abfd
= objfile
->obfd
;
19366 const gdb_byte
*info_ptr
;
19367 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19369 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19370 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19371 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19372 objfile_name (objfile
));
19373 if (addr_base_or_zero
+ addr_index
* addr_size
19374 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19375 error (_("DW_FORM_addr_index pointing outside of "
19376 ".debug_addr section [in module %s]"),
19377 objfile_name (objfile
));
19378 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19379 + addr_base_or_zero
+ addr_index
* addr_size
);
19380 if (addr_size
== 4)
19381 return bfd_get_32 (abfd
, info_ptr
);
19383 return bfd_get_64 (abfd
, info_ptr
);
19386 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19389 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19391 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19392 cu
->addr_base
, cu
->header
.addr_size
);
19395 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19398 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19399 unsigned int *bytes_read
)
19401 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19402 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19404 return read_addr_index (cu
, addr_index
);
19410 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19411 dwarf2_per_objfile
*dwarf2_per_objfile
,
19412 unsigned int addr_index
)
19414 struct dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
19415 gdb::optional
<ULONGEST
> addr_base
;
19418 /* We need addr_base and addr_size.
19419 If we don't have PER_CU->cu, we have to get it.
19420 Nasty, but the alternative is storing the needed info in PER_CU,
19421 which at this point doesn't seem justified: it's not clear how frequently
19422 it would get used and it would increase the size of every PER_CU.
19423 Entry points like dwarf2_per_cu_addr_size do a similar thing
19424 so we're not in uncharted territory here.
19425 Alas we need to be a bit more complicated as addr_base is contained
19428 We don't need to read the entire CU(/TU).
19429 We just need the header and top level die.
19431 IWBN to use the aging mechanism to let us lazily later discard the CU.
19432 For now we skip this optimization. */
19436 addr_base
= cu
->addr_base
;
19437 addr_size
= cu
->header
.addr_size
;
19441 cutu_reader
reader (per_cu
, dwarf2_per_objfile
, nullptr, nullptr, false);
19442 addr_base
= reader
.cu
->addr_base
;
19443 addr_size
= reader
.cu
->header
.addr_size
;
19446 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19450 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19451 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19454 static const char *
19455 read_str_index (struct dwarf2_cu
*cu
,
19456 struct dwarf2_section_info
*str_section
,
19457 struct dwarf2_section_info
*str_offsets_section
,
19458 ULONGEST str_offsets_base
, ULONGEST str_index
)
19460 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19462 const char *objf_name
= objfile_name (objfile
);
19463 bfd
*abfd
= objfile
->obfd
;
19464 const gdb_byte
*info_ptr
;
19465 ULONGEST str_offset
;
19466 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19468 str_section
->read (objfile
);
19469 str_offsets_section
->read (objfile
);
19470 if (str_section
->buffer
== NULL
)
19471 error (_("%s used without %s section"
19472 " in CU at offset %s [in module %s]"),
19473 form_name
, str_section
->get_name (),
19474 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19475 if (str_offsets_section
->buffer
== NULL
)
19476 error (_("%s used without %s section"
19477 " in CU at offset %s [in module %s]"),
19478 form_name
, str_section
->get_name (),
19479 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19480 info_ptr
= (str_offsets_section
->buffer
19482 + str_index
* cu
->header
.offset_size
);
19483 if (cu
->header
.offset_size
== 4)
19484 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19486 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19487 if (str_offset
>= str_section
->size
)
19488 error (_("Offset from %s pointing outside of"
19489 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19490 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19491 return (const char *) (str_section
->buffer
+ str_offset
);
19494 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19496 static const char *
19497 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19499 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19500 ? reader
->cu
->header
.addr_size
: 0;
19501 return read_str_index (reader
->cu
,
19502 &reader
->dwo_file
->sections
.str
,
19503 &reader
->dwo_file
->sections
.str_offsets
,
19504 str_offsets_base
, str_index
);
19507 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19509 static const char *
19510 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19512 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19513 const char *objf_name
= objfile_name (objfile
);
19514 static const char form_name
[] = "DW_FORM_GNU_str_index";
19515 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19517 if (!cu
->str_offsets_base
.has_value ())
19518 error (_("%s used in Fission stub without %s"
19519 " in CU at offset 0x%lx [in module %s]"),
19520 form_name
, str_offsets_attr_name
,
19521 (long) cu
->header
.offset_size
, objf_name
);
19523 return read_str_index (cu
,
19524 &cu
->per_objfile
->per_bfd
->str
,
19525 &cu
->per_objfile
->per_bfd
->str_offsets
,
19526 *cu
->str_offsets_base
, str_index
);
19529 /* Return the length of an LEB128 number in BUF. */
19532 leb128_size (const gdb_byte
*buf
)
19534 const gdb_byte
*begin
= buf
;
19540 if ((byte
& 128) == 0)
19541 return buf
- begin
;
19546 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19555 cu
->language
= language_c
;
19558 case DW_LANG_C_plus_plus
:
19559 case DW_LANG_C_plus_plus_11
:
19560 case DW_LANG_C_plus_plus_14
:
19561 cu
->language
= language_cplus
;
19564 cu
->language
= language_d
;
19566 case DW_LANG_Fortran77
:
19567 case DW_LANG_Fortran90
:
19568 case DW_LANG_Fortran95
:
19569 case DW_LANG_Fortran03
:
19570 case DW_LANG_Fortran08
:
19571 cu
->language
= language_fortran
;
19574 cu
->language
= language_go
;
19576 case DW_LANG_Mips_Assembler
:
19577 cu
->language
= language_asm
;
19579 case DW_LANG_Ada83
:
19580 case DW_LANG_Ada95
:
19581 cu
->language
= language_ada
;
19583 case DW_LANG_Modula2
:
19584 cu
->language
= language_m2
;
19586 case DW_LANG_Pascal83
:
19587 cu
->language
= language_pascal
;
19590 cu
->language
= language_objc
;
19593 case DW_LANG_Rust_old
:
19594 cu
->language
= language_rust
;
19596 case DW_LANG_Cobol74
:
19597 case DW_LANG_Cobol85
:
19599 cu
->language
= language_minimal
;
19602 cu
->language_defn
= language_def (cu
->language
);
19605 /* Return the named attribute or NULL if not there. */
19607 static struct attribute
*
19608 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19613 struct attribute
*spec
= NULL
;
19615 for (i
= 0; i
< die
->num_attrs
; ++i
)
19617 if (die
->attrs
[i
].name
== name
)
19618 return &die
->attrs
[i
];
19619 if (die
->attrs
[i
].name
== DW_AT_specification
19620 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19621 spec
= &die
->attrs
[i
];
19627 die
= follow_die_ref (die
, spec
, &cu
);
19633 /* Return the string associated with a string-typed attribute, or NULL if it
19634 is either not found or is of an incorrect type. */
19636 static const char *
19637 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19639 struct attribute
*attr
;
19640 const char *str
= NULL
;
19642 attr
= dwarf2_attr (die
, name
, cu
);
19646 str
= attr
->value_as_string ();
19647 if (str
== nullptr)
19648 complaint (_("string type expected for attribute %s for "
19649 "DIE at %s in module %s"),
19650 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19651 objfile_name (cu
->per_objfile
->objfile
));
19657 /* Return the dwo name or NULL if not present. If present, it is in either
19658 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19659 static const char *
19660 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19662 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19663 if (dwo_name
== nullptr)
19664 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19668 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19669 and holds a non-zero value. This function should only be used for
19670 DW_FORM_flag or DW_FORM_flag_present attributes. */
19673 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19675 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19677 return (attr
&& DW_UNSND (attr
));
19681 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19683 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19684 which value is non-zero. However, we have to be careful with
19685 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19686 (via dwarf2_flag_true_p) follows this attribute. So we may
19687 end up accidently finding a declaration attribute that belongs
19688 to a different DIE referenced by the specification attribute,
19689 even though the given DIE does not have a declaration attribute. */
19690 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19691 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19694 /* Return the die giving the specification for DIE, if there is
19695 one. *SPEC_CU is the CU containing DIE on input, and the CU
19696 containing the return value on output. If there is no
19697 specification, but there is an abstract origin, that is
19700 static struct die_info
*
19701 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19703 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19706 if (spec_attr
== NULL
)
19707 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19709 if (spec_attr
== NULL
)
19712 return follow_die_ref (die
, spec_attr
, spec_cu
);
19715 /* Stub for free_line_header to match void * callback types. */
19718 free_line_header_voidp (void *arg
)
19720 struct line_header
*lh
= (struct line_header
*) arg
;
19725 /* A convenience function to find the proper .debug_line section for a CU. */
19727 static struct dwarf2_section_info
*
19728 get_debug_line_section (struct dwarf2_cu
*cu
)
19730 struct dwarf2_section_info
*section
;
19731 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19733 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19735 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19736 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19737 else if (cu
->per_cu
->is_dwz
)
19739 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19741 section
= &dwz
->line
;
19744 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19749 /* Read the statement program header starting at OFFSET in
19750 .debug_line, or .debug_line.dwo. Return a pointer
19751 to a struct line_header, allocated using xmalloc.
19752 Returns NULL if there is a problem reading the header, e.g., if it
19753 has a version we don't understand.
19755 NOTE: the strings in the include directory and file name tables of
19756 the returned object point into the dwarf line section buffer,
19757 and must not be freed. */
19759 static line_header_up
19760 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19762 struct dwarf2_section_info
*section
;
19763 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19765 section
= get_debug_line_section (cu
);
19766 section
->read (dwarf2_per_objfile
->objfile
);
19767 if (section
->buffer
== NULL
)
19769 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19770 complaint (_("missing .debug_line.dwo section"));
19772 complaint (_("missing .debug_line section"));
19776 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19777 dwarf2_per_objfile
, section
,
19781 /* Subroutine of dwarf_decode_lines to simplify it.
19782 Return the file name of the psymtab for the given file_entry.
19783 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19784 If space for the result is malloc'd, *NAME_HOLDER will be set.
19785 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19787 static const char *
19788 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19789 const dwarf2_psymtab
*pst
,
19790 const char *comp_dir
,
19791 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19793 const char *include_name
= fe
.name
;
19794 const char *include_name_to_compare
= include_name
;
19795 const char *pst_filename
;
19798 const char *dir_name
= fe
.include_dir (lh
);
19800 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19801 if (!IS_ABSOLUTE_PATH (include_name
)
19802 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19804 /* Avoid creating a duplicate psymtab for PST.
19805 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19806 Before we do the comparison, however, we need to account
19807 for DIR_NAME and COMP_DIR.
19808 First prepend dir_name (if non-NULL). If we still don't
19809 have an absolute path prepend comp_dir (if non-NULL).
19810 However, the directory we record in the include-file's
19811 psymtab does not contain COMP_DIR (to match the
19812 corresponding symtab(s)).
19817 bash$ gcc -g ./hello.c
19818 include_name = "hello.c"
19820 DW_AT_comp_dir = comp_dir = "/tmp"
19821 DW_AT_name = "./hello.c"
19825 if (dir_name
!= NULL
)
19827 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19828 include_name
, (char *) NULL
));
19829 include_name
= name_holder
->get ();
19830 include_name_to_compare
= include_name
;
19832 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19834 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19835 include_name
, (char *) NULL
));
19836 include_name_to_compare
= hold_compare
.get ();
19840 pst_filename
= pst
->filename
;
19841 gdb::unique_xmalloc_ptr
<char> copied_name
;
19842 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19844 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19845 pst_filename
, (char *) NULL
));
19846 pst_filename
= copied_name
.get ();
19849 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19853 return include_name
;
19856 /* State machine to track the state of the line number program. */
19858 class lnp_state_machine
19861 /* Initialize a machine state for the start of a line number
19863 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19864 bool record_lines_p
);
19866 file_entry
*current_file ()
19868 /* lh->file_names is 0-based, but the file name numbers in the
19869 statement program are 1-based. */
19870 return m_line_header
->file_name_at (m_file
);
19873 /* Record the line in the state machine. END_SEQUENCE is true if
19874 we're processing the end of a sequence. */
19875 void record_line (bool end_sequence
);
19877 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19878 nop-out rest of the lines in this sequence. */
19879 void check_line_address (struct dwarf2_cu
*cu
,
19880 const gdb_byte
*line_ptr
,
19881 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19883 void handle_set_discriminator (unsigned int discriminator
)
19885 m_discriminator
= discriminator
;
19886 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19889 /* Handle DW_LNE_set_address. */
19890 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19893 address
+= baseaddr
;
19894 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19897 /* Handle DW_LNS_advance_pc. */
19898 void handle_advance_pc (CORE_ADDR adjust
);
19900 /* Handle a special opcode. */
19901 void handle_special_opcode (unsigned char op_code
);
19903 /* Handle DW_LNS_advance_line. */
19904 void handle_advance_line (int line_delta
)
19906 advance_line (line_delta
);
19909 /* Handle DW_LNS_set_file. */
19910 void handle_set_file (file_name_index file
);
19912 /* Handle DW_LNS_negate_stmt. */
19913 void handle_negate_stmt ()
19915 m_is_stmt
= !m_is_stmt
;
19918 /* Handle DW_LNS_const_add_pc. */
19919 void handle_const_add_pc ();
19921 /* Handle DW_LNS_fixed_advance_pc. */
19922 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19924 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19928 /* Handle DW_LNS_copy. */
19929 void handle_copy ()
19931 record_line (false);
19932 m_discriminator
= 0;
19935 /* Handle DW_LNE_end_sequence. */
19936 void handle_end_sequence ()
19938 m_currently_recording_lines
= true;
19942 /* Advance the line by LINE_DELTA. */
19943 void advance_line (int line_delta
)
19945 m_line
+= line_delta
;
19947 if (line_delta
!= 0)
19948 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19951 struct dwarf2_cu
*m_cu
;
19953 gdbarch
*m_gdbarch
;
19955 /* True if we're recording lines.
19956 Otherwise we're building partial symtabs and are just interested in
19957 finding include files mentioned by the line number program. */
19958 bool m_record_lines_p
;
19960 /* The line number header. */
19961 line_header
*m_line_header
;
19963 /* These are part of the standard DWARF line number state machine,
19964 and initialized according to the DWARF spec. */
19966 unsigned char m_op_index
= 0;
19967 /* The line table index of the current file. */
19968 file_name_index m_file
= 1;
19969 unsigned int m_line
= 1;
19971 /* These are initialized in the constructor. */
19973 CORE_ADDR m_address
;
19975 unsigned int m_discriminator
;
19977 /* Additional bits of state we need to track. */
19979 /* The last file that we called dwarf2_start_subfile for.
19980 This is only used for TLLs. */
19981 unsigned int m_last_file
= 0;
19982 /* The last file a line number was recorded for. */
19983 struct subfile
*m_last_subfile
= NULL
;
19985 /* When true, record the lines we decode. */
19986 bool m_currently_recording_lines
= false;
19988 /* The last line number that was recorded, used to coalesce
19989 consecutive entries for the same line. This can happen, for
19990 example, when discriminators are present. PR 17276. */
19991 unsigned int m_last_line
= 0;
19992 bool m_line_has_non_zero_discriminator
= false;
19996 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19998 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19999 / m_line_header
->maximum_ops_per_instruction
)
20000 * m_line_header
->minimum_instruction_length
);
20001 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20002 m_op_index
= ((m_op_index
+ adjust
)
20003 % m_line_header
->maximum_ops_per_instruction
);
20007 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20009 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20010 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20011 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20012 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20013 / m_line_header
->maximum_ops_per_instruction
)
20014 * m_line_header
->minimum_instruction_length
);
20015 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20016 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20017 % m_line_header
->maximum_ops_per_instruction
);
20019 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20020 advance_line (line_delta
);
20021 record_line (false);
20022 m_discriminator
= 0;
20026 lnp_state_machine::handle_set_file (file_name_index file
)
20030 const file_entry
*fe
= current_file ();
20032 dwarf2_debug_line_missing_file_complaint ();
20033 else if (m_record_lines_p
)
20035 const char *dir
= fe
->include_dir (m_line_header
);
20037 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20038 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20039 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20044 lnp_state_machine::handle_const_add_pc ()
20047 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20050 = (((m_op_index
+ adjust
)
20051 / m_line_header
->maximum_ops_per_instruction
)
20052 * m_line_header
->minimum_instruction_length
);
20054 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20055 m_op_index
= ((m_op_index
+ adjust
)
20056 % m_line_header
->maximum_ops_per_instruction
);
20059 /* Return non-zero if we should add LINE to the line number table.
20060 LINE is the line to add, LAST_LINE is the last line that was added,
20061 LAST_SUBFILE is the subfile for LAST_LINE.
20062 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20063 had a non-zero discriminator.
20065 We have to be careful in the presence of discriminators.
20066 E.g., for this line:
20068 for (i = 0; i < 100000; i++);
20070 clang can emit four line number entries for that one line,
20071 each with a different discriminator.
20072 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20074 However, we want gdb to coalesce all four entries into one.
20075 Otherwise the user could stepi into the middle of the line and
20076 gdb would get confused about whether the pc really was in the
20077 middle of the line.
20079 Things are further complicated by the fact that two consecutive
20080 line number entries for the same line is a heuristic used by gcc
20081 to denote the end of the prologue. So we can't just discard duplicate
20082 entries, we have to be selective about it. The heuristic we use is
20083 that we only collapse consecutive entries for the same line if at least
20084 one of those entries has a non-zero discriminator. PR 17276.
20086 Note: Addresses in the line number state machine can never go backwards
20087 within one sequence, thus this coalescing is ok. */
20090 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20091 unsigned int line
, unsigned int last_line
,
20092 int line_has_non_zero_discriminator
,
20093 struct subfile
*last_subfile
)
20095 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20097 if (line
!= last_line
)
20099 /* Same line for the same file that we've seen already.
20100 As a last check, for pr 17276, only record the line if the line
20101 has never had a non-zero discriminator. */
20102 if (!line_has_non_zero_discriminator
)
20107 /* Use the CU's builder to record line number LINE beginning at
20108 address ADDRESS in the line table of subfile SUBFILE. */
20111 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20112 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20113 struct dwarf2_cu
*cu
)
20115 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20117 if (dwarf_line_debug
)
20119 fprintf_unfiltered (gdb_stdlog
,
20120 "Recording line %u, file %s, address %s\n",
20121 line
, lbasename (subfile
->name
),
20122 paddress (gdbarch
, address
));
20126 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20129 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20130 Mark the end of a set of line number records.
20131 The arguments are the same as for dwarf_record_line_1.
20132 If SUBFILE is NULL the request is ignored. */
20135 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20136 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20138 if (subfile
== NULL
)
20141 if (dwarf_line_debug
)
20143 fprintf_unfiltered (gdb_stdlog
,
20144 "Finishing current line, file %s, address %s\n",
20145 lbasename (subfile
->name
),
20146 paddress (gdbarch
, address
));
20149 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20153 lnp_state_machine::record_line (bool end_sequence
)
20155 if (dwarf_line_debug
)
20157 fprintf_unfiltered (gdb_stdlog
,
20158 "Processing actual line %u: file %u,"
20159 " address %s, is_stmt %u, discrim %u%s\n",
20161 paddress (m_gdbarch
, m_address
),
20162 m_is_stmt
, m_discriminator
,
20163 (end_sequence
? "\t(end sequence)" : ""));
20166 file_entry
*fe
= current_file ();
20169 dwarf2_debug_line_missing_file_complaint ();
20170 /* For now we ignore lines not starting on an instruction boundary.
20171 But not when processing end_sequence for compatibility with the
20172 previous version of the code. */
20173 else if (m_op_index
== 0 || end_sequence
)
20175 fe
->included_p
= 1;
20176 if (m_record_lines_p
)
20178 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20181 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20182 m_currently_recording_lines
? m_cu
: nullptr);
20187 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20189 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20190 m_line_has_non_zero_discriminator
,
20193 buildsym_compunit
*builder
= m_cu
->get_builder ();
20194 dwarf_record_line_1 (m_gdbarch
,
20195 builder
->get_current_subfile (),
20196 m_line
, m_address
, is_stmt
,
20197 m_currently_recording_lines
? m_cu
: nullptr);
20199 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20200 m_last_line
= m_line
;
20206 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20207 line_header
*lh
, bool record_lines_p
)
20211 m_record_lines_p
= record_lines_p
;
20212 m_line_header
= lh
;
20214 m_currently_recording_lines
= true;
20216 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20217 was a line entry for it so that the backend has a chance to adjust it
20218 and also record it in case it needs it. This is currently used by MIPS
20219 code, cf. `mips_adjust_dwarf2_line'. */
20220 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20221 m_is_stmt
= lh
->default_is_stmt
;
20222 m_discriminator
= 0;
20226 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20227 const gdb_byte
*line_ptr
,
20228 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20230 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20231 the pc range of the CU. However, we restrict the test to only ADDRESS
20232 values of zero to preserve GDB's previous behaviour which is to handle
20233 the specific case of a function being GC'd by the linker. */
20235 if (address
== 0 && address
< unrelocated_lowpc
)
20237 /* This line table is for a function which has been
20238 GCd by the linker. Ignore it. PR gdb/12528 */
20240 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20241 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20243 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20244 line_offset
, objfile_name (objfile
));
20245 m_currently_recording_lines
= false;
20246 /* Note: m_currently_recording_lines is left as false until we see
20247 DW_LNE_end_sequence. */
20251 /* Subroutine of dwarf_decode_lines to simplify it.
20252 Process the line number information in LH.
20253 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20254 program in order to set included_p for every referenced header. */
20257 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20258 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20260 const gdb_byte
*line_ptr
, *extended_end
;
20261 const gdb_byte
*line_end
;
20262 unsigned int bytes_read
, extended_len
;
20263 unsigned char op_code
, extended_op
;
20264 CORE_ADDR baseaddr
;
20265 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20266 bfd
*abfd
= objfile
->obfd
;
20267 struct gdbarch
*gdbarch
= objfile
->arch ();
20268 /* True if we're recording line info (as opposed to building partial
20269 symtabs and just interested in finding include files mentioned by
20270 the line number program). */
20271 bool record_lines_p
= !decode_for_pst_p
;
20273 baseaddr
= objfile
->text_section_offset ();
20275 line_ptr
= lh
->statement_program_start
;
20276 line_end
= lh
->statement_program_end
;
20278 /* Read the statement sequences until there's nothing left. */
20279 while (line_ptr
< line_end
)
20281 /* The DWARF line number program state machine. Reset the state
20282 machine at the start of each sequence. */
20283 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20284 bool end_sequence
= false;
20286 if (record_lines_p
)
20288 /* Start a subfile for the current file of the state
20290 const file_entry
*fe
= state_machine
.current_file ();
20293 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20296 /* Decode the table. */
20297 while (line_ptr
< line_end
&& !end_sequence
)
20299 op_code
= read_1_byte (abfd
, line_ptr
);
20302 if (op_code
>= lh
->opcode_base
)
20304 /* Special opcode. */
20305 state_machine
.handle_special_opcode (op_code
);
20307 else switch (op_code
)
20309 case DW_LNS_extended_op
:
20310 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20312 line_ptr
+= bytes_read
;
20313 extended_end
= line_ptr
+ extended_len
;
20314 extended_op
= read_1_byte (abfd
, line_ptr
);
20316 switch (extended_op
)
20318 case DW_LNE_end_sequence
:
20319 state_machine
.handle_end_sequence ();
20320 end_sequence
= true;
20322 case DW_LNE_set_address
:
20325 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20326 line_ptr
+= bytes_read
;
20328 state_machine
.check_line_address (cu
, line_ptr
,
20329 lowpc
- baseaddr
, address
);
20330 state_machine
.handle_set_address (baseaddr
, address
);
20333 case DW_LNE_define_file
:
20335 const char *cur_file
;
20336 unsigned int mod_time
, length
;
20339 cur_file
= read_direct_string (abfd
, line_ptr
,
20341 line_ptr
+= bytes_read
;
20342 dindex
= (dir_index
)
20343 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20344 line_ptr
+= bytes_read
;
20346 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20347 line_ptr
+= bytes_read
;
20349 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20350 line_ptr
+= bytes_read
;
20351 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20354 case DW_LNE_set_discriminator
:
20356 /* The discriminator is not interesting to the
20357 debugger; just ignore it. We still need to
20358 check its value though:
20359 if there are consecutive entries for the same
20360 (non-prologue) line we want to coalesce them.
20363 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20364 line_ptr
+= bytes_read
;
20366 state_machine
.handle_set_discriminator (discr
);
20370 complaint (_("mangled .debug_line section"));
20373 /* Make sure that we parsed the extended op correctly. If e.g.
20374 we expected a different address size than the producer used,
20375 we may have read the wrong number of bytes. */
20376 if (line_ptr
!= extended_end
)
20378 complaint (_("mangled .debug_line section"));
20383 state_machine
.handle_copy ();
20385 case DW_LNS_advance_pc
:
20388 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20389 line_ptr
+= bytes_read
;
20391 state_machine
.handle_advance_pc (adjust
);
20394 case DW_LNS_advance_line
:
20397 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20398 line_ptr
+= bytes_read
;
20400 state_machine
.handle_advance_line (line_delta
);
20403 case DW_LNS_set_file
:
20405 file_name_index file
20406 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20408 line_ptr
+= bytes_read
;
20410 state_machine
.handle_set_file (file
);
20413 case DW_LNS_set_column
:
20414 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20415 line_ptr
+= bytes_read
;
20417 case DW_LNS_negate_stmt
:
20418 state_machine
.handle_negate_stmt ();
20420 case DW_LNS_set_basic_block
:
20422 /* Add to the address register of the state machine the
20423 address increment value corresponding to special opcode
20424 255. I.e., this value is scaled by the minimum
20425 instruction length since special opcode 255 would have
20426 scaled the increment. */
20427 case DW_LNS_const_add_pc
:
20428 state_machine
.handle_const_add_pc ();
20430 case DW_LNS_fixed_advance_pc
:
20432 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20435 state_machine
.handle_fixed_advance_pc (addr_adj
);
20440 /* Unknown standard opcode, ignore it. */
20443 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20445 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20446 line_ptr
+= bytes_read
;
20453 dwarf2_debug_line_missing_end_sequence_complaint ();
20455 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20456 in which case we still finish recording the last line). */
20457 state_machine
.record_line (true);
20461 /* Decode the Line Number Program (LNP) for the given line_header
20462 structure and CU. The actual information extracted and the type
20463 of structures created from the LNP depends on the value of PST.
20465 1. If PST is NULL, then this procedure uses the data from the program
20466 to create all necessary symbol tables, and their linetables.
20468 2. If PST is not NULL, this procedure reads the program to determine
20469 the list of files included by the unit represented by PST, and
20470 builds all the associated partial symbol tables.
20472 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20473 It is used for relative paths in the line table.
20474 NOTE: When processing partial symtabs (pst != NULL),
20475 comp_dir == pst->dirname.
20477 NOTE: It is important that psymtabs have the same file name (via strcmp)
20478 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20479 symtab we don't use it in the name of the psymtabs we create.
20480 E.g. expand_line_sal requires this when finding psymtabs to expand.
20481 A good testcase for this is mb-inline.exp.
20483 LOWPC is the lowest address in CU (or 0 if not known).
20485 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20486 for its PC<->lines mapping information. Otherwise only the filename
20487 table is read in. */
20490 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20491 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20492 CORE_ADDR lowpc
, int decode_mapping
)
20494 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20495 const int decode_for_pst_p
= (pst
!= NULL
);
20497 if (decode_mapping
)
20498 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20500 if (decode_for_pst_p
)
20502 /* Now that we're done scanning the Line Header Program, we can
20503 create the psymtab of each included file. */
20504 for (auto &file_entry
: lh
->file_names ())
20505 if (file_entry
.included_p
== 1)
20507 gdb::unique_xmalloc_ptr
<char> name_holder
;
20508 const char *include_name
=
20509 psymtab_include_file_name (lh
, file_entry
, pst
,
20510 comp_dir
, &name_holder
);
20511 if (include_name
!= NULL
)
20512 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20517 /* Make sure a symtab is created for every file, even files
20518 which contain only variables (i.e. no code with associated
20520 buildsym_compunit
*builder
= cu
->get_builder ();
20521 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20523 for (auto &fe
: lh
->file_names ())
20525 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20526 if (builder
->get_current_subfile ()->symtab
== NULL
)
20528 builder
->get_current_subfile ()->symtab
20529 = allocate_symtab (cust
,
20530 builder
->get_current_subfile ()->name
);
20532 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20537 /* Start a subfile for DWARF. FILENAME is the name of the file and
20538 DIRNAME the name of the source directory which contains FILENAME
20539 or NULL if not known.
20540 This routine tries to keep line numbers from identical absolute and
20541 relative file names in a common subfile.
20543 Using the `list' example from the GDB testsuite, which resides in
20544 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20545 of /srcdir/list0.c yields the following debugging information for list0.c:
20547 DW_AT_name: /srcdir/list0.c
20548 DW_AT_comp_dir: /compdir
20549 files.files[0].name: list0.h
20550 files.files[0].dir: /srcdir
20551 files.files[1].name: list0.c
20552 files.files[1].dir: /srcdir
20554 The line number information for list0.c has to end up in a single
20555 subfile, so that `break /srcdir/list0.c:1' works as expected.
20556 start_subfile will ensure that this happens provided that we pass the
20557 concatenation of files.files[1].dir and files.files[1].name as the
20561 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20562 const char *dirname
)
20564 gdb::unique_xmalloc_ptr
<char> copy
;
20566 /* In order not to lose the line information directory,
20567 we concatenate it to the filename when it makes sense.
20568 Note that the Dwarf3 standard says (speaking of filenames in line
20569 information): ``The directory index is ignored for file names
20570 that represent full path names''. Thus ignoring dirname in the
20571 `else' branch below isn't an issue. */
20573 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20575 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20576 filename
= copy
.get ();
20579 cu
->get_builder ()->start_subfile (filename
);
20582 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20583 buildsym_compunit constructor. */
20585 struct compunit_symtab
*
20586 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20589 gdb_assert (m_builder
== nullptr);
20591 m_builder
.reset (new struct buildsym_compunit
20592 (this->per_objfile
->objfile
,
20593 name
, comp_dir
, language
, low_pc
));
20595 list_in_scope
= get_builder ()->get_file_symbols ();
20597 get_builder ()->record_debugformat ("DWARF 2");
20598 get_builder ()->record_producer (producer
);
20600 processing_has_namespace_info
= false;
20602 return get_builder ()->get_compunit_symtab ();
20606 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20607 struct dwarf2_cu
*cu
)
20609 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20610 struct comp_unit_head
*cu_header
= &cu
->header
;
20612 /* NOTE drow/2003-01-30: There used to be a comment and some special
20613 code here to turn a symbol with DW_AT_external and a
20614 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20615 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20616 with some versions of binutils) where shared libraries could have
20617 relocations against symbols in their debug information - the
20618 minimal symbol would have the right address, but the debug info
20619 would not. It's no longer necessary, because we will explicitly
20620 apply relocations when we read in the debug information now. */
20622 /* A DW_AT_location attribute with no contents indicates that a
20623 variable has been optimized away. */
20624 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20626 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20630 /* Handle one degenerate form of location expression specially, to
20631 preserve GDB's previous behavior when section offsets are
20632 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20633 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20635 if (attr
->form_is_block ()
20636 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20637 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20638 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20639 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20640 && (DW_BLOCK (attr
)->size
20641 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20643 unsigned int dummy
;
20645 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20646 SET_SYMBOL_VALUE_ADDRESS
20647 (sym
, cu
->header
.read_address (objfile
->obfd
,
20648 DW_BLOCK (attr
)->data
+ 1,
20651 SET_SYMBOL_VALUE_ADDRESS
20652 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20654 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20655 fixup_symbol_section (sym
, objfile
);
20656 SET_SYMBOL_VALUE_ADDRESS
20658 SYMBOL_VALUE_ADDRESS (sym
)
20659 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20663 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20664 expression evaluator, and use LOC_COMPUTED only when necessary
20665 (i.e. when the value of a register or memory location is
20666 referenced, or a thread-local block, etc.). Then again, it might
20667 not be worthwhile. I'm assuming that it isn't unless performance
20668 or memory numbers show me otherwise. */
20670 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20672 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20673 cu
->has_loclist
= true;
20676 /* Given a pointer to a DWARF information entry, figure out if we need
20677 to make a symbol table entry for it, and if so, create a new entry
20678 and return a pointer to it.
20679 If TYPE is NULL, determine symbol type from the die, otherwise
20680 used the passed type.
20681 If SPACE is not NULL, use it to hold the new symbol. If it is
20682 NULL, allocate a new symbol on the objfile's obstack. */
20684 static struct symbol
*
20685 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20686 struct symbol
*space
)
20688 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20689 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20690 struct gdbarch
*gdbarch
= objfile
->arch ();
20691 struct symbol
*sym
= NULL
;
20693 struct attribute
*attr
= NULL
;
20694 struct attribute
*attr2
= NULL
;
20695 CORE_ADDR baseaddr
;
20696 struct pending
**list_to_add
= NULL
;
20698 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20700 baseaddr
= objfile
->text_section_offset ();
20702 name
= dwarf2_name (die
, cu
);
20705 int suppress_add
= 0;
20710 sym
= new (&objfile
->objfile_obstack
) symbol
;
20711 OBJSTAT (objfile
, n_syms
++);
20713 /* Cache this symbol's name and the name's demangled form (if any). */
20714 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20715 /* Fortran does not have mangling standard and the mangling does differ
20716 between gfortran, iFort etc. */
20717 const char *physname
20718 = (cu
->language
== language_fortran
20719 ? dwarf2_full_name (name
, die
, cu
)
20720 : dwarf2_physname (name
, die
, cu
));
20721 const char *linkagename
= dw2_linkage_name (die
, cu
);
20723 if (linkagename
== nullptr || cu
->language
== language_ada
)
20724 sym
->set_linkage_name (physname
);
20727 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20728 sym
->set_linkage_name (linkagename
);
20731 /* Default assumptions.
20732 Use the passed type or decode it from the die. */
20733 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20734 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20736 SYMBOL_TYPE (sym
) = type
;
20738 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20739 attr
= dwarf2_attr (die
,
20740 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20742 if (attr
!= nullptr)
20744 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20747 attr
= dwarf2_attr (die
,
20748 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20750 if (attr
!= nullptr)
20752 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20753 struct file_entry
*fe
;
20755 if (cu
->line_header
!= NULL
)
20756 fe
= cu
->line_header
->file_name_at (file_index
);
20761 complaint (_("file index out of range"));
20763 symbol_set_symtab (sym
, fe
->symtab
);
20769 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20770 if (attr
!= nullptr)
20774 addr
= attr
->value_as_address ();
20775 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20776 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20778 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20779 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20780 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20781 add_symbol_to_list (sym
, cu
->list_in_scope
);
20783 case DW_TAG_subprogram
:
20784 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20786 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20787 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20788 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20789 || cu
->language
== language_ada
20790 || cu
->language
== language_fortran
)
20792 /* Subprograms marked external are stored as a global symbol.
20793 Ada and Fortran subprograms, whether marked external or
20794 not, are always stored as a global symbol, because we want
20795 to be able to access them globally. For instance, we want
20796 to be able to break on a nested subprogram without having
20797 to specify the context. */
20798 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20802 list_to_add
= cu
->list_in_scope
;
20805 case DW_TAG_inlined_subroutine
:
20806 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20808 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20809 SYMBOL_INLINED (sym
) = 1;
20810 list_to_add
= cu
->list_in_scope
;
20812 case DW_TAG_template_value_param
:
20814 /* Fall through. */
20815 case DW_TAG_constant
:
20816 case DW_TAG_variable
:
20817 case DW_TAG_member
:
20818 /* Compilation with minimal debug info may result in
20819 variables with missing type entries. Change the
20820 misleading `void' type to something sensible. */
20821 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20822 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20824 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20825 /* In the case of DW_TAG_member, we should only be called for
20826 static const members. */
20827 if (die
->tag
== DW_TAG_member
)
20829 /* dwarf2_add_field uses die_is_declaration,
20830 so we do the same. */
20831 gdb_assert (die_is_declaration (die
, cu
));
20834 if (attr
!= nullptr)
20836 dwarf2_const_value (attr
, sym
, cu
);
20837 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20840 if (attr2
&& (DW_UNSND (attr2
) != 0))
20841 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20843 list_to_add
= cu
->list_in_scope
;
20847 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20848 if (attr
!= nullptr)
20850 var_decode_location (attr
, sym
, cu
);
20851 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20853 /* Fortran explicitly imports any global symbols to the local
20854 scope by DW_TAG_common_block. */
20855 if (cu
->language
== language_fortran
&& die
->parent
20856 && die
->parent
->tag
== DW_TAG_common_block
)
20859 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20860 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20861 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20863 /* When a static variable is eliminated by the linker,
20864 the corresponding debug information is not stripped
20865 out, but the variable address is set to null;
20866 do not add such variables into symbol table. */
20868 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20870 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20871 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20872 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20874 /* A global static variable might be subject to
20875 copy relocation. We first check for a local
20876 minsym, though, because maybe the symbol was
20877 marked hidden, in which case this would not
20879 bound_minimal_symbol found
20880 = (lookup_minimal_symbol_linkage
20881 (sym
->linkage_name (), objfile
));
20882 if (found
.minsym
!= nullptr)
20883 sym
->maybe_copied
= 1;
20886 /* A variable with DW_AT_external is never static,
20887 but it may be block-scoped. */
20889 = ((cu
->list_in_scope
20890 == cu
->get_builder ()->get_file_symbols ())
20891 ? cu
->get_builder ()->get_global_symbols ()
20892 : cu
->list_in_scope
);
20895 list_to_add
= cu
->list_in_scope
;
20899 /* We do not know the address of this symbol.
20900 If it is an external symbol and we have type information
20901 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20902 The address of the variable will then be determined from
20903 the minimal symbol table whenever the variable is
20905 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20907 /* Fortran explicitly imports any global symbols to the local
20908 scope by DW_TAG_common_block. */
20909 if (cu
->language
== language_fortran
&& die
->parent
20910 && die
->parent
->tag
== DW_TAG_common_block
)
20912 /* SYMBOL_CLASS doesn't matter here because
20913 read_common_block is going to reset it. */
20915 list_to_add
= cu
->list_in_scope
;
20917 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20918 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20920 /* A variable with DW_AT_external is never static, but it
20921 may be block-scoped. */
20923 = ((cu
->list_in_scope
20924 == cu
->get_builder ()->get_file_symbols ())
20925 ? cu
->get_builder ()->get_global_symbols ()
20926 : cu
->list_in_scope
);
20928 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20930 else if (!die_is_declaration (die
, cu
))
20932 /* Use the default LOC_OPTIMIZED_OUT class. */
20933 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20935 list_to_add
= cu
->list_in_scope
;
20939 case DW_TAG_formal_parameter
:
20941 /* If we are inside a function, mark this as an argument. If
20942 not, we might be looking at an argument to an inlined function
20943 when we do not have enough information to show inlined frames;
20944 pretend it's a local variable in that case so that the user can
20946 struct context_stack
*curr
20947 = cu
->get_builder ()->get_current_context_stack ();
20948 if (curr
!= nullptr && curr
->name
!= nullptr)
20949 SYMBOL_IS_ARGUMENT (sym
) = 1;
20950 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20951 if (attr
!= nullptr)
20953 var_decode_location (attr
, sym
, cu
);
20955 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20956 if (attr
!= nullptr)
20958 dwarf2_const_value (attr
, sym
, cu
);
20961 list_to_add
= cu
->list_in_scope
;
20964 case DW_TAG_unspecified_parameters
:
20965 /* From varargs functions; gdb doesn't seem to have any
20966 interest in this information, so just ignore it for now.
20969 case DW_TAG_template_type_param
:
20971 /* Fall through. */
20972 case DW_TAG_class_type
:
20973 case DW_TAG_interface_type
:
20974 case DW_TAG_structure_type
:
20975 case DW_TAG_union_type
:
20976 case DW_TAG_set_type
:
20977 case DW_TAG_enumeration_type
:
20978 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20979 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20982 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20983 really ever be static objects: otherwise, if you try
20984 to, say, break of a class's method and you're in a file
20985 which doesn't mention that class, it won't work unless
20986 the check for all static symbols in lookup_symbol_aux
20987 saves you. See the OtherFileClass tests in
20988 gdb.c++/namespace.exp. */
20992 buildsym_compunit
*builder
= cu
->get_builder ();
20994 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20995 && cu
->language
== language_cplus
20996 ? builder
->get_global_symbols ()
20997 : cu
->list_in_scope
);
20999 /* The semantics of C++ state that "struct foo {
21000 ... }" also defines a typedef for "foo". */
21001 if (cu
->language
== language_cplus
21002 || cu
->language
== language_ada
21003 || cu
->language
== language_d
21004 || cu
->language
== language_rust
)
21006 /* The symbol's name is already allocated along
21007 with this objfile, so we don't need to
21008 duplicate it for the type. */
21009 if (SYMBOL_TYPE (sym
)->name () == 0)
21010 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21015 case DW_TAG_typedef
:
21016 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21017 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21018 list_to_add
= cu
->list_in_scope
;
21020 case DW_TAG_base_type
:
21021 case DW_TAG_subrange_type
:
21022 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21023 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21024 list_to_add
= cu
->list_in_scope
;
21026 case DW_TAG_enumerator
:
21027 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21028 if (attr
!= nullptr)
21030 dwarf2_const_value (attr
, sym
, cu
);
21033 /* NOTE: carlton/2003-11-10: See comment above in the
21034 DW_TAG_class_type, etc. block. */
21037 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21038 && cu
->language
== language_cplus
21039 ? cu
->get_builder ()->get_global_symbols ()
21040 : cu
->list_in_scope
);
21043 case DW_TAG_imported_declaration
:
21044 case DW_TAG_namespace
:
21045 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21046 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21048 case DW_TAG_module
:
21049 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21050 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21051 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21053 case DW_TAG_common_block
:
21054 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21055 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21056 add_symbol_to_list (sym
, cu
->list_in_scope
);
21059 /* Not a tag we recognize. Hopefully we aren't processing
21060 trash data, but since we must specifically ignore things
21061 we don't recognize, there is nothing else we should do at
21063 complaint (_("unsupported tag: '%s'"),
21064 dwarf_tag_name (die
->tag
));
21070 sym
->hash_next
= objfile
->template_symbols
;
21071 objfile
->template_symbols
= sym
;
21072 list_to_add
= NULL
;
21075 if (list_to_add
!= NULL
)
21076 add_symbol_to_list (sym
, list_to_add
);
21078 /* For the benefit of old versions of GCC, check for anonymous
21079 namespaces based on the demangled name. */
21080 if (!cu
->processing_has_namespace_info
21081 && cu
->language
== language_cplus
)
21082 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21087 /* Given an attr with a DW_FORM_dataN value in host byte order,
21088 zero-extend it as appropriate for the symbol's type. The DWARF
21089 standard (v4) is not entirely clear about the meaning of using
21090 DW_FORM_dataN for a constant with a signed type, where the type is
21091 wider than the data. The conclusion of a discussion on the DWARF
21092 list was that this is unspecified. We choose to always zero-extend
21093 because that is the interpretation long in use by GCC. */
21096 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21097 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21099 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21100 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21101 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21102 LONGEST l
= DW_UNSND (attr
);
21104 if (bits
< sizeof (*value
) * 8)
21106 l
&= ((LONGEST
) 1 << bits
) - 1;
21109 else if (bits
== sizeof (*value
) * 8)
21113 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21114 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21121 /* Read a constant value from an attribute. Either set *VALUE, or if
21122 the value does not fit in *VALUE, set *BYTES - either already
21123 allocated on the objfile obstack, or newly allocated on OBSTACK,
21124 or, set *BATON, if we translated the constant to a location
21128 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21129 const char *name
, struct obstack
*obstack
,
21130 struct dwarf2_cu
*cu
,
21131 LONGEST
*value
, const gdb_byte
**bytes
,
21132 struct dwarf2_locexpr_baton
**baton
)
21134 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21135 struct objfile
*objfile
= per_objfile
->objfile
;
21136 struct comp_unit_head
*cu_header
= &cu
->header
;
21137 struct dwarf_block
*blk
;
21138 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21139 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21145 switch (attr
->form
)
21148 case DW_FORM_addrx
:
21149 case DW_FORM_GNU_addr_index
:
21153 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21154 dwarf2_const_value_length_mismatch_complaint (name
,
21155 cu_header
->addr_size
,
21156 TYPE_LENGTH (type
));
21157 /* Symbols of this form are reasonably rare, so we just
21158 piggyback on the existing location code rather than writing
21159 a new implementation of symbol_computed_ops. */
21160 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21161 (*baton
)->per_objfile
= per_objfile
;
21162 (*baton
)->per_cu
= cu
->per_cu
;
21163 gdb_assert ((*baton
)->per_cu
);
21165 (*baton
)->size
= 2 + cu_header
->addr_size
;
21166 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21167 (*baton
)->data
= data
;
21169 data
[0] = DW_OP_addr
;
21170 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21171 byte_order
, DW_ADDR (attr
));
21172 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21175 case DW_FORM_string
:
21178 case DW_FORM_GNU_str_index
:
21179 case DW_FORM_GNU_strp_alt
:
21180 /* DW_STRING is already allocated on the objfile obstack, point
21182 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21184 case DW_FORM_block1
:
21185 case DW_FORM_block2
:
21186 case DW_FORM_block4
:
21187 case DW_FORM_block
:
21188 case DW_FORM_exprloc
:
21189 case DW_FORM_data16
:
21190 blk
= DW_BLOCK (attr
);
21191 if (TYPE_LENGTH (type
) != blk
->size
)
21192 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21193 TYPE_LENGTH (type
));
21194 *bytes
= blk
->data
;
21197 /* The DW_AT_const_value attributes are supposed to carry the
21198 symbol's value "represented as it would be on the target
21199 architecture." By the time we get here, it's already been
21200 converted to host endianness, so we just need to sign- or
21201 zero-extend it as appropriate. */
21202 case DW_FORM_data1
:
21203 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21205 case DW_FORM_data2
:
21206 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21208 case DW_FORM_data4
:
21209 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21211 case DW_FORM_data8
:
21212 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21215 case DW_FORM_sdata
:
21216 case DW_FORM_implicit_const
:
21217 *value
= DW_SND (attr
);
21220 case DW_FORM_udata
:
21221 *value
= DW_UNSND (attr
);
21225 complaint (_("unsupported const value attribute form: '%s'"),
21226 dwarf_form_name (attr
->form
));
21233 /* Copy constant value from an attribute to a symbol. */
21236 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21237 struct dwarf2_cu
*cu
)
21239 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21241 const gdb_byte
*bytes
;
21242 struct dwarf2_locexpr_baton
*baton
;
21244 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21245 sym
->print_name (),
21246 &objfile
->objfile_obstack
, cu
,
21247 &value
, &bytes
, &baton
);
21251 SYMBOL_LOCATION_BATON (sym
) = baton
;
21252 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21254 else if (bytes
!= NULL
)
21256 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21257 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21261 SYMBOL_VALUE (sym
) = value
;
21262 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21266 /* Return the type of the die in question using its DW_AT_type attribute. */
21268 static struct type
*
21269 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21271 struct attribute
*type_attr
;
21273 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21276 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21277 /* A missing DW_AT_type represents a void type. */
21278 return objfile_type (objfile
)->builtin_void
;
21281 return lookup_die_type (die
, type_attr
, cu
);
21284 /* True iff CU's producer generates GNAT Ada auxiliary information
21285 that allows to find parallel types through that information instead
21286 of having to do expensive parallel lookups by type name. */
21289 need_gnat_info (struct dwarf2_cu
*cu
)
21291 /* Assume that the Ada compiler was GNAT, which always produces
21292 the auxiliary information. */
21293 return (cu
->language
== language_ada
);
21296 /* Return the auxiliary type of the die in question using its
21297 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21298 attribute is not present. */
21300 static struct type
*
21301 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21303 struct attribute
*type_attr
;
21305 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21309 return lookup_die_type (die
, type_attr
, cu
);
21312 /* If DIE has a descriptive_type attribute, then set the TYPE's
21313 descriptive type accordingly. */
21316 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21317 struct dwarf2_cu
*cu
)
21319 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21321 if (descriptive_type
)
21323 ALLOCATE_GNAT_AUX_TYPE (type
);
21324 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21328 /* Return the containing type of the die in question using its
21329 DW_AT_containing_type attribute. */
21331 static struct type
*
21332 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21334 struct attribute
*type_attr
;
21335 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21337 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21339 error (_("Dwarf Error: Problem turning containing type into gdb type "
21340 "[in module %s]"), objfile_name (objfile
));
21342 return lookup_die_type (die
, type_attr
, cu
);
21345 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21347 static struct type
*
21348 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21350 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21351 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21354 std::string message
21355 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21356 objfile_name (objfile
),
21357 sect_offset_str (cu
->header
.sect_off
),
21358 sect_offset_str (die
->sect_off
));
21359 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21361 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21364 /* Look up the type of DIE in CU using its type attribute ATTR.
21365 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21366 DW_AT_containing_type.
21367 If there is no type substitute an error marker. */
21369 static struct type
*
21370 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21371 struct dwarf2_cu
*cu
)
21373 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21374 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21375 struct type
*this_type
;
21377 gdb_assert (attr
->name
== DW_AT_type
21378 || attr
->name
== DW_AT_GNAT_descriptive_type
21379 || attr
->name
== DW_AT_containing_type
);
21381 /* First see if we have it cached. */
21383 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21385 struct dwarf2_per_cu_data
*per_cu
;
21386 sect_offset sect_off
= attr
->get_ref_die_offset ();
21388 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21389 dwarf2_per_objfile
);
21390 this_type
= get_die_type_at_offset (sect_off
, per_cu
, dwarf2_per_objfile
);
21392 else if (attr
->form_is_ref ())
21394 sect_offset sect_off
= attr
->get_ref_die_offset ();
21396 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
,
21397 dwarf2_per_objfile
);
21399 else if (attr
->form
== DW_FORM_ref_sig8
)
21401 ULONGEST signature
= DW_SIGNATURE (attr
);
21403 return get_signatured_type (die
, signature
, cu
);
21407 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21408 " at %s [in module %s]"),
21409 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21410 objfile_name (objfile
));
21411 return build_error_marker_type (cu
, die
);
21414 /* If not cached we need to read it in. */
21416 if (this_type
== NULL
)
21418 struct die_info
*type_die
= NULL
;
21419 struct dwarf2_cu
*type_cu
= cu
;
21421 if (attr
->form_is_ref ())
21422 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21423 if (type_die
== NULL
)
21424 return build_error_marker_type (cu
, die
);
21425 /* If we find the type now, it's probably because the type came
21426 from an inter-CU reference and the type's CU got expanded before
21428 this_type
= read_type_die (type_die
, type_cu
);
21431 /* If we still don't have a type use an error marker. */
21433 if (this_type
== NULL
)
21434 return build_error_marker_type (cu
, die
);
21439 /* Return the type in DIE, CU.
21440 Returns NULL for invalid types.
21442 This first does a lookup in die_type_hash,
21443 and only reads the die in if necessary.
21445 NOTE: This can be called when reading in partial or full symbols. */
21447 static struct type
*
21448 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21450 struct type
*this_type
;
21452 this_type
= get_die_type (die
, cu
);
21456 return read_type_die_1 (die
, cu
);
21459 /* Read the type in DIE, CU.
21460 Returns NULL for invalid types. */
21462 static struct type
*
21463 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21465 struct type
*this_type
= NULL
;
21469 case DW_TAG_class_type
:
21470 case DW_TAG_interface_type
:
21471 case DW_TAG_structure_type
:
21472 case DW_TAG_union_type
:
21473 this_type
= read_structure_type (die
, cu
);
21475 case DW_TAG_enumeration_type
:
21476 this_type
= read_enumeration_type (die
, cu
);
21478 case DW_TAG_subprogram
:
21479 case DW_TAG_subroutine_type
:
21480 case DW_TAG_inlined_subroutine
:
21481 this_type
= read_subroutine_type (die
, cu
);
21483 case DW_TAG_array_type
:
21484 this_type
= read_array_type (die
, cu
);
21486 case DW_TAG_set_type
:
21487 this_type
= read_set_type (die
, cu
);
21489 case DW_TAG_pointer_type
:
21490 this_type
= read_tag_pointer_type (die
, cu
);
21492 case DW_TAG_ptr_to_member_type
:
21493 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21495 case DW_TAG_reference_type
:
21496 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21498 case DW_TAG_rvalue_reference_type
:
21499 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21501 case DW_TAG_const_type
:
21502 this_type
= read_tag_const_type (die
, cu
);
21504 case DW_TAG_volatile_type
:
21505 this_type
= read_tag_volatile_type (die
, cu
);
21507 case DW_TAG_restrict_type
:
21508 this_type
= read_tag_restrict_type (die
, cu
);
21510 case DW_TAG_string_type
:
21511 this_type
= read_tag_string_type (die
, cu
);
21513 case DW_TAG_typedef
:
21514 this_type
= read_typedef (die
, cu
);
21516 case DW_TAG_subrange_type
:
21517 this_type
= read_subrange_type (die
, cu
);
21519 case DW_TAG_base_type
:
21520 this_type
= read_base_type (die
, cu
);
21522 case DW_TAG_unspecified_type
:
21523 this_type
= read_unspecified_type (die
, cu
);
21525 case DW_TAG_namespace
:
21526 this_type
= read_namespace_type (die
, cu
);
21528 case DW_TAG_module
:
21529 this_type
= read_module_type (die
, cu
);
21531 case DW_TAG_atomic_type
:
21532 this_type
= read_tag_atomic_type (die
, cu
);
21535 complaint (_("unexpected tag in read_type_die: '%s'"),
21536 dwarf_tag_name (die
->tag
));
21543 /* See if we can figure out if the class lives in a namespace. We do
21544 this by looking for a member function; its demangled name will
21545 contain namespace info, if there is any.
21546 Return the computed name or NULL.
21547 Space for the result is allocated on the objfile's obstack.
21548 This is the full-die version of guess_partial_die_structure_name.
21549 In this case we know DIE has no useful parent. */
21551 static const char *
21552 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21554 struct die_info
*spec_die
;
21555 struct dwarf2_cu
*spec_cu
;
21556 struct die_info
*child
;
21557 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21560 spec_die
= die_specification (die
, &spec_cu
);
21561 if (spec_die
!= NULL
)
21567 for (child
= die
->child
;
21569 child
= child
->sibling
)
21571 if (child
->tag
== DW_TAG_subprogram
)
21573 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21575 if (linkage_name
!= NULL
)
21577 gdb::unique_xmalloc_ptr
<char> actual_name
21578 (language_class_name_from_physname (cu
->language_defn
,
21580 const char *name
= NULL
;
21582 if (actual_name
!= NULL
)
21584 const char *die_name
= dwarf2_name (die
, cu
);
21586 if (die_name
!= NULL
21587 && strcmp (die_name
, actual_name
.get ()) != 0)
21589 /* Strip off the class name from the full name.
21590 We want the prefix. */
21591 int die_name_len
= strlen (die_name
);
21592 int actual_name_len
= strlen (actual_name
.get ());
21593 const char *ptr
= actual_name
.get ();
21595 /* Test for '::' as a sanity check. */
21596 if (actual_name_len
> die_name_len
+ 2
21597 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21598 name
= obstack_strndup (
21599 &objfile
->per_bfd
->storage_obstack
,
21600 ptr
, actual_name_len
- die_name_len
- 2);
21611 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21612 prefix part in such case. See
21613 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21615 static const char *
21616 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21618 struct attribute
*attr
;
21621 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21622 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21625 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21628 attr
= dw2_linkage_name_attr (die
, cu
);
21629 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21632 /* dwarf2_name had to be already called. */
21633 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21635 /* Strip the base name, keep any leading namespaces/classes. */
21636 base
= strrchr (DW_STRING (attr
), ':');
21637 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21640 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21641 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21643 &base
[-1] - DW_STRING (attr
));
21646 /* Return the name of the namespace/class that DIE is defined within,
21647 or "" if we can't tell. The caller should not xfree the result.
21649 For example, if we're within the method foo() in the following
21659 then determine_prefix on foo's die will return "N::C". */
21661 static const char *
21662 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21664 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21665 struct die_info
*parent
, *spec_die
;
21666 struct dwarf2_cu
*spec_cu
;
21667 struct type
*parent_type
;
21668 const char *retval
;
21670 if (cu
->language
!= language_cplus
21671 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21672 && cu
->language
!= language_rust
)
21675 retval
= anonymous_struct_prefix (die
, cu
);
21679 /* We have to be careful in the presence of DW_AT_specification.
21680 For example, with GCC 3.4, given the code
21684 // Definition of N::foo.
21688 then we'll have a tree of DIEs like this:
21690 1: DW_TAG_compile_unit
21691 2: DW_TAG_namespace // N
21692 3: DW_TAG_subprogram // declaration of N::foo
21693 4: DW_TAG_subprogram // definition of N::foo
21694 DW_AT_specification // refers to die #3
21696 Thus, when processing die #4, we have to pretend that we're in
21697 the context of its DW_AT_specification, namely the contex of die
21700 spec_die
= die_specification (die
, &spec_cu
);
21701 if (spec_die
== NULL
)
21702 parent
= die
->parent
;
21705 parent
= spec_die
->parent
;
21709 if (parent
== NULL
)
21711 else if (parent
->building_fullname
)
21714 const char *parent_name
;
21716 /* It has been seen on RealView 2.2 built binaries,
21717 DW_TAG_template_type_param types actually _defined_ as
21718 children of the parent class:
21721 template class <class Enum> Class{};
21722 Class<enum E> class_e;
21724 1: DW_TAG_class_type (Class)
21725 2: DW_TAG_enumeration_type (E)
21726 3: DW_TAG_enumerator (enum1:0)
21727 3: DW_TAG_enumerator (enum2:1)
21729 2: DW_TAG_template_type_param
21730 DW_AT_type DW_FORM_ref_udata (E)
21732 Besides being broken debug info, it can put GDB into an
21733 infinite loop. Consider:
21735 When we're building the full name for Class<E>, we'll start
21736 at Class, and go look over its template type parameters,
21737 finding E. We'll then try to build the full name of E, and
21738 reach here. We're now trying to build the full name of E,
21739 and look over the parent DIE for containing scope. In the
21740 broken case, if we followed the parent DIE of E, we'd again
21741 find Class, and once again go look at its template type
21742 arguments, etc., etc. Simply don't consider such parent die
21743 as source-level parent of this die (it can't be, the language
21744 doesn't allow it), and break the loop here. */
21745 name
= dwarf2_name (die
, cu
);
21746 parent_name
= dwarf2_name (parent
, cu
);
21747 complaint (_("template param type '%s' defined within parent '%s'"),
21748 name
? name
: "<unknown>",
21749 parent_name
? parent_name
: "<unknown>");
21753 switch (parent
->tag
)
21755 case DW_TAG_namespace
:
21756 parent_type
= read_type_die (parent
, cu
);
21757 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21758 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21759 Work around this problem here. */
21760 if (cu
->language
== language_cplus
21761 && strcmp (parent_type
->name (), "::") == 0)
21763 /* We give a name to even anonymous namespaces. */
21764 return parent_type
->name ();
21765 case DW_TAG_class_type
:
21766 case DW_TAG_interface_type
:
21767 case DW_TAG_structure_type
:
21768 case DW_TAG_union_type
:
21769 case DW_TAG_module
:
21770 parent_type
= read_type_die (parent
, cu
);
21771 if (parent_type
->name () != NULL
)
21772 return parent_type
->name ();
21774 /* An anonymous structure is only allowed non-static data
21775 members; no typedefs, no member functions, et cetera.
21776 So it does not need a prefix. */
21778 case DW_TAG_compile_unit
:
21779 case DW_TAG_partial_unit
:
21780 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21781 if (cu
->language
== language_cplus
21782 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21783 && die
->child
!= NULL
21784 && (die
->tag
== DW_TAG_class_type
21785 || die
->tag
== DW_TAG_structure_type
21786 || die
->tag
== DW_TAG_union_type
))
21788 const char *name
= guess_full_die_structure_name (die
, cu
);
21793 case DW_TAG_subprogram
:
21794 /* Nested subroutines in Fortran get a prefix with the name
21795 of the parent's subroutine. */
21796 if (cu
->language
== language_fortran
)
21798 if ((die
->tag
== DW_TAG_subprogram
)
21799 && (dwarf2_name (parent
, cu
) != NULL
))
21800 return dwarf2_name (parent
, cu
);
21802 return determine_prefix (parent
, cu
);
21803 case DW_TAG_enumeration_type
:
21804 parent_type
= read_type_die (parent
, cu
);
21805 if (TYPE_DECLARED_CLASS (parent_type
))
21807 if (parent_type
->name () != NULL
)
21808 return parent_type
->name ();
21811 /* Fall through. */
21813 return determine_prefix (parent
, cu
);
21817 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21818 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21819 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21820 an obconcat, otherwise allocate storage for the result. The CU argument is
21821 used to determine the language and hence, the appropriate separator. */
21823 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21826 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21827 int physname
, struct dwarf2_cu
*cu
)
21829 const char *lead
= "";
21832 if (suffix
== NULL
|| suffix
[0] == '\0'
21833 || prefix
== NULL
|| prefix
[0] == '\0')
21835 else if (cu
->language
== language_d
)
21837 /* For D, the 'main' function could be defined in any module, but it
21838 should never be prefixed. */
21839 if (strcmp (suffix
, "D main") == 0)
21847 else if (cu
->language
== language_fortran
&& physname
)
21849 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21850 DW_AT_MIPS_linkage_name is preferred and used instead. */
21858 if (prefix
== NULL
)
21860 if (suffix
== NULL
)
21867 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21869 strcpy (retval
, lead
);
21870 strcat (retval
, prefix
);
21871 strcat (retval
, sep
);
21872 strcat (retval
, suffix
);
21877 /* We have an obstack. */
21878 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21882 /* Get name of a die, return NULL if not found. */
21884 static const char *
21885 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21886 struct objfile
*objfile
)
21888 if (name
&& cu
->language
== language_cplus
)
21890 gdb::unique_xmalloc_ptr
<char> canon_name
21891 = cp_canonicalize_string (name
);
21893 if (canon_name
!= nullptr)
21894 name
= objfile
->intern (canon_name
.get ());
21900 /* Get name of a die, return NULL if not found.
21901 Anonymous namespaces are converted to their magic string. */
21903 static const char *
21904 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21906 struct attribute
*attr
;
21907 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21909 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21910 if ((!attr
|| !DW_STRING (attr
))
21911 && die
->tag
!= DW_TAG_namespace
21912 && die
->tag
!= DW_TAG_class_type
21913 && die
->tag
!= DW_TAG_interface_type
21914 && die
->tag
!= DW_TAG_structure_type
21915 && die
->tag
!= DW_TAG_union_type
)
21920 case DW_TAG_compile_unit
:
21921 case DW_TAG_partial_unit
:
21922 /* Compilation units have a DW_AT_name that is a filename, not
21923 a source language identifier. */
21924 case DW_TAG_enumeration_type
:
21925 case DW_TAG_enumerator
:
21926 /* These tags always have simple identifiers already; no need
21927 to canonicalize them. */
21928 return DW_STRING (attr
);
21930 case DW_TAG_namespace
:
21931 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21932 return DW_STRING (attr
);
21933 return CP_ANONYMOUS_NAMESPACE_STR
;
21935 case DW_TAG_class_type
:
21936 case DW_TAG_interface_type
:
21937 case DW_TAG_structure_type
:
21938 case DW_TAG_union_type
:
21939 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21940 structures or unions. These were of the form "._%d" in GCC 4.1,
21941 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21942 and GCC 4.4. We work around this problem by ignoring these. */
21943 if (attr
&& DW_STRING (attr
)
21944 && (startswith (DW_STRING (attr
), "._")
21945 || startswith (DW_STRING (attr
), "<anonymous")))
21948 /* GCC might emit a nameless typedef that has a linkage name. See
21949 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21950 if (!attr
|| DW_STRING (attr
) == NULL
)
21952 attr
= dw2_linkage_name_attr (die
, cu
);
21953 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21956 /* Avoid demangling DW_STRING (attr) the second time on a second
21957 call for the same DIE. */
21958 if (!DW_STRING_IS_CANONICAL (attr
))
21960 gdb::unique_xmalloc_ptr
<char> demangled
21961 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21962 if (demangled
== nullptr)
21965 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21966 DW_STRING_IS_CANONICAL (attr
) = 1;
21969 /* Strip any leading namespaces/classes, keep only the base name.
21970 DW_AT_name for named DIEs does not contain the prefixes. */
21971 const char *base
= strrchr (DW_STRING (attr
), ':');
21972 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21975 return DW_STRING (attr
);
21983 if (!DW_STRING_IS_CANONICAL (attr
))
21985 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21987 DW_STRING_IS_CANONICAL (attr
) = 1;
21989 return DW_STRING (attr
);
21992 /* Return the die that this die in an extension of, or NULL if there
21993 is none. *EXT_CU is the CU containing DIE on input, and the CU
21994 containing the return value on output. */
21996 static struct die_info
*
21997 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21999 struct attribute
*attr
;
22001 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22005 return follow_die_ref (die
, attr
, ext_cu
);
22009 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22013 print_spaces (indent
, f
);
22014 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22015 dwarf_tag_name (die
->tag
), die
->abbrev
,
22016 sect_offset_str (die
->sect_off
));
22018 if (die
->parent
!= NULL
)
22020 print_spaces (indent
, f
);
22021 fprintf_unfiltered (f
, " parent at offset: %s\n",
22022 sect_offset_str (die
->parent
->sect_off
));
22025 print_spaces (indent
, f
);
22026 fprintf_unfiltered (f
, " has children: %s\n",
22027 dwarf_bool_name (die
->child
!= NULL
));
22029 print_spaces (indent
, f
);
22030 fprintf_unfiltered (f
, " attributes:\n");
22032 for (i
= 0; i
< die
->num_attrs
; ++i
)
22034 print_spaces (indent
, f
);
22035 fprintf_unfiltered (f
, " %s (%s) ",
22036 dwarf_attr_name (die
->attrs
[i
].name
),
22037 dwarf_form_name (die
->attrs
[i
].form
));
22039 switch (die
->attrs
[i
].form
)
22042 case DW_FORM_addrx
:
22043 case DW_FORM_GNU_addr_index
:
22044 fprintf_unfiltered (f
, "address: ");
22045 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22047 case DW_FORM_block2
:
22048 case DW_FORM_block4
:
22049 case DW_FORM_block
:
22050 case DW_FORM_block1
:
22051 fprintf_unfiltered (f
, "block: size %s",
22052 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22054 case DW_FORM_exprloc
:
22055 fprintf_unfiltered (f
, "expression: size %s",
22056 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22058 case DW_FORM_data16
:
22059 fprintf_unfiltered (f
, "constant of 16 bytes");
22061 case DW_FORM_ref_addr
:
22062 fprintf_unfiltered (f
, "ref address: ");
22063 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22065 case DW_FORM_GNU_ref_alt
:
22066 fprintf_unfiltered (f
, "alt ref address: ");
22067 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22073 case DW_FORM_ref_udata
:
22074 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22075 (long) (DW_UNSND (&die
->attrs
[i
])));
22077 case DW_FORM_data1
:
22078 case DW_FORM_data2
:
22079 case DW_FORM_data4
:
22080 case DW_FORM_data8
:
22081 case DW_FORM_udata
:
22082 case DW_FORM_sdata
:
22083 fprintf_unfiltered (f
, "constant: %s",
22084 pulongest (DW_UNSND (&die
->attrs
[i
])));
22086 case DW_FORM_sec_offset
:
22087 fprintf_unfiltered (f
, "section offset: %s",
22088 pulongest (DW_UNSND (&die
->attrs
[i
])));
22090 case DW_FORM_ref_sig8
:
22091 fprintf_unfiltered (f
, "signature: %s",
22092 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22094 case DW_FORM_string
:
22096 case DW_FORM_line_strp
:
22098 case DW_FORM_GNU_str_index
:
22099 case DW_FORM_GNU_strp_alt
:
22100 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22101 DW_STRING (&die
->attrs
[i
])
22102 ? DW_STRING (&die
->attrs
[i
]) : "",
22103 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22106 if (DW_UNSND (&die
->attrs
[i
]))
22107 fprintf_unfiltered (f
, "flag: TRUE");
22109 fprintf_unfiltered (f
, "flag: FALSE");
22111 case DW_FORM_flag_present
:
22112 fprintf_unfiltered (f
, "flag: TRUE");
22114 case DW_FORM_indirect
:
22115 /* The reader will have reduced the indirect form to
22116 the "base form" so this form should not occur. */
22117 fprintf_unfiltered (f
,
22118 "unexpected attribute form: DW_FORM_indirect");
22120 case DW_FORM_implicit_const
:
22121 fprintf_unfiltered (f
, "constant: %s",
22122 plongest (DW_SND (&die
->attrs
[i
])));
22125 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22126 die
->attrs
[i
].form
);
22129 fprintf_unfiltered (f
, "\n");
22134 dump_die_for_error (struct die_info
*die
)
22136 dump_die_shallow (gdb_stderr
, 0, die
);
22140 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22142 int indent
= level
* 4;
22144 gdb_assert (die
!= NULL
);
22146 if (level
>= max_level
)
22149 dump_die_shallow (f
, indent
, die
);
22151 if (die
->child
!= NULL
)
22153 print_spaces (indent
, f
);
22154 fprintf_unfiltered (f
, " Children:");
22155 if (level
+ 1 < max_level
)
22157 fprintf_unfiltered (f
, "\n");
22158 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22162 fprintf_unfiltered (f
,
22163 " [not printed, max nesting level reached]\n");
22167 if (die
->sibling
!= NULL
&& level
> 0)
22169 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22173 /* This is called from the pdie macro in gdbinit.in.
22174 It's not static so gcc will keep a copy callable from gdb. */
22177 dump_die (struct die_info
*die
, int max_level
)
22179 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22183 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22187 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22188 to_underlying (die
->sect_off
),
22194 /* Follow reference or signature attribute ATTR of SRC_DIE.
22195 On entry *REF_CU is the CU of SRC_DIE.
22196 On exit *REF_CU is the CU of the result. */
22198 static struct die_info
*
22199 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22200 struct dwarf2_cu
**ref_cu
)
22202 struct die_info
*die
;
22204 if (attr
->form_is_ref ())
22205 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22206 else if (attr
->form
== DW_FORM_ref_sig8
)
22207 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22210 dump_die_for_error (src_die
);
22211 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22212 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22218 /* Follow reference OFFSET.
22219 On entry *REF_CU is the CU of the source die referencing OFFSET.
22220 On exit *REF_CU is the CU of the result.
22221 Returns NULL if OFFSET is invalid. */
22223 static struct die_info
*
22224 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22225 struct dwarf2_cu
**ref_cu
)
22227 struct die_info temp_die
;
22228 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22229 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22231 gdb_assert (cu
->per_cu
!= NULL
);
22235 if (cu
->per_cu
->is_debug_types
)
22237 /* .debug_types CUs cannot reference anything outside their CU.
22238 If they need to, they have to reference a signatured type via
22239 DW_FORM_ref_sig8. */
22240 if (!cu
->header
.offset_in_cu_p (sect_off
))
22243 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22244 || !cu
->header
.offset_in_cu_p (sect_off
))
22246 struct dwarf2_per_cu_data
*per_cu
;
22248 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22249 dwarf2_per_objfile
);
22251 /* If necessary, add it to the queue and load its DIEs. */
22252 if (maybe_queue_comp_unit (cu
, per_cu
, dwarf2_per_objfile
, cu
->language
))
22253 load_full_comp_unit (per_cu
, dwarf2_per_objfile
, false, cu
->language
);
22255 target_cu
= dwarf2_per_objfile
->get_cu (per_cu
);
22257 else if (cu
->dies
== NULL
)
22259 /* We're loading full DIEs during partial symbol reading. */
22260 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22261 load_full_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, false,
22265 *ref_cu
= target_cu
;
22266 temp_die
.sect_off
= sect_off
;
22268 if (target_cu
!= cu
)
22269 target_cu
->ancestor
= cu
;
22271 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22273 to_underlying (sect_off
));
22276 /* Follow reference attribute ATTR of SRC_DIE.
22277 On entry *REF_CU is the CU of SRC_DIE.
22278 On exit *REF_CU is the CU of the result. */
22280 static struct die_info
*
22281 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22282 struct dwarf2_cu
**ref_cu
)
22284 sect_offset sect_off
= attr
->get_ref_die_offset ();
22285 struct dwarf2_cu
*cu
= *ref_cu
;
22286 struct die_info
*die
;
22288 die
= follow_die_offset (sect_off
,
22289 (attr
->form
== DW_FORM_GNU_ref_alt
22290 || cu
->per_cu
->is_dwz
),
22293 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22294 "at %s [in module %s]"),
22295 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22296 objfile_name (cu
->per_objfile
->objfile
));
22303 struct dwarf2_locexpr_baton
22304 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22305 dwarf2_per_cu_data
*per_cu
,
22306 dwarf2_per_objfile
*dwarf2_per_objfile
,
22307 CORE_ADDR (*get_frame_pc
) (void *baton
),
22308 void *baton
, bool resolve_abstract_p
)
22310 struct die_info
*die
;
22311 struct attribute
*attr
;
22312 struct dwarf2_locexpr_baton retval
;
22313 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22315 dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
22317 cu
= load_cu (per_cu
, dwarf2_per_objfile
, false);
22321 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22322 Instead just throw an error, not much else we can do. */
22323 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22324 sect_offset_str (sect_off
), objfile_name (objfile
));
22327 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22329 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22330 sect_offset_str (sect_off
), objfile_name (objfile
));
22332 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22333 if (!attr
&& resolve_abstract_p
22334 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22335 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22337 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22338 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22339 struct gdbarch
*gdbarch
= objfile
->arch ();
22341 for (const auto &cand_off
22342 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22344 struct dwarf2_cu
*cand_cu
= cu
;
22345 struct die_info
*cand
22346 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22349 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22352 CORE_ADDR pc_low
, pc_high
;
22353 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22354 if (pc_low
== ((CORE_ADDR
) -1))
22356 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22357 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22358 if (!(pc_low
<= pc
&& pc
< pc_high
))
22362 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22369 /* DWARF: "If there is no such attribute, then there is no effect.".
22370 DATA is ignored if SIZE is 0. */
22372 retval
.data
= NULL
;
22375 else if (attr
->form_is_section_offset ())
22377 struct dwarf2_loclist_baton loclist_baton
;
22378 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22381 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22383 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22385 retval
.size
= size
;
22389 if (!attr
->form_is_block ())
22390 error (_("Dwarf Error: DIE at %s referenced in module %s "
22391 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22392 sect_offset_str (sect_off
), objfile_name (objfile
));
22394 retval
.data
= DW_BLOCK (attr
)->data
;
22395 retval
.size
= DW_BLOCK (attr
)->size
;
22397 retval
.per_objfile
= dwarf2_per_objfile
;
22398 retval
.per_cu
= cu
->per_cu
;
22400 dwarf2_per_objfile
->age_comp_units ();
22407 struct dwarf2_locexpr_baton
22408 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22409 dwarf2_per_cu_data
*per_cu
,
22410 dwarf2_per_objfile
*per_objfile
,
22411 CORE_ADDR (*get_frame_pc
) (void *baton
),
22414 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22416 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22417 get_frame_pc
, baton
);
22420 /* Write a constant of a given type as target-ordered bytes into
22423 static const gdb_byte
*
22424 write_constant_as_bytes (struct obstack
*obstack
,
22425 enum bfd_endian byte_order
,
22432 *len
= TYPE_LENGTH (type
);
22433 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22434 store_unsigned_integer (result
, *len
, byte_order
, value
);
22442 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22443 dwarf2_per_cu_data
*per_cu
,
22444 dwarf2_per_objfile
*per_objfile
,
22448 struct die_info
*die
;
22449 struct attribute
*attr
;
22450 const gdb_byte
*result
= NULL
;
22453 enum bfd_endian byte_order
;
22454 struct objfile
*objfile
= per_objfile
->objfile
;
22456 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22458 cu
= load_cu (per_cu
, per_objfile
, false);
22462 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22463 Instead just throw an error, not much else we can do. */
22464 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22465 sect_offset_str (sect_off
), objfile_name (objfile
));
22468 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22470 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22471 sect_offset_str (sect_off
), objfile_name (objfile
));
22473 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22477 byte_order
= (bfd_big_endian (objfile
->obfd
)
22478 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22480 switch (attr
->form
)
22483 case DW_FORM_addrx
:
22484 case DW_FORM_GNU_addr_index
:
22488 *len
= cu
->header
.addr_size
;
22489 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22490 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22494 case DW_FORM_string
:
22497 case DW_FORM_GNU_str_index
:
22498 case DW_FORM_GNU_strp_alt
:
22499 /* DW_STRING is already allocated on the objfile obstack, point
22501 result
= (const gdb_byte
*) DW_STRING (attr
);
22502 *len
= strlen (DW_STRING (attr
));
22504 case DW_FORM_block1
:
22505 case DW_FORM_block2
:
22506 case DW_FORM_block4
:
22507 case DW_FORM_block
:
22508 case DW_FORM_exprloc
:
22509 case DW_FORM_data16
:
22510 result
= DW_BLOCK (attr
)->data
;
22511 *len
= DW_BLOCK (attr
)->size
;
22514 /* The DW_AT_const_value attributes are supposed to carry the
22515 symbol's value "represented as it would be on the target
22516 architecture." By the time we get here, it's already been
22517 converted to host endianness, so we just need to sign- or
22518 zero-extend it as appropriate. */
22519 case DW_FORM_data1
:
22520 type
= die_type (die
, cu
);
22521 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22522 if (result
== NULL
)
22523 result
= write_constant_as_bytes (obstack
, byte_order
,
22526 case DW_FORM_data2
:
22527 type
= die_type (die
, cu
);
22528 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22529 if (result
== NULL
)
22530 result
= write_constant_as_bytes (obstack
, byte_order
,
22533 case DW_FORM_data4
:
22534 type
= die_type (die
, cu
);
22535 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22536 if (result
== NULL
)
22537 result
= write_constant_as_bytes (obstack
, byte_order
,
22540 case DW_FORM_data8
:
22541 type
= die_type (die
, cu
);
22542 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22543 if (result
== NULL
)
22544 result
= write_constant_as_bytes (obstack
, byte_order
,
22548 case DW_FORM_sdata
:
22549 case DW_FORM_implicit_const
:
22550 type
= die_type (die
, cu
);
22551 result
= write_constant_as_bytes (obstack
, byte_order
,
22552 type
, DW_SND (attr
), len
);
22555 case DW_FORM_udata
:
22556 type
= die_type (die
, cu
);
22557 result
= write_constant_as_bytes (obstack
, byte_order
,
22558 type
, DW_UNSND (attr
), len
);
22562 complaint (_("unsupported const value attribute form: '%s'"),
22563 dwarf_form_name (attr
->form
));
22573 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22574 dwarf2_per_cu_data
*per_cu
,
22575 dwarf2_per_objfile
*per_objfile
)
22577 struct die_info
*die
;
22579 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22581 cu
= load_cu (per_cu
, per_objfile
, false);
22586 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22590 return die_type (die
, cu
);
22596 dwarf2_get_die_type (cu_offset die_offset
,
22597 dwarf2_per_cu_data
*per_cu
,
22598 dwarf2_per_objfile
*per_objfile
)
22600 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22601 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22604 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22605 On entry *REF_CU is the CU of SRC_DIE.
22606 On exit *REF_CU is the CU of the result.
22607 Returns NULL if the referenced DIE isn't found. */
22609 static struct die_info
*
22610 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22611 struct dwarf2_cu
**ref_cu
)
22613 struct die_info temp_die
;
22614 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22615 struct die_info
*die
;
22616 dwarf2_per_objfile
*dwarf2_per_objfile
= (*ref_cu
)->per_objfile
;
22619 /* While it might be nice to assert sig_type->type == NULL here,
22620 we can get here for DW_AT_imported_declaration where we need
22621 the DIE not the type. */
22623 /* If necessary, add it to the queue and load its DIEs. */
22625 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, dwarf2_per_objfile
,
22627 read_signatured_type (sig_type
, dwarf2_per_objfile
);
22629 sig_cu
= dwarf2_per_objfile
->get_cu (&sig_type
->per_cu
);
22630 gdb_assert (sig_cu
!= NULL
);
22631 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22632 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22633 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22634 to_underlying (temp_die
.sect_off
));
22637 /* For .gdb_index version 7 keep track of included TUs.
22638 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22639 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22640 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22642 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22647 sig_cu
->ancestor
= cu
;
22655 /* Follow signatured type referenced by ATTR in SRC_DIE.
22656 On entry *REF_CU is the CU of SRC_DIE.
22657 On exit *REF_CU is the CU of the result.
22658 The result is the DIE of the type.
22659 If the referenced type cannot be found an error is thrown. */
22661 static struct die_info
*
22662 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22663 struct dwarf2_cu
**ref_cu
)
22665 ULONGEST signature
= DW_SIGNATURE (attr
);
22666 struct signatured_type
*sig_type
;
22667 struct die_info
*die
;
22669 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22671 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22672 /* sig_type will be NULL if the signatured type is missing from
22674 if (sig_type
== NULL
)
22676 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22677 " from DIE at %s [in module %s]"),
22678 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22679 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22682 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22685 dump_die_for_error (src_die
);
22686 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22687 " from DIE at %s [in module %s]"),
22688 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22689 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22695 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22696 reading in and processing the type unit if necessary. */
22698 static struct type
*
22699 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22700 struct dwarf2_cu
*cu
)
22702 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22703 struct signatured_type
*sig_type
;
22704 struct dwarf2_cu
*type_cu
;
22705 struct die_info
*type_die
;
22708 sig_type
= lookup_signatured_type (cu
, signature
);
22709 /* sig_type will be NULL if the signatured type is missing from
22711 if (sig_type
== NULL
)
22713 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22714 " from DIE at %s [in module %s]"),
22715 hex_string (signature
), sect_offset_str (die
->sect_off
),
22716 objfile_name (dwarf2_per_objfile
->objfile
));
22717 return build_error_marker_type (cu
, die
);
22720 /* If we already know the type we're done. */
22721 type
= dwarf2_per_objfile
->get_type_for_signatured_type (sig_type
);
22722 if (type
!= nullptr)
22726 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22727 if (type_die
!= NULL
)
22729 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22730 is created. This is important, for example, because for c++ classes
22731 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22732 type
= read_type_die (type_die
, type_cu
);
22735 complaint (_("Dwarf Error: Cannot build signatured type %s"
22736 " referenced from DIE at %s [in module %s]"),
22737 hex_string (signature
), sect_offset_str (die
->sect_off
),
22738 objfile_name (dwarf2_per_objfile
->objfile
));
22739 type
= build_error_marker_type (cu
, die
);
22744 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22745 " from DIE at %s [in module %s]"),
22746 hex_string (signature
), sect_offset_str (die
->sect_off
),
22747 objfile_name (dwarf2_per_objfile
->objfile
));
22748 type
= build_error_marker_type (cu
, die
);
22751 dwarf2_per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22756 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22757 reading in and processing the type unit if necessary. */
22759 static struct type
*
22760 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22761 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22763 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22764 if (attr
->form_is_ref ())
22766 struct dwarf2_cu
*type_cu
= cu
;
22767 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22769 return read_type_die (type_die
, type_cu
);
22771 else if (attr
->form
== DW_FORM_ref_sig8
)
22773 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22777 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22779 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22780 " at %s [in module %s]"),
22781 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22782 objfile_name (dwarf2_per_objfile
->objfile
));
22783 return build_error_marker_type (cu
, die
);
22787 /* Load the DIEs associated with type unit PER_CU into memory. */
22790 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22791 dwarf2_per_objfile
*per_objfile
)
22793 struct signatured_type
*sig_type
;
22795 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22796 gdb_assert (! per_cu
->type_unit_group_p ());
22798 /* We have the per_cu, but we need the signatured_type.
22799 Fortunately this is an easy translation. */
22800 gdb_assert (per_cu
->is_debug_types
);
22801 sig_type
= (struct signatured_type
*) per_cu
;
22803 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22805 read_signatured_type (sig_type
, per_objfile
);
22807 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22810 /* Read in a signatured type and build its CU and DIEs.
22811 If the type is a stub for the real type in a DWO file,
22812 read in the real type from the DWO file as well. */
22815 read_signatured_type (signatured_type
*sig_type
,
22816 dwarf2_per_objfile
*per_objfile
)
22818 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22820 gdb_assert (per_cu
->is_debug_types
);
22821 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22823 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22825 if (!reader
.dummy_p
)
22827 struct dwarf2_cu
*cu
= reader
.cu
;
22828 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22830 gdb_assert (cu
->die_hash
== NULL
);
22832 htab_create_alloc_ex (cu
->header
.length
/ 12,
22836 &cu
->comp_unit_obstack
,
22837 hashtab_obstack_allocate
,
22838 dummy_obstack_deallocate
);
22840 if (reader
.comp_unit_die
->has_children
)
22841 reader
.comp_unit_die
->child
22842 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22843 reader
.comp_unit_die
);
22844 cu
->dies
= reader
.comp_unit_die
;
22845 /* comp_unit_die is not stored in die_hash, no need. */
22847 /* We try not to read any attributes in this function, because
22848 not all CUs needed for references have been loaded yet, and
22849 symbol table processing isn't initialized. But we have to
22850 set the CU language, or we won't be able to build types
22851 correctly. Similarly, if we do not read the producer, we can
22852 not apply producer-specific interpretation. */
22853 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22858 sig_type
->per_cu
.tu_read
= 1;
22861 /* Decode simple location descriptions.
22862 Given a pointer to a dwarf block that defines a location, compute
22863 the location and return the value. If COMPUTED is non-null, it is
22864 set to true to indicate that decoding was successful, and false
22865 otherwise. If COMPUTED is null, then this function may emit a
22869 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22871 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22873 size_t size
= blk
->size
;
22874 const gdb_byte
*data
= blk
->data
;
22875 CORE_ADDR stack
[64];
22877 unsigned int bytes_read
, unsnd
;
22880 if (computed
!= nullptr)
22886 stack
[++stacki
] = 0;
22925 stack
[++stacki
] = op
- DW_OP_lit0
;
22960 stack
[++stacki
] = op
- DW_OP_reg0
;
22963 if (computed
== nullptr)
22964 dwarf2_complex_location_expr_complaint ();
22971 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22973 stack
[++stacki
] = unsnd
;
22976 if (computed
== nullptr)
22977 dwarf2_complex_location_expr_complaint ();
22984 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22989 case DW_OP_const1u
:
22990 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22994 case DW_OP_const1s
:
22995 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22999 case DW_OP_const2u
:
23000 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23004 case DW_OP_const2s
:
23005 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23009 case DW_OP_const4u
:
23010 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23014 case DW_OP_const4s
:
23015 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23019 case DW_OP_const8u
:
23020 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23025 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23031 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23036 stack
[stacki
+ 1] = stack
[stacki
];
23041 stack
[stacki
- 1] += stack
[stacki
];
23045 case DW_OP_plus_uconst
:
23046 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23052 stack
[stacki
- 1] -= stack
[stacki
];
23057 /* If we're not the last op, then we definitely can't encode
23058 this using GDB's address_class enum. This is valid for partial
23059 global symbols, although the variable's address will be bogus
23063 if (computed
== nullptr)
23064 dwarf2_complex_location_expr_complaint ();
23070 case DW_OP_GNU_push_tls_address
:
23071 case DW_OP_form_tls_address
:
23072 /* The top of the stack has the offset from the beginning
23073 of the thread control block at which the variable is located. */
23074 /* Nothing should follow this operator, so the top of stack would
23076 /* This is valid for partial global symbols, but the variable's
23077 address will be bogus in the psymtab. Make it always at least
23078 non-zero to not look as a variable garbage collected by linker
23079 which have DW_OP_addr 0. */
23082 if (computed
== nullptr)
23083 dwarf2_complex_location_expr_complaint ();
23090 case DW_OP_GNU_uninit
:
23091 if (computed
!= nullptr)
23096 case DW_OP_GNU_addr_index
:
23097 case DW_OP_GNU_const_index
:
23098 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23104 if (computed
== nullptr)
23106 const char *name
= get_DW_OP_name (op
);
23109 complaint (_("unsupported stack op: '%s'"),
23112 complaint (_("unsupported stack op: '%02x'"),
23116 return (stack
[stacki
]);
23119 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23120 outside of the allocated space. Also enforce minimum>0. */
23121 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23123 if (computed
== nullptr)
23124 complaint (_("location description stack overflow"));
23130 if (computed
== nullptr)
23131 complaint (_("location description stack underflow"));
23136 if (computed
!= nullptr)
23138 return (stack
[stacki
]);
23141 /* memory allocation interface */
23143 static struct dwarf_block
*
23144 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23146 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23149 static struct die_info
*
23150 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23152 struct die_info
*die
;
23153 size_t size
= sizeof (struct die_info
);
23156 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23158 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23159 memset (die
, 0, sizeof (struct die_info
));
23165 /* Macro support. */
23167 /* An overload of dwarf_decode_macros that finds the correct section
23168 and ensures it is read in before calling the other overload. */
23171 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23172 int section_is_gnu
)
23174 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23175 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23176 const struct line_header
*lh
= cu
->line_header
;
23177 unsigned int offset_size
= cu
->header
.offset_size
;
23178 struct dwarf2_section_info
*section
;
23179 const char *section_name
;
23181 if (cu
->dwo_unit
!= nullptr)
23183 if (section_is_gnu
)
23185 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23186 section_name
= ".debug_macro.dwo";
23190 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23191 section_name
= ".debug_macinfo.dwo";
23196 if (section_is_gnu
)
23198 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23199 section_name
= ".debug_macro";
23203 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23204 section_name
= ".debug_macinfo";
23208 section
->read (objfile
);
23209 if (section
->buffer
== nullptr)
23211 complaint (_("missing %s section"), section_name
);
23215 buildsym_compunit
*builder
= cu
->get_builder ();
23217 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23218 offset_size
, offset
, section_is_gnu
);
23221 /* Return the .debug_loc section to use for CU.
23222 For DWO files use .debug_loc.dwo. */
23224 static struct dwarf2_section_info
*
23225 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23227 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23231 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23233 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23235 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23236 : &dwarf2_per_objfile
->per_bfd
->loc
);
23239 /* A helper function that fills in a dwarf2_loclist_baton. */
23242 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23243 struct dwarf2_loclist_baton
*baton
,
23244 const struct attribute
*attr
)
23246 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23247 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23249 section
->read (dwarf2_per_objfile
->objfile
);
23251 baton
->per_objfile
= dwarf2_per_objfile
;
23252 baton
->per_cu
= cu
->per_cu
;
23253 gdb_assert (baton
->per_cu
);
23254 /* We don't know how long the location list is, but make sure we
23255 don't run off the edge of the section. */
23256 baton
->size
= section
->size
- DW_UNSND (attr
);
23257 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23258 if (cu
->base_address
.has_value ())
23259 baton
->base_address
= *cu
->base_address
;
23261 baton
->base_address
= 0;
23262 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23266 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23267 struct dwarf2_cu
*cu
, int is_block
)
23269 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23270 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23271 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23273 if (attr
->form_is_section_offset ()
23274 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23275 the section. If so, fall through to the complaint in the
23277 && DW_UNSND (attr
) < section
->get_size (objfile
))
23279 struct dwarf2_loclist_baton
*baton
;
23281 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23283 fill_in_loclist_baton (cu
, baton
, attr
);
23285 if (!cu
->base_address
.has_value ())
23286 complaint (_("Location list used without "
23287 "specifying the CU base address."));
23289 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23290 ? dwarf2_loclist_block_index
23291 : dwarf2_loclist_index
);
23292 SYMBOL_LOCATION_BATON (sym
) = baton
;
23296 struct dwarf2_locexpr_baton
*baton
;
23298 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23299 baton
->per_objfile
= dwarf2_per_objfile
;
23300 baton
->per_cu
= cu
->per_cu
;
23301 gdb_assert (baton
->per_cu
);
23303 if (attr
->form_is_block ())
23305 /* Note that we're just copying the block's data pointer
23306 here, not the actual data. We're still pointing into the
23307 info_buffer for SYM's objfile; right now we never release
23308 that buffer, but when we do clean up properly this may
23310 baton
->size
= DW_BLOCK (attr
)->size
;
23311 baton
->data
= DW_BLOCK (attr
)->data
;
23315 dwarf2_invalid_attrib_class_complaint ("location description",
23316 sym
->natural_name ());
23320 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23321 ? dwarf2_locexpr_block_index
23322 : dwarf2_locexpr_index
);
23323 SYMBOL_LOCATION_BATON (sym
) = baton
;
23329 const comp_unit_head
*
23330 dwarf2_per_cu_data::get_header () const
23332 if (!m_header_read_in
)
23334 const gdb_byte
*info_ptr
23335 = this->section
->buffer
+ to_underlying (this->sect_off
);
23337 memset (&m_header
, 0, sizeof (m_header
));
23339 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23340 rcuh_kind::COMPILE
);
23349 dwarf2_per_cu_data::addr_size () const
23351 return this->get_header ()->addr_size
;
23357 dwarf2_per_cu_data::offset_size () const
23359 return this->get_header ()->offset_size
;
23365 dwarf2_per_cu_data::ref_addr_size () const
23367 const comp_unit_head
*header
= this->get_header ();
23369 if (header
->version
== 2)
23370 return header
->addr_size
;
23372 return header
->offset_size
;
23378 dwarf2_cu::addr_type () const
23380 struct objfile
*objfile
= this->per_objfile
->objfile
;
23381 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23382 struct type
*addr_type
= lookup_pointer_type (void_type
);
23383 int addr_size
= this->per_cu
->addr_size ();
23385 if (TYPE_LENGTH (addr_type
) == addr_size
)
23388 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23392 /* A helper function for dwarf2_find_containing_comp_unit that returns
23393 the index of the result, and that searches a vector. It will
23394 return a result even if the offset in question does not actually
23395 occur in any CU. This is separate so that it can be unit
23399 dwarf2_find_containing_comp_unit
23400 (sect_offset sect_off
,
23401 unsigned int offset_in_dwz
,
23402 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23407 high
= all_comp_units
.size () - 1;
23410 struct dwarf2_per_cu_data
*mid_cu
;
23411 int mid
= low
+ (high
- low
) / 2;
23413 mid_cu
= all_comp_units
[mid
];
23414 if (mid_cu
->is_dwz
> offset_in_dwz
23415 || (mid_cu
->is_dwz
== offset_in_dwz
23416 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23421 gdb_assert (low
== high
);
23425 /* Locate the .debug_info compilation unit from CU's objfile which contains
23426 the DIE at OFFSET. Raises an error on failure. */
23428 static struct dwarf2_per_cu_data
*
23429 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23430 unsigned int offset_in_dwz
,
23431 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23434 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23435 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23436 struct dwarf2_per_cu_data
*this_cu
23437 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23439 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23441 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23442 error (_("Dwarf Error: could not find partial DIE containing "
23443 "offset %s [in module %s]"),
23444 sect_offset_str (sect_off
),
23445 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23447 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23449 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23453 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23454 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23455 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23456 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23463 namespace selftests
{
23464 namespace find_containing_comp_unit
{
23469 struct dwarf2_per_cu_data one
{};
23470 struct dwarf2_per_cu_data two
{};
23471 struct dwarf2_per_cu_data three
{};
23472 struct dwarf2_per_cu_data four
{};
23475 two
.sect_off
= sect_offset (one
.length
);
23480 four
.sect_off
= sect_offset (three
.length
);
23484 std::vector
<dwarf2_per_cu_data
*> units
;
23485 units
.push_back (&one
);
23486 units
.push_back (&two
);
23487 units
.push_back (&three
);
23488 units
.push_back (&four
);
23492 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23493 SELF_CHECK (units
[result
] == &one
);
23494 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23495 SELF_CHECK (units
[result
] == &one
);
23496 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23497 SELF_CHECK (units
[result
] == &two
);
23499 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23500 SELF_CHECK (units
[result
] == &three
);
23501 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23502 SELF_CHECK (units
[result
] == &three
);
23503 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23504 SELF_CHECK (units
[result
] == &four
);
23510 #endif /* GDB_SELF_TEST */
23512 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23514 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23515 dwarf2_per_objfile
*per_objfile
)
23517 per_objfile (per_objfile
),
23519 has_loclist (false),
23520 checked_producer (false),
23521 producer_is_gxx_lt_4_6 (false),
23522 producer_is_gcc_lt_4_3 (false),
23523 producer_is_icc (false),
23524 producer_is_icc_lt_14 (false),
23525 producer_is_codewarrior (false),
23526 processing_has_namespace_info (false)
23530 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23533 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23534 enum language pretend_language
)
23536 struct attribute
*attr
;
23538 /* Set the language we're debugging. */
23539 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23540 if (attr
!= nullptr)
23541 set_cu_language (DW_UNSND (attr
), cu
);
23544 cu
->language
= pretend_language
;
23545 cu
->language_defn
= language_def (cu
->language
);
23548 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23554 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23556 auto it
= m_dwarf2_cus
.find (per_cu
);
23557 if (it
== m_dwarf2_cus
.end ())
23566 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23568 gdb_assert (this->get_cu (per_cu
) == nullptr);
23570 m_dwarf2_cus
[per_cu
] = cu
;
23576 dwarf2_per_objfile::age_comp_units ()
23578 /* Start by clearing all marks. */
23579 for (auto pair
: m_dwarf2_cus
)
23580 pair
.second
->mark
= false;
23582 /* Traverse all CUs, mark them and their dependencies if used recently
23584 for (auto pair
: m_dwarf2_cus
)
23586 dwarf2_cu
*cu
= pair
.second
;
23589 if (cu
->last_used
<= dwarf_max_cache_age
)
23593 /* Delete all CUs still not marked. */
23594 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23596 dwarf2_cu
*cu
= it
->second
;
23601 it
= m_dwarf2_cus
.erase (it
);
23611 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23613 auto it
= m_dwarf2_cus
.find (per_cu
);
23614 if (it
== m_dwarf2_cus
.end ())
23619 m_dwarf2_cus
.erase (it
);
23622 dwarf2_per_objfile::~dwarf2_per_objfile ()
23627 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23628 We store these in a hash table separate from the DIEs, and preserve them
23629 when the DIEs are flushed out of cache.
23631 The CU "per_cu" pointer is needed because offset alone is not enough to
23632 uniquely identify the type. A file may have multiple .debug_types sections,
23633 or the type may come from a DWO file. Furthermore, while it's more logical
23634 to use per_cu->section+offset, with Fission the section with the data is in
23635 the DWO file but we don't know that section at the point we need it.
23636 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23637 because we can enter the lookup routine, get_die_type_at_offset, from
23638 outside this file, and thus won't necessarily have PER_CU->cu.
23639 Fortunately, PER_CU is stable for the life of the objfile. */
23641 struct dwarf2_per_cu_offset_and_type
23643 const struct dwarf2_per_cu_data
*per_cu
;
23644 sect_offset sect_off
;
23648 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23651 per_cu_offset_and_type_hash (const void *item
)
23653 const struct dwarf2_per_cu_offset_and_type
*ofs
23654 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23656 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23659 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23662 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23664 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23665 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23666 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23667 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23669 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23670 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23673 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23674 table if necessary. For convenience, return TYPE.
23676 The DIEs reading must have careful ordering to:
23677 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23678 reading current DIE.
23679 * Not trying to dereference contents of still incompletely read in types
23680 while reading in other DIEs.
23681 * Enable referencing still incompletely read in types just by a pointer to
23682 the type without accessing its fields.
23684 Therefore caller should follow these rules:
23685 * Try to fetch any prerequisite types we may need to build this DIE type
23686 before building the type and calling set_die_type.
23687 * After building type call set_die_type for current DIE as soon as
23688 possible before fetching more types to complete the current type.
23689 * Make the type as complete as possible before fetching more types. */
23691 static struct type
*
23692 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23694 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23695 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23696 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23697 struct attribute
*attr
;
23698 struct dynamic_prop prop
;
23700 /* For Ada types, make sure that the gnat-specific data is always
23701 initialized (if not already set). There are a few types where
23702 we should not be doing so, because the type-specific area is
23703 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23704 where the type-specific area is used to store the floatformat).
23705 But this is not a problem, because the gnat-specific information
23706 is actually not needed for these types. */
23707 if (need_gnat_info (cu
)
23708 && type
->code () != TYPE_CODE_FUNC
23709 && type
->code () != TYPE_CODE_FLT
23710 && type
->code () != TYPE_CODE_METHODPTR
23711 && type
->code () != TYPE_CODE_MEMBERPTR
23712 && type
->code () != TYPE_CODE_METHOD
23713 && !HAVE_GNAT_AUX_INFO (type
))
23714 INIT_GNAT_SPECIFIC (type
);
23716 /* Read DW_AT_allocated and set in type. */
23717 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23718 if (attr
!= NULL
&& attr
->form_is_block ())
23720 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23721 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23722 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23724 else if (attr
!= NULL
)
23726 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23727 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23728 sect_offset_str (die
->sect_off
));
23731 /* Read DW_AT_associated and set in type. */
23732 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23733 if (attr
!= NULL
&& attr
->form_is_block ())
23735 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23736 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23737 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23739 else if (attr
!= NULL
)
23741 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23742 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23743 sect_offset_str (die
->sect_off
));
23746 /* Read DW_AT_data_location and set in type. */
23747 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23748 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23749 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23751 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23752 dwarf2_per_objfile
->die_type_hash
23753 = htab_up (htab_create_alloc (127,
23754 per_cu_offset_and_type_hash
,
23755 per_cu_offset_and_type_eq
,
23756 NULL
, xcalloc
, xfree
));
23758 ofs
.per_cu
= cu
->per_cu
;
23759 ofs
.sect_off
= die
->sect_off
;
23761 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23762 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23764 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23765 sect_offset_str (die
->sect_off
));
23766 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23767 struct dwarf2_per_cu_offset_and_type
);
23772 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23773 or return NULL if the die does not have a saved type. */
23775 static struct type
*
23776 get_die_type_at_offset (sect_offset sect_off
,
23777 dwarf2_per_cu_data
*per_cu
,
23778 dwarf2_per_objfile
*dwarf2_per_objfile
)
23780 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23782 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23785 ofs
.per_cu
= per_cu
;
23786 ofs
.sect_off
= sect_off
;
23787 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23788 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23795 /* Look up the type for DIE in CU in die_type_hash,
23796 or return NULL if DIE does not have a saved type. */
23798 static struct type
*
23799 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23801 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23804 /* Add a dependence relationship from CU to REF_PER_CU. */
23807 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23808 struct dwarf2_per_cu_data
*ref_per_cu
)
23812 if (cu
->dependencies
== NULL
)
23814 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23815 NULL
, &cu
->comp_unit_obstack
,
23816 hashtab_obstack_allocate
,
23817 dummy_obstack_deallocate
);
23819 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23821 *slot
= ref_per_cu
;
23824 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23825 Set the mark field in every compilation unit in the
23826 cache that we must keep because we are keeping CU.
23828 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23831 dwarf2_mark_helper (void **slot
, void *data
)
23833 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23834 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23835 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23837 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23838 reading of the chain. As such dependencies remain valid it is not much
23839 useful to track and undo them during QUIT cleanups. */
23848 if (cu
->dependencies
!= nullptr)
23849 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23854 /* Set the mark field in CU and in every other compilation unit in the
23855 cache that we must keep because we are keeping CU. */
23858 dwarf2_mark (struct dwarf2_cu
*cu
)
23865 if (cu
->dependencies
!= nullptr)
23866 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
23869 /* Trivial hash function for partial_die_info: the hash value of a DIE
23870 is its offset in .debug_info for this objfile. */
23873 partial_die_hash (const void *item
)
23875 const struct partial_die_info
*part_die
23876 = (const struct partial_die_info
*) item
;
23878 return to_underlying (part_die
->sect_off
);
23881 /* Trivial comparison function for partial_die_info structures: two DIEs
23882 are equal if they have the same offset. */
23885 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23887 const struct partial_die_info
*part_die_lhs
23888 = (const struct partial_die_info
*) item_lhs
;
23889 const struct partial_die_info
*part_die_rhs
23890 = (const struct partial_die_info
*) item_rhs
;
23892 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23895 struct cmd_list_element
*set_dwarf_cmdlist
;
23896 struct cmd_list_element
*show_dwarf_cmdlist
;
23899 show_check_physname (struct ui_file
*file
, int from_tty
,
23900 struct cmd_list_element
*c
, const char *value
)
23902 fprintf_filtered (file
,
23903 _("Whether to check \"physname\" is %s.\n"),
23907 void _initialize_dwarf2_read ();
23909 _initialize_dwarf2_read ()
23911 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23912 Set DWARF specific variables.\n\
23913 Configure DWARF variables such as the cache size."),
23914 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23915 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23917 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23918 Show DWARF specific variables.\n\
23919 Show DWARF variables such as the cache size."),
23920 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23921 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23923 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23924 &dwarf_max_cache_age
, _("\
23925 Set the upper bound on the age of cached DWARF compilation units."), _("\
23926 Show the upper bound on the age of cached DWARF compilation units."), _("\
23927 A higher limit means that cached compilation units will be stored\n\
23928 in memory longer, and more total memory will be used. Zero disables\n\
23929 caching, which can slow down startup."),
23931 show_dwarf_max_cache_age
,
23932 &set_dwarf_cmdlist
,
23933 &show_dwarf_cmdlist
);
23935 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23936 Set debugging of the DWARF reader."), _("\
23937 Show debugging of the DWARF reader."), _("\
23938 When enabled (non-zero), debugging messages are printed during DWARF\n\
23939 reading and symtab expansion. A value of 1 (one) provides basic\n\
23940 information. A value greater than 1 provides more verbose information."),
23943 &setdebuglist
, &showdebuglist
);
23945 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23946 Set debugging of the DWARF DIE reader."), _("\
23947 Show debugging of the DWARF DIE reader."), _("\
23948 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23949 The value is the maximum depth to print."),
23952 &setdebuglist
, &showdebuglist
);
23954 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23955 Set debugging of the dwarf line reader."), _("\
23956 Show debugging of the dwarf line reader."), _("\
23957 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23958 A value of 1 (one) provides basic information.\n\
23959 A value greater than 1 provides more verbose information."),
23962 &setdebuglist
, &showdebuglist
);
23964 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23965 Set cross-checking of \"physname\" code against demangler."), _("\
23966 Show cross-checking of \"physname\" code against demangler."), _("\
23967 When enabled, GDB's internal \"physname\" code is checked against\n\
23969 NULL
, show_check_physname
,
23970 &setdebuglist
, &showdebuglist
);
23972 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23973 no_class
, &use_deprecated_index_sections
, _("\
23974 Set whether to use deprecated gdb_index sections."), _("\
23975 Show whether to use deprecated gdb_index sections."), _("\
23976 When enabled, deprecated .gdb_index sections are used anyway.\n\
23977 Normally they are ignored either because of a missing feature or\n\
23978 performance issue.\n\
23979 Warning: This option must be enabled before gdb reads the file."),
23982 &setlist
, &showlist
);
23984 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23985 &dwarf2_locexpr_funcs
);
23986 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23987 &dwarf2_loclist_funcs
);
23989 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23990 &dwarf2_block_frame_base_locexpr_funcs
);
23991 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23992 &dwarf2_block_frame_base_loclist_funcs
);
23995 selftests::register_test ("dw2_expand_symtabs_matching",
23996 selftests::dw2_expand_symtabs_matching::run_test
);
23997 selftests::register_test ("dwarf2_find_containing_comp_unit",
23998 selftests::find_containing_comp_unit::run_test
);