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"
50 #include "gdb-demangle.h"
51 #include "filenames.h" /* for DOSish file names */
53 #include "complaints.h"
54 #include "dwarf2/expr.h"
55 #include "dwarf2/loc.h"
56 #include "cp-support.h"
62 #include "typeprint.h"
67 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb/gdb-index.h"
73 #include "namespace.h"
74 #include "gdbsupport/function-view.h"
75 #include "gdbsupport/gdb_optional.h"
76 #include "gdbsupport/underlying.h"
77 #include "gdbsupport/hash_enum.h"
78 #include "filename-seen-cache.h"
82 #include <unordered_map>
83 #include "gdbsupport/selftest.h"
84 #include "rust-lang.h"
85 #include "gdbsupport/pathstuff.h"
86 #include "count-one-bits.h"
87 #include "debuginfod-support.h"
89 /* When == 1, print basic high level tracing messages.
90 When > 1, be more verbose.
91 This is in contrast to the low level DIE reading of dwarf_die_debug. */
92 static unsigned int dwarf_read_debug
= 0;
94 /* When non-zero, dump DIEs after they are read in. */
95 static unsigned int dwarf_die_debug
= 0;
97 /* When non-zero, dump line number entries as they are read in. */
98 unsigned int dwarf_line_debug
= 0;
100 /* When true, cross-check physname against demangler. */
101 static bool check_physname
= false;
103 /* When true, do not reject deprecated .gdb_index sections. */
104 static bool use_deprecated_index_sections
= false;
106 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
108 /* The "aclass" indices for various kinds of computed DWARF symbols. */
110 static int dwarf2_locexpr_index
;
111 static int dwarf2_loclist_index
;
112 static int dwarf2_locexpr_block_index
;
113 static int dwarf2_loclist_block_index
;
115 /* An index into a (C++) symbol name component in a symbol name as
116 recorded in the mapped_index's symbol table. For each C++ symbol
117 in the symbol table, we record one entry for the start of each
118 component in the symbol in a table of name components, and then
119 sort the table, in order to be able to binary search symbol names,
120 ignoring leading namespaces, both completion and regular look up.
121 For example, for symbol "A::B::C", we'll have an entry that points
122 to "A::B::C", another that points to "B::C", and another for "C".
123 Note that function symbols in GDB index have no parameter
124 information, just the function/method names. You can convert a
125 name_component to a "const char *" using the
126 'mapped_index::symbol_name_at(offset_type)' method. */
128 struct name_component
130 /* Offset in the symbol name where the component starts. Stored as
131 a (32-bit) offset instead of a pointer to save memory and improve
132 locality on 64-bit architectures. */
133 offset_type name_offset
;
135 /* The symbol's index in the symbol and constant pool tables of a
140 /* Base class containing bits shared by both .gdb_index and
141 .debug_name indexes. */
143 struct mapped_index_base
145 mapped_index_base () = default;
146 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
148 /* The name_component table (a sorted vector). See name_component's
149 description above. */
150 std::vector
<name_component
> name_components
;
152 /* How NAME_COMPONENTS is sorted. */
153 enum case_sensitivity name_components_casing
;
155 /* Return the number of names in the symbol table. */
156 virtual size_t symbol_name_count () const = 0;
158 /* Get the name of the symbol at IDX in the symbol table. */
159 virtual const char *symbol_name_at (offset_type idx
) const = 0;
161 /* Return whether the name at IDX in the symbol table should be
163 virtual bool symbol_name_slot_invalid (offset_type idx
) const
168 /* Build the symbol name component sorted vector, if we haven't
170 void build_name_components ();
172 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
173 possible matches for LN_NO_PARAMS in the name component
175 std::pair
<std::vector
<name_component
>::const_iterator
,
176 std::vector
<name_component
>::const_iterator
>
177 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
178 enum language lang
) const;
180 /* Prevent deleting/destroying via a base class pointer. */
182 ~mapped_index_base() = default;
185 /* A description of the mapped index. The file format is described in
186 a comment by the code that writes the index. */
187 struct mapped_index final
: public mapped_index_base
189 /* A slot/bucket in the symbol table hash. */
190 struct symbol_table_slot
192 const offset_type name
;
193 const offset_type vec
;
196 /* Index data format version. */
199 /* The address table data. */
200 gdb::array_view
<const gdb_byte
> address_table
;
202 /* The symbol table, implemented as a hash table. */
203 gdb::array_view
<symbol_table_slot
> symbol_table
;
205 /* A pointer to the constant pool. */
206 const char *constant_pool
= nullptr;
208 bool symbol_name_slot_invalid (offset_type idx
) const override
210 const auto &bucket
= this->symbol_table
[idx
];
211 return bucket
.name
== 0 && bucket
.vec
== 0;
214 /* Convenience method to get at the name of the symbol at IDX in the
216 const char *symbol_name_at (offset_type idx
) const override
217 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
219 size_t symbol_name_count () const override
220 { return this->symbol_table
.size (); }
223 /* A description of the mapped .debug_names.
224 Uninitialized map has CU_COUNT 0. */
225 struct mapped_debug_names final
: public mapped_index_base
227 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
228 : dwarf2_per_objfile (dwarf2_per_objfile_
)
231 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
232 bfd_endian dwarf5_byte_order
;
233 bool dwarf5_is_dwarf64
;
234 bool augmentation_is_gdb
;
236 uint32_t cu_count
= 0;
237 uint32_t tu_count
, bucket_count
, name_count
;
238 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
239 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
240 const gdb_byte
*name_table_string_offs_reordered
;
241 const gdb_byte
*name_table_entry_offs_reordered
;
242 const gdb_byte
*entry_pool
;
249 /* Attribute name DW_IDX_*. */
252 /* Attribute form DW_FORM_*. */
255 /* Value if FORM is DW_FORM_implicit_const. */
256 LONGEST implicit_const
;
258 std::vector
<attr
> attr_vec
;
261 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
263 const char *namei_to_name (uint32_t namei
) const;
265 /* Implementation of the mapped_index_base virtual interface, for
266 the name_components cache. */
268 const char *symbol_name_at (offset_type idx
) const override
269 { return namei_to_name (idx
); }
271 size_t symbol_name_count () const override
272 { return this->name_count
; }
275 /* See dwarf2read.h. */
278 get_dwarf2_per_objfile (struct objfile
*objfile
)
280 return dwarf2_objfile_data_key
.get (objfile
);
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_loclists", ".zdebug_loclists" },
295 { ".debug_macinfo", ".zdebug_macinfo" },
296 { ".debug_macro", ".zdebug_macro" },
297 { ".debug_str", ".zdebug_str" },
298 { ".debug_str_offsets", ".zdebug_str_offsets" },
299 { ".debug_line_str", ".zdebug_line_str" },
300 { ".debug_ranges", ".zdebug_ranges" },
301 { ".debug_rnglists", ".zdebug_rnglists" },
302 { ".debug_types", ".zdebug_types" },
303 { ".debug_addr", ".zdebug_addr" },
304 { ".debug_frame", ".zdebug_frame" },
305 { ".eh_frame", NULL
},
306 { ".gdb_index", ".zgdb_index" },
307 { ".debug_names", ".zdebug_names" },
308 { ".debug_aranges", ".zdebug_aranges" },
312 /* List of DWO/DWP sections. */
314 static const struct dwop_section_names
316 struct dwarf2_section_names abbrev_dwo
;
317 struct dwarf2_section_names info_dwo
;
318 struct dwarf2_section_names line_dwo
;
319 struct dwarf2_section_names loc_dwo
;
320 struct dwarf2_section_names loclists_dwo
;
321 struct dwarf2_section_names macinfo_dwo
;
322 struct dwarf2_section_names macro_dwo
;
323 struct dwarf2_section_names str_dwo
;
324 struct dwarf2_section_names str_offsets_dwo
;
325 struct dwarf2_section_names types_dwo
;
326 struct dwarf2_section_names cu_index
;
327 struct dwarf2_section_names tu_index
;
331 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
332 { ".debug_info.dwo", ".zdebug_info.dwo" },
333 { ".debug_line.dwo", ".zdebug_line.dwo" },
334 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
335 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
336 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
337 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
338 { ".debug_str.dwo", ".zdebug_str.dwo" },
339 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
340 { ".debug_types.dwo", ".zdebug_types.dwo" },
341 { ".debug_cu_index", ".zdebug_cu_index" },
342 { ".debug_tu_index", ".zdebug_tu_index" },
345 /* local data types */
347 /* Type used for delaying computation of method physnames.
348 See comments for compute_delayed_physnames. */
349 struct delayed_method_info
351 /* The type to which the method is attached, i.e., its parent class. */
354 /* The index of the method in the type's function fieldlists. */
357 /* The index of the method in the fieldlist. */
360 /* The name of the DIE. */
363 /* The DIE associated with this method. */
364 struct die_info
*die
;
367 /* Internal state when decoding a particular compilation unit. */
370 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
373 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
375 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
376 Create the set of symtabs used by this TU, or if this TU is sharing
377 symtabs with another TU and the symtabs have already been created
378 then restore those symtabs in the line header.
379 We don't need the pc/line-number mapping for type units. */
380 void setup_type_unit_groups (struct die_info
*die
);
382 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
383 buildsym_compunit constructor. */
384 struct compunit_symtab
*start_symtab (const char *name
,
385 const char *comp_dir
,
388 /* Reset the builder. */
389 void reset_builder () { m_builder
.reset (); }
391 /* The header of the compilation unit. */
392 struct comp_unit_head header
{};
394 /* Base address of this compilation unit. */
395 CORE_ADDR base_address
= 0;
397 /* Non-zero if base_address has been set. */
400 /* The language we are debugging. */
401 enum language language
= language_unknown
;
402 const struct language_defn
*language_defn
= nullptr;
404 const char *producer
= nullptr;
407 /* The symtab builder for this CU. This is only non-NULL when full
408 symbols are being read. */
409 std::unique_ptr
<buildsym_compunit
> m_builder
;
412 /* The generic symbol table building routines have separate lists for
413 file scope symbols and all all other scopes (local scopes). So
414 we need to select the right one to pass to add_symbol_to_list().
415 We do it by keeping a pointer to the correct list in list_in_scope.
417 FIXME: The original dwarf code just treated the file scope as the
418 first local scope, and all other local scopes as nested local
419 scopes, and worked fine. Check to see if we really need to
420 distinguish these in buildsym.c. */
421 struct pending
**list_in_scope
= nullptr;
423 /* Hash table holding all the loaded partial DIEs
424 with partial_die->offset.SECT_OFF as hash. */
425 htab_t partial_dies
= nullptr;
427 /* Storage for things with the same lifetime as this read-in compilation
428 unit, including partial DIEs. */
429 auto_obstack comp_unit_obstack
;
431 /* When multiple dwarf2_cu structures are living in memory, this field
432 chains them all together, so that they can be released efficiently.
433 We will probably also want a generation counter so that most-recently-used
434 compilation units are cached... */
435 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
437 /* Backlink to our per_cu entry. */
438 struct dwarf2_per_cu_data
*per_cu
;
440 /* How many compilation units ago was this CU last referenced? */
443 /* A hash table of DIE cu_offset for following references with
444 die_info->offset.sect_off as hash. */
445 htab_t die_hash
= nullptr;
447 /* Full DIEs if read in. */
448 struct die_info
*dies
= nullptr;
450 /* A set of pointers to dwarf2_per_cu_data objects for compilation
451 units referenced by this one. Only set during full symbol processing;
452 partial symbol tables do not have dependencies. */
453 htab_t dependencies
= nullptr;
455 /* Header data from the line table, during full symbol processing. */
456 struct line_header
*line_header
= nullptr;
457 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
458 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
459 this is the DW_TAG_compile_unit die for this CU. We'll hold on
460 to the line header as long as this DIE is being processed. See
461 process_die_scope. */
462 die_info
*line_header_die_owner
= nullptr;
464 /* A list of methods which need to have physnames computed
465 after all type information has been read. */
466 std::vector
<delayed_method_info
> method_list
;
468 /* To be copied to symtab->call_site_htab. */
469 htab_t call_site_htab
= nullptr;
471 /* Non-NULL if this CU came from a DWO file.
472 There is an invariant here that is important to remember:
473 Except for attributes copied from the top level DIE in the "main"
474 (or "stub") file in preparation for reading the DWO file
475 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
476 Either there isn't a DWO file (in which case this is NULL and the point
477 is moot), or there is and either we're not going to read it (in which
478 case this is NULL) or there is and we are reading it (in which case this
480 struct dwo_unit
*dwo_unit
= nullptr;
482 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
483 Note this value comes from the Fission stub CU/TU's DIE. */
484 gdb::optional
<ULONGEST
> addr_base
;
486 /* The DW_AT_rnglists_base attribute if present.
487 Note this value comes from the Fission stub CU/TU's DIE.
488 Also note that the value is zero in the non-DWO case so this value can
489 be used without needing to know whether DWO files are in use or not.
490 N.B. This does not apply to DW_AT_ranges appearing in
491 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
492 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
493 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
494 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
495 ULONGEST ranges_base
= 0;
497 /* When reading debug info generated by older versions of rustc, we
498 have to rewrite some union types to be struct types with a
499 variant part. This rewriting must be done after the CU is fully
500 read in, because otherwise at the point of rewriting some struct
501 type might not have been fully processed. So, we keep a list of
502 all such types here and process them after expansion. */
503 std::vector
<struct type
*> rust_unions
;
505 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
506 files, the value is implicitly zero. For DWARF 5 version DWO files, the
507 value is often implicit and is the size of the header of
508 .debug_str_offsets section (8 or 4, depending on the address size). */
509 gdb::optional
<ULONGEST
> str_offsets_base
;
511 /* Mark used when releasing cached dies. */
514 /* This CU references .debug_loc. See the symtab->locations_valid field.
515 This test is imperfect as there may exist optimized debug code not using
516 any location list and still facing inlining issues if handled as
517 unoptimized code. For a future better test see GCC PR other/32998. */
518 bool has_loclist
: 1;
520 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
521 if all the producer_is_* fields are valid. This information is cached
522 because profiling CU expansion showed excessive time spent in
523 producer_is_gxx_lt_4_6. */
524 bool checked_producer
: 1;
525 bool producer_is_gxx_lt_4_6
: 1;
526 bool producer_is_gcc_lt_4_3
: 1;
527 bool producer_is_icc
: 1;
528 bool producer_is_icc_lt_14
: 1;
529 bool producer_is_codewarrior
: 1;
531 /* When true, the file that we're processing is known to have
532 debugging info for C++ namespaces. GCC 3.3.x did not produce
533 this information, but later versions do. */
535 bool processing_has_namespace_info
: 1;
537 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
539 /* If this CU was inherited by another CU (via specification,
540 abstract_origin, etc), this is the ancestor CU. */
543 /* Get the buildsym_compunit for this CU. */
544 buildsym_compunit
*get_builder ()
546 /* If this CU has a builder associated with it, use that. */
547 if (m_builder
!= nullptr)
548 return m_builder
.get ();
550 /* Otherwise, search ancestors for a valid builder. */
551 if (ancestor
!= nullptr)
552 return ancestor
->get_builder ();
558 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
559 This includes type_unit_group and quick_file_names. */
561 struct stmt_list_hash
563 /* The DWO unit this table is from or NULL if there is none. */
564 struct dwo_unit
*dwo_unit
;
566 /* Offset in .debug_line or .debug_line.dwo. */
567 sect_offset line_sect_off
;
570 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
571 an object of this type. */
573 struct type_unit_group
575 /* dwarf2read.c's main "handle" on a TU symtab.
576 To simplify things we create an artificial CU that "includes" all the
577 type units using this stmt_list so that the rest of the code still has
578 a "per_cu" handle on the symtab. */
579 struct dwarf2_per_cu_data per_cu
;
581 /* The TUs that share this DW_AT_stmt_list entry.
582 This is added to while parsing type units to build partial symtabs,
583 and is deleted afterwards and not used again. */
584 std::vector
<signatured_type
*> *tus
;
586 /* The compunit symtab.
587 Type units in a group needn't all be defined in the same source file,
588 so we create an essentially anonymous symtab as the compunit symtab. */
589 struct compunit_symtab
*compunit_symtab
;
591 /* The data used to construct the hash key. */
592 struct stmt_list_hash hash
;
594 /* The symbol tables for this TU (obtained from the files listed in
596 WARNING: The order of entries here must match the order of entries
597 in the line header. After the first TU using this type_unit_group, the
598 line header for the subsequent TUs is recreated from this. This is done
599 because we need to use the same symtabs for each TU using the same
600 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
601 there's no guarantee the line header doesn't have duplicate entries. */
602 struct symtab
**symtabs
;
605 /* These sections are what may appear in a (real or virtual) DWO file. */
609 struct dwarf2_section_info abbrev
;
610 struct dwarf2_section_info line
;
611 struct dwarf2_section_info loc
;
612 struct dwarf2_section_info loclists
;
613 struct dwarf2_section_info macinfo
;
614 struct dwarf2_section_info macro
;
615 struct dwarf2_section_info str
;
616 struct dwarf2_section_info str_offsets
;
617 /* In the case of a virtual DWO file, these two are unused. */
618 struct dwarf2_section_info info
;
619 std::vector
<dwarf2_section_info
> types
;
622 /* CUs/TUs in DWP/DWO files. */
626 /* Backlink to the containing struct dwo_file. */
627 struct dwo_file
*dwo_file
;
629 /* The "id" that distinguishes this CU/TU.
630 .debug_info calls this "dwo_id", .debug_types calls this "signature".
631 Since signatures came first, we stick with it for consistency. */
634 /* The section this CU/TU lives in, in the DWO file. */
635 struct dwarf2_section_info
*section
;
637 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
638 sect_offset sect_off
;
641 /* For types, offset in the type's DIE of the type defined by this TU. */
642 cu_offset type_offset_in_tu
;
645 /* include/dwarf2.h defines the DWP section codes.
646 It defines a max value but it doesn't define a min value, which we
647 use for error checking, so provide one. */
649 enum dwp_v2_section_ids
654 /* Data for one DWO file.
656 This includes virtual DWO files (a virtual DWO file is a DWO file as it
657 appears in a DWP file). DWP files don't really have DWO files per se -
658 comdat folding of types "loses" the DWO file they came from, and from
659 a high level view DWP files appear to contain a mass of random types.
660 However, to maintain consistency with the non-DWP case we pretend DWP
661 files contain virtual DWO files, and we assign each TU with one virtual
662 DWO file (generally based on the line and abbrev section offsets -
663 a heuristic that seems to work in practice). */
667 dwo_file () = default;
668 DISABLE_COPY_AND_ASSIGN (dwo_file
);
670 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
671 For virtual DWO files the name is constructed from the section offsets
672 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
673 from related CU+TUs. */
674 const char *dwo_name
= nullptr;
676 /* The DW_AT_comp_dir attribute. */
677 const char *comp_dir
= nullptr;
679 /* The bfd, when the file is open. Otherwise this is NULL.
680 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
681 gdb_bfd_ref_ptr dbfd
;
683 /* The sections that make up this DWO file.
684 Remember that for virtual DWO files in DWP V2, these are virtual
685 sections (for lack of a better name). */
686 struct dwo_sections sections
{};
688 /* The CUs in the file.
689 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
690 an extension to handle LLVM's Link Time Optimization output (where
691 multiple source files may be compiled into a single object/dwo pair). */
694 /* Table of TUs in the file.
695 Each element is a struct dwo_unit. */
699 /* These sections are what may appear in a DWP file. */
703 /* These are used by both DWP version 1 and 2. */
704 struct dwarf2_section_info str
;
705 struct dwarf2_section_info cu_index
;
706 struct dwarf2_section_info tu_index
;
708 /* These are only used by DWP version 2 files.
709 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
710 sections are referenced by section number, and are not recorded here.
711 In DWP version 2 there is at most one copy of all these sections, each
712 section being (effectively) comprised of the concatenation of all of the
713 individual sections that exist in the version 1 format.
714 To keep the code simple we treat each of these concatenated pieces as a
715 section itself (a virtual section?). */
716 struct dwarf2_section_info abbrev
;
717 struct dwarf2_section_info info
;
718 struct dwarf2_section_info line
;
719 struct dwarf2_section_info loc
;
720 struct dwarf2_section_info macinfo
;
721 struct dwarf2_section_info macro
;
722 struct dwarf2_section_info str_offsets
;
723 struct dwarf2_section_info types
;
726 /* These sections are what may appear in a virtual DWO file in DWP version 1.
727 A virtual DWO file is a DWO file as it appears in a DWP file. */
729 struct virtual_v1_dwo_sections
731 struct dwarf2_section_info abbrev
;
732 struct dwarf2_section_info line
;
733 struct dwarf2_section_info loc
;
734 struct dwarf2_section_info macinfo
;
735 struct dwarf2_section_info macro
;
736 struct dwarf2_section_info str_offsets
;
737 /* Each DWP hash table entry records one CU or one TU.
738 That is recorded here, and copied to dwo_unit.section. */
739 struct dwarf2_section_info info_or_types
;
742 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
743 In version 2, the sections of the DWO files are concatenated together
744 and stored in one section of that name. Thus each ELF section contains
745 several "virtual" sections. */
747 struct virtual_v2_dwo_sections
749 bfd_size_type abbrev_offset
;
750 bfd_size_type abbrev_size
;
752 bfd_size_type line_offset
;
753 bfd_size_type line_size
;
755 bfd_size_type loc_offset
;
756 bfd_size_type loc_size
;
758 bfd_size_type macinfo_offset
;
759 bfd_size_type macinfo_size
;
761 bfd_size_type macro_offset
;
762 bfd_size_type macro_size
;
764 bfd_size_type str_offsets_offset
;
765 bfd_size_type str_offsets_size
;
767 /* Each DWP hash table entry records one CU or one TU.
768 That is recorded here, and copied to dwo_unit.section. */
769 bfd_size_type info_or_types_offset
;
770 bfd_size_type info_or_types_size
;
773 /* Contents of DWP hash tables. */
775 struct dwp_hash_table
777 uint32_t version
, nr_columns
;
778 uint32_t nr_units
, nr_slots
;
779 const gdb_byte
*hash_table
, *unit_table
;
784 const gdb_byte
*indices
;
788 /* This is indexed by column number and gives the id of the section
790 #define MAX_NR_V2_DWO_SECTIONS \
791 (1 /* .debug_info or .debug_types */ \
792 + 1 /* .debug_abbrev */ \
793 + 1 /* .debug_line */ \
794 + 1 /* .debug_loc */ \
795 + 1 /* .debug_str_offsets */ \
796 + 1 /* .debug_macro or .debug_macinfo */)
797 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
798 const gdb_byte
*offsets
;
799 const gdb_byte
*sizes
;
804 /* Data for one DWP file. */
808 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
810 dbfd (std::move (abfd
))
814 /* Name of the file. */
817 /* File format version. */
821 gdb_bfd_ref_ptr dbfd
;
823 /* Section info for this file. */
824 struct dwp_sections sections
{};
826 /* Table of CUs in the file. */
827 const struct dwp_hash_table
*cus
= nullptr;
829 /* Table of TUs in the file. */
830 const struct dwp_hash_table
*tus
= nullptr;
832 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
836 /* Table to map ELF section numbers to their sections.
837 This is only needed for the DWP V1 file format. */
838 unsigned int num_sections
= 0;
839 asection
**elf_sections
= nullptr;
842 /* Struct used to pass misc. parameters to read_die_and_children, et
843 al. which are used for both .debug_info and .debug_types dies.
844 All parameters here are unchanging for the life of the call. This
845 struct exists to abstract away the constant parameters of die reading. */
847 struct die_reader_specs
849 /* The bfd of die_section. */
852 /* The CU of the DIE we are parsing. */
853 struct dwarf2_cu
*cu
;
855 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
856 struct dwo_file
*dwo_file
;
858 /* The section the die comes from.
859 This is either .debug_info or .debug_types, or the .dwo variants. */
860 struct dwarf2_section_info
*die_section
;
862 /* die_section->buffer. */
863 const gdb_byte
*buffer
;
865 /* The end of the buffer. */
866 const gdb_byte
*buffer_end
;
868 /* The abbreviation table to use when reading the DIEs. */
869 struct abbrev_table
*abbrev_table
;
872 /* A subclass of die_reader_specs that holds storage and has complex
873 constructor and destructor behavior. */
875 class cutu_reader
: public die_reader_specs
879 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
880 struct abbrev_table
*abbrev_table
,
884 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
885 struct dwarf2_cu
*parent_cu
= nullptr,
886 struct dwo_file
*dwo_file
= nullptr);
888 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
890 const gdb_byte
*info_ptr
= nullptr;
891 struct die_info
*comp_unit_die
= nullptr;
892 bool dummy_p
= false;
894 /* Release the new CU, putting it on the chain. This cannot be done
899 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
900 int use_existing_cu
);
902 struct dwarf2_per_cu_data
*m_this_cu
;
903 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
905 /* The ordinary abbreviation table. */
906 abbrev_table_up m_abbrev_table_holder
;
908 /* The DWO abbreviation table. */
909 abbrev_table_up m_dwo_abbrev_table
;
912 /* When we construct a partial symbol table entry we only
913 need this much information. */
914 struct partial_die_info
: public allocate_on_obstack
916 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
918 /* Disable assign but still keep copy ctor, which is needed
919 load_partial_dies. */
920 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
922 /* Adjust the partial die before generating a symbol for it. This
923 function may set the is_external flag or change the DIE's
925 void fixup (struct dwarf2_cu
*cu
);
927 /* Read a minimal amount of information into the minimal die
929 const gdb_byte
*read (const struct die_reader_specs
*reader
,
930 const struct abbrev_info
&abbrev
,
931 const gdb_byte
*info_ptr
);
933 /* Offset of this DIE. */
934 const sect_offset sect_off
;
936 /* DWARF-2 tag for this DIE. */
937 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
939 /* Assorted flags describing the data found in this DIE. */
940 const unsigned int has_children
: 1;
942 unsigned int is_external
: 1;
943 unsigned int is_declaration
: 1;
944 unsigned int has_type
: 1;
945 unsigned int has_specification
: 1;
946 unsigned int has_pc_info
: 1;
947 unsigned int may_be_inlined
: 1;
949 /* This DIE has been marked DW_AT_main_subprogram. */
950 unsigned int main_subprogram
: 1;
952 /* Flag set if the SCOPE field of this structure has been
954 unsigned int scope_set
: 1;
956 /* Flag set if the DIE has a byte_size attribute. */
957 unsigned int has_byte_size
: 1;
959 /* Flag set if the DIE has a DW_AT_const_value attribute. */
960 unsigned int has_const_value
: 1;
962 /* Flag set if any of the DIE's children are template arguments. */
963 unsigned int has_template_arguments
: 1;
965 /* Flag set if fixup has been called on this die. */
966 unsigned int fixup_called
: 1;
968 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
969 unsigned int is_dwz
: 1;
971 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
972 unsigned int spec_is_dwz
: 1;
974 /* The name of this DIE. Normally the value of DW_AT_name, but
975 sometimes a default name for unnamed DIEs. */
976 const char *name
= nullptr;
978 /* The linkage name, if present. */
979 const char *linkage_name
= nullptr;
981 /* The scope to prepend to our children. This is generally
982 allocated on the comp_unit_obstack, so will disappear
983 when this compilation unit leaves the cache. */
984 const char *scope
= nullptr;
986 /* Some data associated with the partial DIE. The tag determines
987 which field is live. */
990 /* The location description associated with this DIE, if any. */
991 struct dwarf_block
*locdesc
;
992 /* The offset of an import, for DW_TAG_imported_unit. */
993 sect_offset sect_off
;
996 /* If HAS_PC_INFO, the PC range associated with this DIE. */
998 CORE_ADDR highpc
= 0;
1000 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1001 DW_AT_sibling, if any. */
1002 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1003 could return DW_AT_sibling values to its caller load_partial_dies. */
1004 const gdb_byte
*sibling
= nullptr;
1006 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1007 DW_AT_specification (or DW_AT_abstract_origin or
1008 DW_AT_extension). */
1009 sect_offset spec_offset
{};
1011 /* Pointers to this DIE's parent, first child, and next sibling,
1013 struct partial_die_info
*die_parent
= nullptr;
1014 struct partial_die_info
*die_child
= nullptr;
1015 struct partial_die_info
*die_sibling
= nullptr;
1017 friend struct partial_die_info
*
1018 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1021 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1022 partial_die_info (sect_offset sect_off
)
1023 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1027 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1029 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1034 has_specification
= 0;
1037 main_subprogram
= 0;
1040 has_const_value
= 0;
1041 has_template_arguments
= 0;
1048 /* This data structure holds a complete die structure. */
1051 /* DWARF-2 tag for this DIE. */
1052 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1054 /* Number of attributes */
1055 unsigned char num_attrs
;
1057 /* True if we're presently building the full type name for the
1058 type derived from this DIE. */
1059 unsigned char building_fullname
: 1;
1061 /* True if this die is in process. PR 16581. */
1062 unsigned char in_process
: 1;
1064 /* True if this DIE has children. */
1065 unsigned char has_children
: 1;
1068 unsigned int abbrev
;
1070 /* Offset in .debug_info or .debug_types section. */
1071 sect_offset sect_off
;
1073 /* The dies in a compilation unit form an n-ary tree. PARENT
1074 points to this die's parent; CHILD points to the first child of
1075 this node; and all the children of a given node are chained
1076 together via their SIBLING fields. */
1077 struct die_info
*child
; /* Its first child, if any. */
1078 struct die_info
*sibling
; /* Its next sibling, if any. */
1079 struct die_info
*parent
; /* Its parent, if any. */
1081 /* An array of attributes, with NUM_ATTRS elements. There may be
1082 zero, but it's not common and zero-sized arrays are not
1083 sufficiently portable C. */
1084 struct attribute attrs
[1];
1087 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1088 but this would require a corresponding change in unpack_field_as_long
1090 static int bits_per_byte
= 8;
1092 /* When reading a variant or variant part, we track a bit more
1093 information about the field, and store it in an object of this
1096 struct variant_field
1098 /* If we see a DW_TAG_variant, then this will be the discriminant
1100 ULONGEST discriminant_value
;
1101 /* If we see a DW_TAG_variant, then this will be set if this is the
1103 bool default_branch
;
1104 /* While reading a DW_TAG_variant_part, this will be set if this
1105 field is the discriminant. */
1106 bool is_discriminant
;
1111 int accessibility
= 0;
1113 /* Extra information to describe a variant or variant part. */
1114 struct variant_field variant
{};
1115 struct field field
{};
1120 const char *name
= nullptr;
1121 std::vector
<struct fn_field
> fnfields
;
1124 /* The routines that read and process dies for a C struct or C++ class
1125 pass lists of data member fields and lists of member function fields
1126 in an instance of a field_info structure, as defined below. */
1129 /* List of data member and baseclasses fields. */
1130 std::vector
<struct nextfield
> fields
;
1131 std::vector
<struct nextfield
> baseclasses
;
1133 /* Set if the accessibility of one of the fields is not public. */
1134 int non_public_fields
= 0;
1136 /* Member function fieldlist array, contains name of possibly overloaded
1137 member function, number of overloaded member functions and a pointer
1138 to the head of the member function field chain. */
1139 std::vector
<struct fnfieldlist
> fnfieldlists
;
1141 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1142 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1143 std::vector
<struct decl_field
> typedef_field_list
;
1145 /* Nested types defined by this class and the number of elements in this
1147 std::vector
<struct decl_field
> nested_types_list
;
1149 /* Return the total number of fields (including baseclasses). */
1150 int nfields () const
1152 return fields
.size () + baseclasses
.size ();
1156 /* Loaded secondary compilation units are kept in memory until they
1157 have not been referenced for the processing of this many
1158 compilation units. Set this to zero to disable caching. Cache
1159 sizes of up to at least twenty will improve startup time for
1160 typical inter-CU-reference binaries, at an obvious memory cost. */
1161 static int dwarf_max_cache_age
= 5;
1163 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1164 struct cmd_list_element
*c
, const char *value
)
1166 fprintf_filtered (file
, _("The upper bound on the age of cached "
1167 "DWARF compilation units is %s.\n"),
1171 /* local function prototypes */
1173 static void dwarf2_find_base_address (struct die_info
*die
,
1174 struct dwarf2_cu
*cu
);
1176 static dwarf2_psymtab
*create_partial_symtab
1177 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1179 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1180 const gdb_byte
*info_ptr
,
1181 struct die_info
*type_unit_die
);
1183 static void dwarf2_build_psymtabs_hard
1184 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1186 static void scan_partial_symbols (struct partial_die_info
*,
1187 CORE_ADDR
*, CORE_ADDR
*,
1188 int, struct dwarf2_cu
*);
1190 static void add_partial_symbol (struct partial_die_info
*,
1191 struct dwarf2_cu
*);
1193 static void add_partial_namespace (struct partial_die_info
*pdi
,
1194 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1195 int set_addrmap
, struct dwarf2_cu
*cu
);
1197 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1198 CORE_ADDR
*highpc
, int set_addrmap
,
1199 struct dwarf2_cu
*cu
);
1201 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1202 struct dwarf2_cu
*cu
);
1204 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1205 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1206 int need_pc
, struct dwarf2_cu
*cu
);
1208 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1210 static struct partial_die_info
*load_partial_dies
1211 (const struct die_reader_specs
*, const gdb_byte
*, int);
1213 /* A pair of partial_die_info and compilation unit. */
1214 struct cu_partial_die_info
1216 /* The compilation unit of the partial_die_info. */
1217 struct dwarf2_cu
*cu
;
1218 /* A partial_die_info. */
1219 struct partial_die_info
*pdi
;
1221 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1227 cu_partial_die_info () = delete;
1230 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1231 struct dwarf2_cu
*);
1233 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1234 struct attribute
*, struct attr_abbrev
*,
1235 const gdb_byte
*, bool *need_reprocess
);
1237 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1238 struct attribute
*attr
);
1240 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1242 static LONGEST read_checked_initial_length_and_offset
1243 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1244 unsigned int *, unsigned int *);
1246 static sect_offset read_abbrev_offset
1247 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1248 struct dwarf2_section_info
*, sect_offset
);
1250 static const char *read_indirect_string
1251 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1252 const struct comp_unit_head
*, unsigned int *);
1254 static const char *read_indirect_line_string
1255 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1256 const struct comp_unit_head
*, unsigned int *);
1258 static const char *read_indirect_string_at_offset
1259 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1261 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1265 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1266 ULONGEST str_index
);
1268 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1269 ULONGEST str_index
);
1271 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1273 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1274 struct dwarf2_cu
*);
1276 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1279 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1280 struct dwarf2_cu
*cu
);
1282 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1284 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1285 struct dwarf2_cu
*cu
);
1287 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1289 static struct die_info
*die_specification (struct die_info
*die
,
1290 struct dwarf2_cu
**);
1292 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1293 struct dwarf2_cu
*cu
);
1295 static void dwarf_decode_lines (struct line_header
*, const char *,
1296 struct dwarf2_cu
*, dwarf2_psymtab
*,
1297 CORE_ADDR
, int decode_mapping
);
1299 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1302 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1303 struct dwarf2_cu
*, struct symbol
* = NULL
);
1305 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1306 struct dwarf2_cu
*);
1308 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1311 struct obstack
*obstack
,
1312 struct dwarf2_cu
*cu
, LONGEST
*value
,
1313 const gdb_byte
**bytes
,
1314 struct dwarf2_locexpr_baton
**baton
);
1316 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1318 static int need_gnat_info (struct dwarf2_cu
*);
1320 static struct type
*die_descriptive_type (struct die_info
*,
1321 struct dwarf2_cu
*);
1323 static void set_descriptive_type (struct type
*, struct die_info
*,
1324 struct dwarf2_cu
*);
1326 static struct type
*die_containing_type (struct die_info
*,
1327 struct dwarf2_cu
*);
1329 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1330 struct dwarf2_cu
*);
1332 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1334 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1336 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1338 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1339 const char *suffix
, int physname
,
1340 struct dwarf2_cu
*cu
);
1342 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1344 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1346 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1348 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1350 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1352 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1354 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1355 struct dwarf2_cu
*, dwarf2_psymtab
*);
1357 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1358 values. Keep the items ordered with increasing constraints compliance. */
1361 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1362 PC_BOUNDS_NOT_PRESENT
,
1364 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1365 were present but they do not form a valid range of PC addresses. */
1368 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1371 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1375 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1376 CORE_ADDR
*, CORE_ADDR
*,
1380 static void get_scope_pc_bounds (struct die_info
*,
1381 CORE_ADDR
*, CORE_ADDR
*,
1382 struct dwarf2_cu
*);
1384 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1385 CORE_ADDR
, struct dwarf2_cu
*);
1387 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1388 struct dwarf2_cu
*);
1390 static void dwarf2_attach_fields_to_type (struct field_info
*,
1391 struct type
*, struct dwarf2_cu
*);
1393 static void dwarf2_add_member_fn (struct field_info
*,
1394 struct die_info
*, struct type
*,
1395 struct dwarf2_cu
*);
1397 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1399 struct dwarf2_cu
*);
1401 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1403 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1405 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1407 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1409 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1411 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1413 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1415 static struct type
*read_module_type (struct die_info
*die
,
1416 struct dwarf2_cu
*cu
);
1418 static const char *namespace_name (struct die_info
*die
,
1419 int *is_anonymous
, struct dwarf2_cu
*);
1421 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1423 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1425 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1426 struct dwarf2_cu
*);
1428 static struct die_info
*read_die_and_siblings_1
1429 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1432 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1433 const gdb_byte
*info_ptr
,
1434 const gdb_byte
**new_info_ptr
,
1435 struct die_info
*parent
);
1437 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1438 struct die_info
**, const gdb_byte
*,
1441 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1442 struct die_info
**, const gdb_byte
*);
1444 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1446 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1449 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1451 static const char *dwarf2_full_name (const char *name
,
1452 struct die_info
*die
,
1453 struct dwarf2_cu
*cu
);
1455 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1456 struct dwarf2_cu
*cu
);
1458 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1459 struct dwarf2_cu
**);
1461 static const char *dwarf_tag_name (unsigned int);
1463 static const char *dwarf_attr_name (unsigned int);
1465 static const char *dwarf_form_name (unsigned int);
1467 static const char *dwarf_bool_name (unsigned int);
1469 static const char *dwarf_type_encoding_name (unsigned int);
1471 static struct die_info
*sibling_die (struct die_info
*);
1473 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1475 static void dump_die_for_error (struct die_info
*);
1477 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1480 /*static*/ void dump_die (struct die_info
*, int max_level
);
1482 static void store_in_ref_table (struct die_info
*,
1483 struct dwarf2_cu
*);
1485 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1487 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1489 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1490 const struct attribute
*,
1491 struct dwarf2_cu
**);
1493 static struct die_info
*follow_die_ref (struct die_info
*,
1494 const struct attribute
*,
1495 struct dwarf2_cu
**);
1497 static struct die_info
*follow_die_sig (struct die_info
*,
1498 const struct attribute
*,
1499 struct dwarf2_cu
**);
1501 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1502 struct dwarf2_cu
*);
1504 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1505 const struct attribute
*,
1506 struct dwarf2_cu
*);
1508 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1510 static void read_signatured_type (struct signatured_type
*);
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 void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1551 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1553 static struct type
*set_die_type (struct die_info
*, struct type
*,
1554 struct dwarf2_cu
*);
1556 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1558 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1560 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1563 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1566 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1569 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1570 struct dwarf2_per_cu_data
*);
1572 static void dwarf2_mark (struct dwarf2_cu
*);
1574 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1576 static struct type
*get_die_type_at_offset (sect_offset
,
1577 struct dwarf2_per_cu_data
*);
1579 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1581 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1582 enum language pretend_language
);
1584 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1586 /* Class, the destructor of which frees all allocated queue entries. This
1587 will only have work to do if an error was thrown while processing the
1588 dwarf. If no error was thrown then the queue entries should have all
1589 been processed, and freed, as we went along. */
1591 class dwarf2_queue_guard
1594 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1595 : m_per_objfile (per_objfile
)
1599 /* Free any entries remaining on the queue. There should only be
1600 entries left if we hit an error while processing the dwarf. */
1601 ~dwarf2_queue_guard ()
1603 /* Ensure that no memory is allocated by the queue. */
1604 std::queue
<dwarf2_queue_item
> empty
;
1605 std::swap (m_per_objfile
->queue
, empty
);
1608 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1611 dwarf2_per_objfile
*m_per_objfile
;
1614 dwarf2_queue_item::~dwarf2_queue_item ()
1616 /* Anything still marked queued is likely to be in an
1617 inconsistent state, so discard it. */
1620 if (per_cu
->cu
!= NULL
)
1621 free_one_cached_comp_unit (per_cu
);
1626 /* The return type of find_file_and_directory. Note, the enclosed
1627 string pointers are only valid while this object is valid. */
1629 struct file_and_directory
1631 /* The filename. This is never NULL. */
1634 /* The compilation directory. NULL if not known. If we needed to
1635 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1636 points directly to the DW_AT_comp_dir string attribute owned by
1637 the obstack that owns the DIE. */
1638 const char *comp_dir
;
1640 /* If we needed to build a new string for comp_dir, this is what
1641 owns the storage. */
1642 std::string comp_dir_storage
;
1645 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1646 struct dwarf2_cu
*cu
);
1648 static htab_up
allocate_signatured_type_table ();
1650 static htab_up
allocate_dwo_unit_table ();
1652 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1653 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1654 struct dwp_file
*dwp_file
, const char *comp_dir
,
1655 ULONGEST signature
, int is_debug_types
);
1657 static struct dwp_file
*get_dwp_file
1658 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1660 static struct dwo_unit
*lookup_dwo_comp_unit
1661 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1663 static struct dwo_unit
*lookup_dwo_type_unit
1664 (struct signatured_type
*, const char *, const char *);
1666 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1668 /* A unique pointer to a dwo_file. */
1670 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1672 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1674 static void check_producer (struct dwarf2_cu
*cu
);
1676 static void free_line_header_voidp (void *arg
);
1678 /* Various complaints about symbol reading that don't abort the process. */
1681 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1683 complaint (_("statement list doesn't fit in .debug_line section"));
1687 dwarf2_debug_line_missing_file_complaint (void)
1689 complaint (_(".debug_line section has line data without a file"));
1693 dwarf2_debug_line_missing_end_sequence_complaint (void)
1695 complaint (_(".debug_line section has line "
1696 "program sequence without an end"));
1700 dwarf2_complex_location_expr_complaint (void)
1702 complaint (_("location expression too complex"));
1706 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1709 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1714 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1716 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1720 /* Hash function for line_header_hash. */
1723 line_header_hash (const struct line_header
*ofs
)
1725 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1728 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1731 line_header_hash_voidp (const void *item
)
1733 const struct line_header
*ofs
= (const struct line_header
*) item
;
1735 return line_header_hash (ofs
);
1738 /* Equality function for line_header_hash. */
1741 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1743 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1744 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1746 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1747 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1752 /* See declaration. */
1754 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1755 const dwarf2_debug_sections
*names
,
1757 : objfile (objfile_
),
1758 can_copy (can_copy_
)
1761 names
= &dwarf2_elf_names
;
1763 bfd
*obfd
= objfile
->obfd
;
1765 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1766 locate_sections (obfd
, sec
, *names
);
1769 dwarf2_per_objfile::~dwarf2_per_objfile ()
1771 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1772 free_cached_comp_units ();
1774 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1775 per_cu
->imported_symtabs_free ();
1777 for (signatured_type
*sig_type
: all_type_units
)
1778 sig_type
->per_cu
.imported_symtabs_free ();
1780 /* Everything else should be on the objfile obstack. */
1783 /* See declaration. */
1786 dwarf2_per_objfile::free_cached_comp_units ()
1788 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1789 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1790 while (per_cu
!= NULL
)
1792 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1795 *last_chain
= next_cu
;
1800 /* A helper class that calls free_cached_comp_units on
1803 class free_cached_comp_units
1807 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1808 : m_per_objfile (per_objfile
)
1812 ~free_cached_comp_units ()
1814 m_per_objfile
->free_cached_comp_units ();
1817 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1821 dwarf2_per_objfile
*m_per_objfile
;
1824 /* Try to locate the sections we need for DWARF 2 debugging
1825 information and return true if we have enough to do something.
1826 NAMES points to the dwarf2 section names, or is NULL if the standard
1827 ELF names are used. CAN_COPY is true for formats where symbol
1828 interposition is possible and so symbol values must follow copy
1829 relocation rules. */
1832 dwarf2_has_info (struct objfile
*objfile
,
1833 const struct dwarf2_debug_sections
*names
,
1836 if (objfile
->flags
& OBJF_READNEVER
)
1839 struct dwarf2_per_objfile
*dwarf2_per_objfile
1840 = get_dwarf2_per_objfile (objfile
);
1842 if (dwarf2_per_objfile
== NULL
)
1843 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1847 return (!dwarf2_per_objfile
->info
.is_virtual
1848 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1849 && !dwarf2_per_objfile
->abbrev
.is_virtual
1850 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1853 /* When loading sections, we look either for uncompressed section or for
1854 compressed section names. */
1857 section_is_p (const char *section_name
,
1858 const struct dwarf2_section_names
*names
)
1860 if (names
->normal
!= NULL
1861 && strcmp (section_name
, names
->normal
) == 0)
1863 if (names
->compressed
!= NULL
1864 && strcmp (section_name
, names
->compressed
) == 0)
1869 /* See declaration. */
1872 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1873 const dwarf2_debug_sections
&names
)
1875 flagword aflag
= bfd_section_flags (sectp
);
1877 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1880 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1881 > bfd_get_file_size (abfd
))
1883 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1884 warning (_("Discarding section %s which has a section size (%s"
1885 ") larger than the file size [in module %s]"),
1886 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1887 bfd_get_filename (abfd
));
1889 else if (section_is_p (sectp
->name
, &names
.info
))
1891 this->info
.s
.section
= sectp
;
1892 this->info
.size
= bfd_section_size (sectp
);
1894 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1896 this->abbrev
.s
.section
= sectp
;
1897 this->abbrev
.size
= bfd_section_size (sectp
);
1899 else if (section_is_p (sectp
->name
, &names
.line
))
1901 this->line
.s
.section
= sectp
;
1902 this->line
.size
= bfd_section_size (sectp
);
1904 else if (section_is_p (sectp
->name
, &names
.loc
))
1906 this->loc
.s
.section
= sectp
;
1907 this->loc
.size
= bfd_section_size (sectp
);
1909 else if (section_is_p (sectp
->name
, &names
.loclists
))
1911 this->loclists
.s
.section
= sectp
;
1912 this->loclists
.size
= bfd_section_size (sectp
);
1914 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1916 this->macinfo
.s
.section
= sectp
;
1917 this->macinfo
.size
= bfd_section_size (sectp
);
1919 else if (section_is_p (sectp
->name
, &names
.macro
))
1921 this->macro
.s
.section
= sectp
;
1922 this->macro
.size
= bfd_section_size (sectp
);
1924 else if (section_is_p (sectp
->name
, &names
.str
))
1926 this->str
.s
.section
= sectp
;
1927 this->str
.size
= bfd_section_size (sectp
);
1929 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1931 this->str_offsets
.s
.section
= sectp
;
1932 this->str_offsets
.size
= bfd_section_size (sectp
);
1934 else if (section_is_p (sectp
->name
, &names
.line_str
))
1936 this->line_str
.s
.section
= sectp
;
1937 this->line_str
.size
= bfd_section_size (sectp
);
1939 else if (section_is_p (sectp
->name
, &names
.addr
))
1941 this->addr
.s
.section
= sectp
;
1942 this->addr
.size
= bfd_section_size (sectp
);
1944 else if (section_is_p (sectp
->name
, &names
.frame
))
1946 this->frame
.s
.section
= sectp
;
1947 this->frame
.size
= bfd_section_size (sectp
);
1949 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1951 this->eh_frame
.s
.section
= sectp
;
1952 this->eh_frame
.size
= bfd_section_size (sectp
);
1954 else if (section_is_p (sectp
->name
, &names
.ranges
))
1956 this->ranges
.s
.section
= sectp
;
1957 this->ranges
.size
= bfd_section_size (sectp
);
1959 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1961 this->rnglists
.s
.section
= sectp
;
1962 this->rnglists
.size
= bfd_section_size (sectp
);
1964 else if (section_is_p (sectp
->name
, &names
.types
))
1966 struct dwarf2_section_info type_section
;
1968 memset (&type_section
, 0, sizeof (type_section
));
1969 type_section
.s
.section
= sectp
;
1970 type_section
.size
= bfd_section_size (sectp
);
1972 this->types
.push_back (type_section
);
1974 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1976 this->gdb_index
.s
.section
= sectp
;
1977 this->gdb_index
.size
= bfd_section_size (sectp
);
1979 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1981 this->debug_names
.s
.section
= sectp
;
1982 this->debug_names
.size
= bfd_section_size (sectp
);
1984 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1986 this->debug_aranges
.s
.section
= sectp
;
1987 this->debug_aranges
.size
= bfd_section_size (sectp
);
1990 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1991 && bfd_section_vma (sectp
) == 0)
1992 this->has_section_at_zero
= true;
1995 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1999 dwarf2_get_section_info (struct objfile
*objfile
,
2000 enum dwarf2_section_enum sect
,
2001 asection
**sectp
, const gdb_byte
**bufp
,
2002 bfd_size_type
*sizep
)
2004 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2005 struct dwarf2_section_info
*info
;
2007 /* We may see an objfile without any DWARF, in which case we just
2018 case DWARF2_DEBUG_FRAME
:
2019 info
= &data
->frame
;
2021 case DWARF2_EH_FRAME
:
2022 info
= &data
->eh_frame
;
2025 gdb_assert_not_reached ("unexpected section");
2028 info
->read (objfile
);
2030 *sectp
= info
->get_bfd_section ();
2031 *bufp
= info
->buffer
;
2032 *sizep
= info
->size
;
2035 /* A helper function to find the sections for a .dwz file. */
2038 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2040 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2042 /* Note that we only support the standard ELF names, because .dwz
2043 is ELF-only (at the time of writing). */
2044 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2046 dwz_file
->abbrev
.s
.section
= sectp
;
2047 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2049 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2051 dwz_file
->info
.s
.section
= sectp
;
2052 dwz_file
->info
.size
= bfd_section_size (sectp
);
2054 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2056 dwz_file
->str
.s
.section
= sectp
;
2057 dwz_file
->str
.size
= bfd_section_size (sectp
);
2059 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2061 dwz_file
->line
.s
.section
= sectp
;
2062 dwz_file
->line
.size
= bfd_section_size (sectp
);
2064 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2066 dwz_file
->macro
.s
.section
= sectp
;
2067 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2069 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2071 dwz_file
->gdb_index
.s
.section
= sectp
;
2072 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2074 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2076 dwz_file
->debug_names
.s
.section
= sectp
;
2077 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2081 /* See dwarf2read.h. */
2084 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2086 const char *filename
;
2087 bfd_size_type buildid_len_arg
;
2091 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2092 return dwarf2_per_objfile
->dwz_file
.get ();
2094 bfd_set_error (bfd_error_no_error
);
2095 gdb::unique_xmalloc_ptr
<char> data
2096 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2097 &buildid_len_arg
, &buildid
));
2100 if (bfd_get_error () == bfd_error_no_error
)
2102 error (_("could not read '.gnu_debugaltlink' section: %s"),
2103 bfd_errmsg (bfd_get_error ()));
2106 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2108 buildid_len
= (size_t) buildid_len_arg
;
2110 filename
= data
.get ();
2112 std::string abs_storage
;
2113 if (!IS_ABSOLUTE_PATH (filename
))
2115 gdb::unique_xmalloc_ptr
<char> abs
2116 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2118 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2119 filename
= abs_storage
.c_str ();
2122 /* First try the file name given in the section. If that doesn't
2123 work, try to use the build-id instead. */
2124 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2125 if (dwz_bfd
!= NULL
)
2127 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2128 dwz_bfd
.reset (nullptr);
2131 if (dwz_bfd
== NULL
)
2132 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2134 if (dwz_bfd
== nullptr)
2136 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2137 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2139 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2146 /* File successfully retrieved from server. */
2147 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2149 if (dwz_bfd
== nullptr)
2150 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2151 alt_filename
.get ());
2152 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2153 dwz_bfd
.reset (nullptr);
2157 if (dwz_bfd
== NULL
)
2158 error (_("could not find '.gnu_debugaltlink' file for %s"),
2159 objfile_name (dwarf2_per_objfile
->objfile
));
2161 std::unique_ptr
<struct dwz_file
> result
2162 (new struct dwz_file (std::move (dwz_bfd
)));
2164 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2167 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2168 result
->dwz_bfd
.get ());
2169 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2170 return dwarf2_per_objfile
->dwz_file
.get ();
2173 /* DWARF quick_symbols_functions support. */
2175 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2176 unique line tables, so we maintain a separate table of all .debug_line
2177 derived entries to support the sharing.
2178 All the quick functions need is the list of file names. We discard the
2179 line_header when we're done and don't need to record it here. */
2180 struct quick_file_names
2182 /* The data used to construct the hash key. */
2183 struct stmt_list_hash hash
;
2185 /* The number of entries in file_names, real_names. */
2186 unsigned int num_file_names
;
2188 /* The file names from the line table, after being run through
2190 const char **file_names
;
2192 /* The file names from the line table after being run through
2193 gdb_realpath. These are computed lazily. */
2194 const char **real_names
;
2197 /* When using the index (and thus not using psymtabs), each CU has an
2198 object of this type. This is used to hold information needed by
2199 the various "quick" methods. */
2200 struct dwarf2_per_cu_quick_data
2202 /* The file table. This can be NULL if there was no file table
2203 or it's currently not read in.
2204 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2205 struct quick_file_names
*file_names
;
2207 /* The corresponding symbol table. This is NULL if symbols for this
2208 CU have not yet been read. */
2209 struct compunit_symtab
*compunit_symtab
;
2211 /* A temporary mark bit used when iterating over all CUs in
2212 expand_symtabs_matching. */
2213 unsigned int mark
: 1;
2215 /* True if we've tried to read the file table and found there isn't one.
2216 There will be no point in trying to read it again next time. */
2217 unsigned int no_file_data
: 1;
2220 /* Utility hash function for a stmt_list_hash. */
2223 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2227 if (stmt_list_hash
->dwo_unit
!= NULL
)
2228 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2229 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2233 /* Utility equality function for a stmt_list_hash. */
2236 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2237 const struct stmt_list_hash
*rhs
)
2239 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2241 if (lhs
->dwo_unit
!= NULL
2242 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2245 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2248 /* Hash function for a quick_file_names. */
2251 hash_file_name_entry (const void *e
)
2253 const struct quick_file_names
*file_data
2254 = (const struct quick_file_names
*) e
;
2256 return hash_stmt_list_entry (&file_data
->hash
);
2259 /* Equality function for a quick_file_names. */
2262 eq_file_name_entry (const void *a
, const void *b
)
2264 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2265 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2267 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2270 /* Delete function for a quick_file_names. */
2273 delete_file_name_entry (void *e
)
2275 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2278 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2280 xfree ((void*) file_data
->file_names
[i
]);
2281 if (file_data
->real_names
)
2282 xfree ((void*) file_data
->real_names
[i
]);
2285 /* The space for the struct itself lives on objfile_obstack,
2286 so we don't free it here. */
2289 /* Create a quick_file_names hash table. */
2292 create_quick_file_names_table (unsigned int nr_initial_entries
)
2294 return htab_up (htab_create_alloc (nr_initial_entries
,
2295 hash_file_name_entry
, eq_file_name_entry
,
2296 delete_file_name_entry
, xcalloc
, xfree
));
2299 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2300 have to be created afterwards. You should call age_cached_comp_units after
2301 processing PER_CU->CU. dw2_setup must have been already called. */
2304 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2306 if (per_cu
->is_debug_types
)
2307 load_full_type_unit (per_cu
);
2309 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2311 if (per_cu
->cu
== NULL
)
2312 return; /* Dummy CU. */
2314 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2317 /* Read in the symbols for PER_CU. */
2320 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2322 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2324 /* Skip type_unit_groups, reading the type units they contain
2325 is handled elsewhere. */
2326 if (per_cu
->type_unit_group_p ())
2329 /* The destructor of dwarf2_queue_guard frees any entries left on
2330 the queue. After this point we're guaranteed to leave this function
2331 with the dwarf queue empty. */
2332 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2334 if (dwarf2_per_objfile
->using_index
2335 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2336 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2338 queue_comp_unit (per_cu
, language_minimal
);
2339 load_cu (per_cu
, skip_partial
);
2341 /* If we just loaded a CU from a DWO, and we're working with an index
2342 that may badly handle TUs, load all the TUs in that DWO as well.
2343 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2344 if (!per_cu
->is_debug_types
2345 && per_cu
->cu
!= NULL
2346 && per_cu
->cu
->dwo_unit
!= NULL
2347 && dwarf2_per_objfile
->index_table
!= NULL
2348 && dwarf2_per_objfile
->index_table
->version
<= 7
2349 /* DWP files aren't supported yet. */
2350 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2351 queue_and_load_all_dwo_tus (per_cu
);
2354 process_queue (dwarf2_per_objfile
);
2356 /* Age the cache, releasing compilation units that have not
2357 been used recently. */
2358 age_cached_comp_units (dwarf2_per_objfile
);
2361 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2362 the objfile from which this CU came. Returns the resulting symbol
2365 static struct compunit_symtab
*
2366 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2368 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2370 gdb_assert (dwarf2_per_objfile
->using_index
);
2371 if (!per_cu
->v
.quick
->compunit_symtab
)
2373 free_cached_comp_units
freer (dwarf2_per_objfile
);
2374 scoped_restore decrementer
= increment_reading_symtab ();
2375 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2376 process_cu_includes (dwarf2_per_objfile
);
2379 return per_cu
->v
.quick
->compunit_symtab
;
2382 /* See declaration. */
2384 dwarf2_per_cu_data
*
2385 dwarf2_per_objfile::get_cutu (int index
)
2387 if (index
>= this->all_comp_units
.size ())
2389 index
-= this->all_comp_units
.size ();
2390 gdb_assert (index
< this->all_type_units
.size ());
2391 return &this->all_type_units
[index
]->per_cu
;
2394 return this->all_comp_units
[index
];
2397 /* See declaration. */
2399 dwarf2_per_cu_data
*
2400 dwarf2_per_objfile::get_cu (int index
)
2402 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2404 return this->all_comp_units
[index
];
2407 /* See declaration. */
2410 dwarf2_per_objfile::get_tu (int index
)
2412 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2414 return this->all_type_units
[index
];
2417 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2418 objfile_obstack, and constructed with the specified field
2421 static dwarf2_per_cu_data
*
2422 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2423 struct dwarf2_section_info
*section
,
2425 sect_offset sect_off
, ULONGEST length
)
2427 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2428 dwarf2_per_cu_data
*the_cu
2429 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2430 struct dwarf2_per_cu_data
);
2431 the_cu
->sect_off
= sect_off
;
2432 the_cu
->length
= length
;
2433 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2434 the_cu
->section
= section
;
2435 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2436 struct dwarf2_per_cu_quick_data
);
2437 the_cu
->is_dwz
= is_dwz
;
2441 /* A helper for create_cus_from_index that handles a given list of
2445 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2446 const gdb_byte
*cu_list
, offset_type n_elements
,
2447 struct dwarf2_section_info
*section
,
2450 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2452 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2454 sect_offset sect_off
2455 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2456 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2459 dwarf2_per_cu_data
*per_cu
2460 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2462 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2466 /* Read the CU list from the mapped index, and use it to create all
2467 the CU objects for this objfile. */
2470 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2471 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2472 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2474 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2475 dwarf2_per_objfile
->all_comp_units
.reserve
2476 ((cu_list_elements
+ dwz_elements
) / 2);
2478 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2479 &dwarf2_per_objfile
->info
, 0);
2481 if (dwz_elements
== 0)
2484 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2485 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2489 /* Create the signatured type hash table from the index. */
2492 create_signatured_type_table_from_index
2493 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2494 struct dwarf2_section_info
*section
,
2495 const gdb_byte
*bytes
,
2496 offset_type elements
)
2498 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2500 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2501 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2503 htab_up sig_types_hash
= allocate_signatured_type_table ();
2505 for (offset_type i
= 0; i
< elements
; i
+= 3)
2507 struct signatured_type
*sig_type
;
2510 cu_offset type_offset_in_tu
;
2512 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2513 sect_offset sect_off
2514 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2516 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2518 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2521 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2522 struct signatured_type
);
2523 sig_type
->signature
= signature
;
2524 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2525 sig_type
->per_cu
.is_debug_types
= 1;
2526 sig_type
->per_cu
.section
= section
;
2527 sig_type
->per_cu
.sect_off
= sect_off
;
2528 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2529 sig_type
->per_cu
.v
.quick
2530 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2531 struct dwarf2_per_cu_quick_data
);
2533 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2536 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2539 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2542 /* Create the signatured type hash table from .debug_names. */
2545 create_signatured_type_table_from_debug_names
2546 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2547 const mapped_debug_names
&map
,
2548 struct dwarf2_section_info
*section
,
2549 struct dwarf2_section_info
*abbrev_section
)
2551 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2553 section
->read (objfile
);
2554 abbrev_section
->read (objfile
);
2556 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2557 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2559 htab_up sig_types_hash
= allocate_signatured_type_table ();
2561 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2563 struct signatured_type
*sig_type
;
2566 sect_offset sect_off
2567 = (sect_offset
) (extract_unsigned_integer
2568 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2570 map
.dwarf5_byte_order
));
2572 comp_unit_head cu_header
;
2573 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2575 section
->buffer
+ to_underlying (sect_off
),
2578 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2579 struct signatured_type
);
2580 sig_type
->signature
= cu_header
.signature
;
2581 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2582 sig_type
->per_cu
.is_debug_types
= 1;
2583 sig_type
->per_cu
.section
= section
;
2584 sig_type
->per_cu
.sect_off
= sect_off
;
2585 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2586 sig_type
->per_cu
.v
.quick
2587 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2588 struct dwarf2_per_cu_quick_data
);
2590 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2593 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2596 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2599 /* Read the address map data from the mapped index, and use it to
2600 populate the objfile's psymtabs_addrmap. */
2603 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2604 struct mapped_index
*index
)
2606 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2607 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2608 const gdb_byte
*iter
, *end
;
2609 struct addrmap
*mutable_map
;
2612 auto_obstack temp_obstack
;
2614 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2616 iter
= index
->address_table
.data ();
2617 end
= iter
+ index
->address_table
.size ();
2619 baseaddr
= objfile
->text_section_offset ();
2623 ULONGEST hi
, lo
, cu_index
;
2624 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2626 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2628 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2633 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2634 hex_string (lo
), hex_string (hi
));
2638 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2640 complaint (_(".gdb_index address table has invalid CU number %u"),
2641 (unsigned) cu_index
);
2645 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2646 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2647 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2648 dwarf2_per_objfile
->get_cu (cu_index
));
2651 objfile
->partial_symtabs
->psymtabs_addrmap
2652 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2655 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2656 populate the objfile's psymtabs_addrmap. */
2659 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2660 struct dwarf2_section_info
*section
)
2662 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2663 bfd
*abfd
= objfile
->obfd
;
2664 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2665 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2667 auto_obstack temp_obstack
;
2668 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2670 std::unordered_map
<sect_offset
,
2671 dwarf2_per_cu_data
*,
2672 gdb::hash_enum
<sect_offset
>>
2673 debug_info_offset_to_per_cu
;
2674 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2676 const auto insertpair
2677 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2678 if (!insertpair
.second
)
2680 warning (_("Section .debug_aranges in %s has duplicate "
2681 "debug_info_offset %s, ignoring .debug_aranges."),
2682 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2687 section
->read (objfile
);
2689 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2691 const gdb_byte
*addr
= section
->buffer
;
2693 while (addr
< section
->buffer
+ section
->size
)
2695 const gdb_byte
*const entry_addr
= addr
;
2696 unsigned int bytes_read
;
2698 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2702 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2703 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2704 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2705 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2707 warning (_("Section .debug_aranges in %s entry at offset %s "
2708 "length %s exceeds section length %s, "
2709 "ignoring .debug_aranges."),
2710 objfile_name (objfile
),
2711 plongest (entry_addr
- section
->buffer
),
2712 plongest (bytes_read
+ entry_length
),
2713 pulongest (section
->size
));
2717 /* The version number. */
2718 const uint16_t version
= read_2_bytes (abfd
, addr
);
2722 warning (_("Section .debug_aranges in %s entry at offset %s "
2723 "has unsupported version %d, ignoring .debug_aranges."),
2724 objfile_name (objfile
),
2725 plongest (entry_addr
- section
->buffer
), version
);
2729 const uint64_t debug_info_offset
2730 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2731 addr
+= offset_size
;
2732 const auto per_cu_it
2733 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2734 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2736 warning (_("Section .debug_aranges in %s entry at offset %s "
2737 "debug_info_offset %s does not exists, "
2738 "ignoring .debug_aranges."),
2739 objfile_name (objfile
),
2740 plongest (entry_addr
- section
->buffer
),
2741 pulongest (debug_info_offset
));
2744 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2746 const uint8_t address_size
= *addr
++;
2747 if (address_size
< 1 || address_size
> 8)
2749 warning (_("Section .debug_aranges in %s entry at offset %s "
2750 "address_size %u is invalid, ignoring .debug_aranges."),
2751 objfile_name (objfile
),
2752 plongest (entry_addr
- section
->buffer
), address_size
);
2756 const uint8_t segment_selector_size
= *addr
++;
2757 if (segment_selector_size
!= 0)
2759 warning (_("Section .debug_aranges in %s entry at offset %s "
2760 "segment_selector_size %u is not supported, "
2761 "ignoring .debug_aranges."),
2762 objfile_name (objfile
),
2763 plongest (entry_addr
- section
->buffer
),
2764 segment_selector_size
);
2768 /* Must pad to an alignment boundary that is twice the address
2769 size. It is undocumented by the DWARF standard but GCC does
2771 for (size_t padding
= ((-(addr
- section
->buffer
))
2772 & (2 * address_size
- 1));
2773 padding
> 0; padding
--)
2776 warning (_("Section .debug_aranges in %s entry at offset %s "
2777 "padding is not zero, ignoring .debug_aranges."),
2778 objfile_name (objfile
),
2779 plongest (entry_addr
- section
->buffer
));
2785 if (addr
+ 2 * address_size
> entry_end
)
2787 warning (_("Section .debug_aranges in %s entry at offset %s "
2788 "address list is not properly terminated, "
2789 "ignoring .debug_aranges."),
2790 objfile_name (objfile
),
2791 plongest (entry_addr
- section
->buffer
));
2794 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2796 addr
+= address_size
;
2797 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2799 addr
+= address_size
;
2800 if (start
== 0 && length
== 0)
2802 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2804 /* Symbol was eliminated due to a COMDAT group. */
2807 ULONGEST end
= start
+ length
;
2808 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2810 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2812 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2816 objfile
->partial_symtabs
->psymtabs_addrmap
2817 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2820 /* Find a slot in the mapped index INDEX for the object named NAME.
2821 If NAME is found, set *VEC_OUT to point to the CU vector in the
2822 constant pool and return true. If NAME cannot be found, return
2826 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2827 offset_type
**vec_out
)
2830 offset_type slot
, step
;
2831 int (*cmp
) (const char *, const char *);
2833 gdb::unique_xmalloc_ptr
<char> without_params
;
2834 if (current_language
->la_language
== language_cplus
2835 || current_language
->la_language
== language_fortran
2836 || current_language
->la_language
== language_d
)
2838 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2841 if (strchr (name
, '(') != NULL
)
2843 without_params
= cp_remove_params (name
);
2845 if (without_params
!= NULL
)
2846 name
= without_params
.get ();
2850 /* Index version 4 did not support case insensitive searches. But the
2851 indices for case insensitive languages are built in lowercase, therefore
2852 simulate our NAME being searched is also lowercased. */
2853 hash
= mapped_index_string_hash ((index
->version
== 4
2854 && case_sensitivity
== case_sensitive_off
2855 ? 5 : index
->version
),
2858 slot
= hash
& (index
->symbol_table
.size () - 1);
2859 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2860 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2866 const auto &bucket
= index
->symbol_table
[slot
];
2867 if (bucket
.name
== 0 && bucket
.vec
== 0)
2870 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2871 if (!cmp (name
, str
))
2873 *vec_out
= (offset_type
*) (index
->constant_pool
2874 + MAYBE_SWAP (bucket
.vec
));
2878 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2882 /* A helper function that reads the .gdb_index from BUFFER and fills
2883 in MAP. FILENAME is the name of the file containing the data;
2884 it is used for error reporting. DEPRECATED_OK is true if it is
2885 ok to use deprecated sections.
2887 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2888 out parameters that are filled in with information about the CU and
2889 TU lists in the section.
2891 Returns true if all went well, false otherwise. */
2894 read_gdb_index_from_buffer (struct objfile
*objfile
,
2895 const char *filename
,
2897 gdb::array_view
<const gdb_byte
> buffer
,
2898 struct mapped_index
*map
,
2899 const gdb_byte
**cu_list
,
2900 offset_type
*cu_list_elements
,
2901 const gdb_byte
**types_list
,
2902 offset_type
*types_list_elements
)
2904 const gdb_byte
*addr
= &buffer
[0];
2906 /* Version check. */
2907 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2908 /* Versions earlier than 3 emitted every copy of a psymbol. This
2909 causes the index to behave very poorly for certain requests. Version 3
2910 contained incomplete addrmap. So, it seems better to just ignore such
2914 static int warning_printed
= 0;
2915 if (!warning_printed
)
2917 warning (_("Skipping obsolete .gdb_index section in %s."),
2919 warning_printed
= 1;
2923 /* Index version 4 uses a different hash function than index version
2926 Versions earlier than 6 did not emit psymbols for inlined
2927 functions. Using these files will cause GDB not to be able to
2928 set breakpoints on inlined functions by name, so we ignore these
2929 indices unless the user has done
2930 "set use-deprecated-index-sections on". */
2931 if (version
< 6 && !deprecated_ok
)
2933 static int warning_printed
= 0;
2934 if (!warning_printed
)
2937 Skipping deprecated .gdb_index section in %s.\n\
2938 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2939 to use the section anyway."),
2941 warning_printed
= 1;
2945 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2946 of the TU (for symbols coming from TUs),
2947 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2948 Plus gold-generated indices can have duplicate entries for global symbols,
2949 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2950 These are just performance bugs, and we can't distinguish gdb-generated
2951 indices from gold-generated ones, so issue no warning here. */
2953 /* Indexes with higher version than the one supported by GDB may be no
2954 longer backward compatible. */
2958 map
->version
= version
;
2960 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2963 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2964 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2968 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2969 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2970 - MAYBE_SWAP (metadata
[i
]))
2974 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2975 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2977 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2980 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2981 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2983 = gdb::array_view
<mapped_index::symbol_table_slot
>
2984 ((mapped_index::symbol_table_slot
*) symbol_table
,
2985 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2988 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2993 /* Callback types for dwarf2_read_gdb_index. */
2995 typedef gdb::function_view
2996 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2997 get_gdb_index_contents_ftype
;
2998 typedef gdb::function_view
2999 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3000 get_gdb_index_contents_dwz_ftype
;
3002 /* Read .gdb_index. If everything went ok, initialize the "quick"
3003 elements of all the CUs and return 1. Otherwise, return 0. */
3006 dwarf2_read_gdb_index
3007 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3008 get_gdb_index_contents_ftype get_gdb_index_contents
,
3009 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3011 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3012 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3013 struct dwz_file
*dwz
;
3014 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3016 gdb::array_view
<const gdb_byte
> main_index_contents
3017 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3019 if (main_index_contents
.empty ())
3022 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3023 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3024 use_deprecated_index_sections
,
3025 main_index_contents
, map
.get (), &cu_list
,
3026 &cu_list_elements
, &types_list
,
3027 &types_list_elements
))
3030 /* Don't use the index if it's empty. */
3031 if (map
->symbol_table
.empty ())
3034 /* If there is a .dwz file, read it so we can get its CU list as
3036 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3039 struct mapped_index dwz_map
;
3040 const gdb_byte
*dwz_types_ignore
;
3041 offset_type dwz_types_elements_ignore
;
3043 gdb::array_view
<const gdb_byte
> dwz_index_content
3044 = get_gdb_index_contents_dwz (objfile
, dwz
);
3046 if (dwz_index_content
.empty ())
3049 if (!read_gdb_index_from_buffer (objfile
,
3050 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3051 1, dwz_index_content
, &dwz_map
,
3052 &dwz_list
, &dwz_list_elements
,
3054 &dwz_types_elements_ignore
))
3056 warning (_("could not read '.gdb_index' section from %s; skipping"),
3057 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3062 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3063 dwz_list
, dwz_list_elements
);
3065 if (types_list_elements
)
3067 /* We can only handle a single .debug_types when we have an
3069 if (dwarf2_per_objfile
->types
.size () != 1)
3072 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3074 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3075 types_list
, types_list_elements
);
3078 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3080 dwarf2_per_objfile
->index_table
= std::move (map
);
3081 dwarf2_per_objfile
->using_index
= 1;
3082 dwarf2_per_objfile
->quick_file_names_table
=
3083 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3088 /* die_reader_func for dw2_get_file_names. */
3091 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3092 const gdb_byte
*info_ptr
,
3093 struct die_info
*comp_unit_die
)
3095 struct dwarf2_cu
*cu
= reader
->cu
;
3096 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3097 struct dwarf2_per_objfile
*dwarf2_per_objfile
3098 = cu
->per_cu
->dwarf2_per_objfile
;
3099 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3100 struct dwarf2_per_cu_data
*lh_cu
;
3101 struct attribute
*attr
;
3103 struct quick_file_names
*qfn
;
3105 gdb_assert (! this_cu
->is_debug_types
);
3107 /* Our callers never want to match partial units -- instead they
3108 will match the enclosing full CU. */
3109 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3111 this_cu
->v
.quick
->no_file_data
= 1;
3119 sect_offset line_offset
{};
3121 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3122 if (attr
!= nullptr)
3124 struct quick_file_names find_entry
;
3126 line_offset
= (sect_offset
) DW_UNSND (attr
);
3128 /* We may have already read in this line header (TU line header sharing).
3129 If we have we're done. */
3130 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3131 find_entry
.hash
.line_sect_off
= line_offset
;
3132 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3133 &find_entry
, INSERT
);
3136 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3140 lh
= dwarf_decode_line_header (line_offset
, cu
);
3144 lh_cu
->v
.quick
->no_file_data
= 1;
3148 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3149 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3150 qfn
->hash
.line_sect_off
= line_offset
;
3151 gdb_assert (slot
!= NULL
);
3154 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3157 if (strcmp (fnd
.name
, "<unknown>") != 0)
3160 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3162 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3164 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3165 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3166 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3167 fnd
.comp_dir
).release ();
3168 qfn
->real_names
= NULL
;
3170 lh_cu
->v
.quick
->file_names
= qfn
;
3173 /* A helper for the "quick" functions which attempts to read the line
3174 table for THIS_CU. */
3176 static struct quick_file_names
*
3177 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3179 /* This should never be called for TUs. */
3180 gdb_assert (! this_cu
->is_debug_types
);
3181 /* Nor type unit groups. */
3182 gdb_assert (! this_cu
->type_unit_group_p ());
3184 if (this_cu
->v
.quick
->file_names
!= NULL
)
3185 return this_cu
->v
.quick
->file_names
;
3186 /* If we know there is no line data, no point in looking again. */
3187 if (this_cu
->v
.quick
->no_file_data
)
3190 cutu_reader
reader (this_cu
);
3191 if (!reader
.dummy_p
)
3192 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3194 if (this_cu
->v
.quick
->no_file_data
)
3196 return this_cu
->v
.quick
->file_names
;
3199 /* A helper for the "quick" functions which computes and caches the
3200 real path for a given file name from the line table. */
3203 dw2_get_real_path (struct objfile
*objfile
,
3204 struct quick_file_names
*qfn
, int index
)
3206 if (qfn
->real_names
== NULL
)
3207 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3208 qfn
->num_file_names
, const char *);
3210 if (qfn
->real_names
[index
] == NULL
)
3211 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3213 return qfn
->real_names
[index
];
3216 static struct symtab
*
3217 dw2_find_last_source_symtab (struct objfile
*objfile
)
3219 struct dwarf2_per_objfile
*dwarf2_per_objfile
3220 = get_dwarf2_per_objfile (objfile
);
3221 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3222 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3227 return compunit_primary_filetab (cust
);
3230 /* Traversal function for dw2_forget_cached_source_info. */
3233 dw2_free_cached_file_names (void **slot
, void *info
)
3235 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3237 if (file_data
->real_names
)
3241 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3243 xfree ((void*) file_data
->real_names
[i
]);
3244 file_data
->real_names
[i
] = NULL
;
3252 dw2_forget_cached_source_info (struct objfile
*objfile
)
3254 struct dwarf2_per_objfile
*dwarf2_per_objfile
3255 = get_dwarf2_per_objfile (objfile
);
3257 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3258 dw2_free_cached_file_names
, NULL
);
3261 /* Helper function for dw2_map_symtabs_matching_filename that expands
3262 the symtabs and calls the iterator. */
3265 dw2_map_expand_apply (struct objfile
*objfile
,
3266 struct dwarf2_per_cu_data
*per_cu
,
3267 const char *name
, const char *real_path
,
3268 gdb::function_view
<bool (symtab
*)> callback
)
3270 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3272 /* Don't visit already-expanded CUs. */
3273 if (per_cu
->v
.quick
->compunit_symtab
)
3276 /* This may expand more than one symtab, and we want to iterate over
3278 dw2_instantiate_symtab (per_cu
, false);
3280 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3281 last_made
, callback
);
3284 /* Implementation of the map_symtabs_matching_filename method. */
3287 dw2_map_symtabs_matching_filename
3288 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3289 gdb::function_view
<bool (symtab
*)> callback
)
3291 const char *name_basename
= lbasename (name
);
3292 struct dwarf2_per_objfile
*dwarf2_per_objfile
3293 = get_dwarf2_per_objfile (objfile
);
3295 /* The rule is CUs specify all the files, including those used by
3296 any TU, so there's no need to scan TUs here. */
3298 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3300 /* We only need to look at symtabs not already expanded. */
3301 if (per_cu
->v
.quick
->compunit_symtab
)
3304 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3305 if (file_data
== NULL
)
3308 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3310 const char *this_name
= file_data
->file_names
[j
];
3311 const char *this_real_name
;
3313 if (compare_filenames_for_search (this_name
, name
))
3315 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3321 /* Before we invoke realpath, which can get expensive when many
3322 files are involved, do a quick comparison of the basenames. */
3323 if (! basenames_may_differ
3324 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3327 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3328 if (compare_filenames_for_search (this_real_name
, name
))
3330 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3336 if (real_path
!= NULL
)
3338 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3339 gdb_assert (IS_ABSOLUTE_PATH (name
));
3340 if (this_real_name
!= NULL
3341 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3343 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3355 /* Struct used to manage iterating over all CUs looking for a symbol. */
3357 struct dw2_symtab_iterator
3359 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3360 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3361 /* If set, only look for symbols that match that block. Valid values are
3362 GLOBAL_BLOCK and STATIC_BLOCK. */
3363 gdb::optional
<block_enum
> block_index
;
3364 /* The kind of symbol we're looking for. */
3366 /* The list of CUs from the index entry of the symbol,
3367 or NULL if not found. */
3369 /* The next element in VEC to look at. */
3371 /* The number of elements in VEC, or zero if there is no match. */
3373 /* Have we seen a global version of the symbol?
3374 If so we can ignore all further global instances.
3375 This is to work around gold/15646, inefficient gold-generated
3380 /* Initialize the index symtab iterator ITER. */
3383 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3384 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3385 gdb::optional
<block_enum
> block_index
,
3389 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3390 iter
->block_index
= block_index
;
3391 iter
->domain
= domain
;
3393 iter
->global_seen
= 0;
3395 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3397 /* index is NULL if OBJF_READNOW. */
3398 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3399 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3407 /* Return the next matching CU or NULL if there are no more. */
3409 static struct dwarf2_per_cu_data
*
3410 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3412 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3414 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3416 offset_type cu_index_and_attrs
=
3417 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3418 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3419 gdb_index_symbol_kind symbol_kind
=
3420 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3421 /* Only check the symbol attributes if they're present.
3422 Indices prior to version 7 don't record them,
3423 and indices >= 7 may elide them for certain symbols
3424 (gold does this). */
3426 (dwarf2_per_objfile
->index_table
->version
>= 7
3427 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3429 /* Don't crash on bad data. */
3430 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3431 + dwarf2_per_objfile
->all_type_units
.size ()))
3433 complaint (_(".gdb_index entry has bad CU index"
3435 objfile_name (dwarf2_per_objfile
->objfile
));
3439 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3441 /* Skip if already read in. */
3442 if (per_cu
->v
.quick
->compunit_symtab
)
3445 /* Check static vs global. */
3448 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3450 if (iter
->block_index
.has_value ())
3452 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3454 if (is_static
!= want_static
)
3458 /* Work around gold/15646. */
3459 if (!is_static
&& iter
->global_seen
)
3462 iter
->global_seen
= 1;
3465 /* Only check the symbol's kind if it has one. */
3468 switch (iter
->domain
)
3471 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3472 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3473 /* Some types are also in VAR_DOMAIN. */
3474 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3478 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3482 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3486 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3501 static struct compunit_symtab
*
3502 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3503 const char *name
, domain_enum domain
)
3505 struct compunit_symtab
*stab_best
= NULL
;
3506 struct dwarf2_per_objfile
*dwarf2_per_objfile
3507 = get_dwarf2_per_objfile (objfile
);
3509 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3511 struct dw2_symtab_iterator iter
;
3512 struct dwarf2_per_cu_data
*per_cu
;
3514 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3516 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3518 struct symbol
*sym
, *with_opaque
= NULL
;
3519 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3520 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3521 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3523 sym
= block_find_symbol (block
, name
, domain
,
3524 block_find_non_opaque_type_preferred
,
3527 /* Some caution must be observed with overloaded functions
3528 and methods, since the index will not contain any overload
3529 information (but NAME might contain it). */
3532 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3534 if (with_opaque
!= NULL
3535 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3538 /* Keep looking through other CUs. */
3545 dw2_print_stats (struct objfile
*objfile
)
3547 struct dwarf2_per_objfile
*dwarf2_per_objfile
3548 = get_dwarf2_per_objfile (objfile
);
3549 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3550 + dwarf2_per_objfile
->all_type_units
.size ());
3553 for (int i
= 0; i
< total
; ++i
)
3555 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3557 if (!per_cu
->v
.quick
->compunit_symtab
)
3560 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3561 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3564 /* This dumps minimal information about the index.
3565 It is called via "mt print objfiles".
3566 One use is to verify .gdb_index has been loaded by the
3567 gdb.dwarf2/gdb-index.exp testcase. */
3570 dw2_dump (struct objfile
*objfile
)
3572 struct dwarf2_per_objfile
*dwarf2_per_objfile
3573 = get_dwarf2_per_objfile (objfile
);
3575 gdb_assert (dwarf2_per_objfile
->using_index
);
3576 printf_filtered (".gdb_index:");
3577 if (dwarf2_per_objfile
->index_table
!= NULL
)
3579 printf_filtered (" version %d\n",
3580 dwarf2_per_objfile
->index_table
->version
);
3583 printf_filtered (" faked for \"readnow\"\n");
3584 printf_filtered ("\n");
3588 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3589 const char *func_name
)
3591 struct dwarf2_per_objfile
*dwarf2_per_objfile
3592 = get_dwarf2_per_objfile (objfile
);
3594 struct dw2_symtab_iterator iter
;
3595 struct dwarf2_per_cu_data
*per_cu
;
3597 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3599 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3600 dw2_instantiate_symtab (per_cu
, false);
3605 dw2_expand_all_symtabs (struct objfile
*objfile
)
3607 struct dwarf2_per_objfile
*dwarf2_per_objfile
3608 = get_dwarf2_per_objfile (objfile
);
3609 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3610 + dwarf2_per_objfile
->all_type_units
.size ());
3612 for (int i
= 0; i
< total_units
; ++i
)
3614 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3616 /* We don't want to directly expand a partial CU, because if we
3617 read it with the wrong language, then assertion failures can
3618 be triggered later on. See PR symtab/23010. So, tell
3619 dw2_instantiate_symtab to skip partial CUs -- any important
3620 partial CU will be read via DW_TAG_imported_unit anyway. */
3621 dw2_instantiate_symtab (per_cu
, true);
3626 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3627 const char *fullname
)
3629 struct dwarf2_per_objfile
*dwarf2_per_objfile
3630 = get_dwarf2_per_objfile (objfile
);
3632 /* We don't need to consider type units here.
3633 This is only called for examining code, e.g. expand_line_sal.
3634 There can be an order of magnitude (or more) more type units
3635 than comp units, and we avoid them if we can. */
3637 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3639 /* We only need to look at symtabs not already expanded. */
3640 if (per_cu
->v
.quick
->compunit_symtab
)
3643 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3644 if (file_data
== NULL
)
3647 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3649 const char *this_fullname
= file_data
->file_names
[j
];
3651 if (filename_cmp (this_fullname
, fullname
) == 0)
3653 dw2_instantiate_symtab (per_cu
, false);
3661 dw2_map_matching_symbols
3662 (struct objfile
*objfile
,
3663 const lookup_name_info
&name
, domain_enum domain
,
3665 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3666 symbol_compare_ftype
*ordered_compare
)
3668 /* Currently unimplemented; used for Ada. The function can be called if the
3669 current language is Ada for a non-Ada objfile using GNU index. As Ada
3670 does not look for non-Ada symbols this function should just return. */
3673 /* Starting from a search name, return the string that finds the upper
3674 bound of all strings that start with SEARCH_NAME in a sorted name
3675 list. Returns the empty string to indicate that the upper bound is
3676 the end of the list. */
3679 make_sort_after_prefix_name (const char *search_name
)
3681 /* When looking to complete "func", we find the upper bound of all
3682 symbols that start with "func" by looking for where we'd insert
3683 the closest string that would follow "func" in lexicographical
3684 order. Usually, that's "func"-with-last-character-incremented,
3685 i.e. "fund". Mind non-ASCII characters, though. Usually those
3686 will be UTF-8 multi-byte sequences, but we can't be certain.
3687 Especially mind the 0xff character, which is a valid character in
3688 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3689 rule out compilers allowing it in identifiers. Note that
3690 conveniently, strcmp/strcasecmp are specified to compare
3691 characters interpreted as unsigned char. So what we do is treat
3692 the whole string as a base 256 number composed of a sequence of
3693 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3694 to 0, and carries 1 to the following more-significant position.
3695 If the very first character in SEARCH_NAME ends up incremented
3696 and carries/overflows, then the upper bound is the end of the
3697 list. The string after the empty string is also the empty
3700 Some examples of this operation:
3702 SEARCH_NAME => "+1" RESULT
3706 "\xff" "a" "\xff" => "\xff" "b"
3711 Then, with these symbols for example:
3717 completing "func" looks for symbols between "func" and
3718 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3719 which finds "func" and "func1", but not "fund".
3723 funcÿ (Latin1 'ÿ' [0xff])
3727 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3728 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3732 ÿÿ (Latin1 'ÿ' [0xff])
3735 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3736 the end of the list.
3738 std::string after
= search_name
;
3739 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3741 if (!after
.empty ())
3742 after
.back () = (unsigned char) after
.back () + 1;
3746 /* See declaration. */
3748 std::pair
<std::vector
<name_component
>::const_iterator
,
3749 std::vector
<name_component
>::const_iterator
>
3750 mapped_index_base::find_name_components_bounds
3751 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3754 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3756 const char *lang_name
3757 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3759 /* Comparison function object for lower_bound that matches against a
3760 given symbol name. */
3761 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3764 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3765 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3766 return name_cmp (elem_name
, name
) < 0;
3769 /* Comparison function object for upper_bound that matches against a
3770 given symbol name. */
3771 auto lookup_compare_upper
= [&] (const char *name
,
3772 const name_component
&elem
)
3774 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3775 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3776 return name_cmp (name
, elem_name
) < 0;
3779 auto begin
= this->name_components
.begin ();
3780 auto end
= this->name_components
.end ();
3782 /* Find the lower bound. */
3785 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3788 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3791 /* Find the upper bound. */
3794 if (lookup_name_without_params
.completion_mode ())
3796 /* In completion mode, we want UPPER to point past all
3797 symbols names that have the same prefix. I.e., with
3798 these symbols, and completing "func":
3800 function << lower bound
3802 other_function << upper bound
3804 We find the upper bound by looking for the insertion
3805 point of "func"-with-last-character-incremented,
3807 std::string after
= make_sort_after_prefix_name (lang_name
);
3810 return std::lower_bound (lower
, end
, after
.c_str (),
3811 lookup_compare_lower
);
3814 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3817 return {lower
, upper
};
3820 /* See declaration. */
3823 mapped_index_base::build_name_components ()
3825 if (!this->name_components
.empty ())
3828 this->name_components_casing
= case_sensitivity
;
3830 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3832 /* The code below only knows how to break apart components of C++
3833 symbol names (and other languages that use '::' as
3834 namespace/module separator) and Ada symbol names. */
3835 auto count
= this->symbol_name_count ();
3836 for (offset_type idx
= 0; idx
< count
; idx
++)
3838 if (this->symbol_name_slot_invalid (idx
))
3841 const char *name
= this->symbol_name_at (idx
);
3843 /* Add each name component to the name component table. */
3844 unsigned int previous_len
= 0;
3846 if (strstr (name
, "::") != nullptr)
3848 for (unsigned int current_len
= cp_find_first_component (name
);
3849 name
[current_len
] != '\0';
3850 current_len
+= cp_find_first_component (name
+ current_len
))
3852 gdb_assert (name
[current_len
] == ':');
3853 this->name_components
.push_back ({previous_len
, idx
});
3854 /* Skip the '::'. */
3856 previous_len
= current_len
;
3861 /* Handle the Ada encoded (aka mangled) form here. */
3862 for (const char *iter
= strstr (name
, "__");
3864 iter
= strstr (iter
, "__"))
3866 this->name_components
.push_back ({previous_len
, idx
});
3868 previous_len
= iter
- name
;
3872 this->name_components
.push_back ({previous_len
, idx
});
3875 /* Sort name_components elements by name. */
3876 auto name_comp_compare
= [&] (const name_component
&left
,
3877 const name_component
&right
)
3879 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3880 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3882 const char *left_name
= left_qualified
+ left
.name_offset
;
3883 const char *right_name
= right_qualified
+ right
.name_offset
;
3885 return name_cmp (left_name
, right_name
) < 0;
3888 std::sort (this->name_components
.begin (),
3889 this->name_components
.end (),
3893 /* Helper for dw2_expand_symtabs_matching that works with a
3894 mapped_index_base instead of the containing objfile. This is split
3895 to a separate function in order to be able to unit test the
3896 name_components matching using a mock mapped_index_base. For each
3897 symbol name that matches, calls MATCH_CALLBACK, passing it the
3898 symbol's index in the mapped_index_base symbol table. */
3901 dw2_expand_symtabs_matching_symbol
3902 (mapped_index_base
&index
,
3903 const lookup_name_info
&lookup_name_in
,
3904 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3905 enum search_domain kind
,
3906 gdb::function_view
<bool (offset_type
)> match_callback
)
3908 lookup_name_info lookup_name_without_params
3909 = lookup_name_in
.make_ignore_params ();
3911 /* Build the symbol name component sorted vector, if we haven't
3913 index
.build_name_components ();
3915 /* The same symbol may appear more than once in the range though.
3916 E.g., if we're looking for symbols that complete "w", and we have
3917 a symbol named "w1::w2", we'll find the two name components for
3918 that same symbol in the range. To be sure we only call the
3919 callback once per symbol, we first collect the symbol name
3920 indexes that matched in a temporary vector and ignore
3922 std::vector
<offset_type
> matches
;
3924 struct name_and_matcher
3926 symbol_name_matcher_ftype
*matcher
;
3927 const std::string
&name
;
3929 bool operator== (const name_and_matcher
&other
) const
3931 return matcher
== other
.matcher
&& name
== other
.name
;
3935 /* A vector holding all the different symbol name matchers, for all
3937 std::vector
<name_and_matcher
> matchers
;
3939 for (int i
= 0; i
< nr_languages
; i
++)
3941 enum language lang_e
= (enum language
) i
;
3943 const language_defn
*lang
= language_def (lang_e
);
3944 symbol_name_matcher_ftype
*name_matcher
3945 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3947 name_and_matcher key
{
3949 lookup_name_without_params
.language_lookup_name (lang_e
)
3952 /* Don't insert the same comparison routine more than once.
3953 Note that we do this linear walk. This is not a problem in
3954 practice because the number of supported languages is
3956 if (std::find (matchers
.begin (), matchers
.end (), key
)
3959 matchers
.push_back (std::move (key
));
3962 = index
.find_name_components_bounds (lookup_name_without_params
,
3965 /* Now for each symbol name in range, check to see if we have a name
3966 match, and if so, call the MATCH_CALLBACK callback. */
3968 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3970 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3972 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3973 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3976 matches
.push_back (bounds
.first
->idx
);
3980 std::sort (matches
.begin (), matches
.end ());
3982 /* Finally call the callback, once per match. */
3984 for (offset_type idx
: matches
)
3988 if (!match_callback (idx
))
3994 /* Above we use a type wider than idx's for 'prev', since 0 and
3995 (offset_type)-1 are both possible values. */
3996 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4001 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4003 /* A mock .gdb_index/.debug_names-like name index table, enough to
4004 exercise dw2_expand_symtabs_matching_symbol, which works with the
4005 mapped_index_base interface. Builds an index from the symbol list
4006 passed as parameter to the constructor. */
4007 class mock_mapped_index
: public mapped_index_base
4010 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4011 : m_symbol_table (symbols
)
4014 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4016 /* Return the number of names in the symbol table. */
4017 size_t symbol_name_count () const override
4019 return m_symbol_table
.size ();
4022 /* Get the name of the symbol at IDX in the symbol table. */
4023 const char *symbol_name_at (offset_type idx
) const override
4025 return m_symbol_table
[idx
];
4029 gdb::array_view
<const char *> m_symbol_table
;
4032 /* Convenience function that converts a NULL pointer to a "<null>"
4033 string, to pass to print routines. */
4036 string_or_null (const char *str
)
4038 return str
!= NULL
? str
: "<null>";
4041 /* Check if a lookup_name_info built from
4042 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4043 index. EXPECTED_LIST is the list of expected matches, in expected
4044 matching order. If no match expected, then an empty list is
4045 specified. Returns true on success. On failure prints a warning
4046 indicating the file:line that failed, and returns false. */
4049 check_match (const char *file
, int line
,
4050 mock_mapped_index
&mock_index
,
4051 const char *name
, symbol_name_match_type match_type
,
4052 bool completion_mode
,
4053 std::initializer_list
<const char *> expected_list
)
4055 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4057 bool matched
= true;
4059 auto mismatch
= [&] (const char *expected_str
,
4062 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4063 "expected=\"%s\", got=\"%s\"\n"),
4065 (match_type
== symbol_name_match_type::FULL
4067 name
, string_or_null (expected_str
), string_or_null (got
));
4071 auto expected_it
= expected_list
.begin ();
4072 auto expected_end
= expected_list
.end ();
4074 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4076 [&] (offset_type idx
)
4078 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4079 const char *expected_str
4080 = expected_it
== expected_end
? NULL
: *expected_it
++;
4082 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4083 mismatch (expected_str
, matched_name
);
4087 const char *expected_str
4088 = expected_it
== expected_end
? NULL
: *expected_it
++;
4089 if (expected_str
!= NULL
)
4090 mismatch (expected_str
, NULL
);
4095 /* The symbols added to the mock mapped_index for testing (in
4097 static const char *test_symbols
[] = {
4106 "ns2::tmpl<int>::foo2",
4107 "(anonymous namespace)::A::B::C",
4109 /* These are used to check that the increment-last-char in the
4110 matching algorithm for completion doesn't match "t1_fund" when
4111 completing "t1_func". */
4117 /* A UTF-8 name with multi-byte sequences to make sure that
4118 cp-name-parser understands this as a single identifier ("função"
4119 is "function" in PT). */
4122 /* \377 (0xff) is Latin1 'ÿ'. */
4125 /* \377 (0xff) is Latin1 'ÿ'. */
4129 /* A name with all sorts of complications. Starts with "z" to make
4130 it easier for the completion tests below. */
4131 #define Z_SYM_NAME \
4132 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4133 "::tuple<(anonymous namespace)::ui*, " \
4134 "std::default_delete<(anonymous namespace)::ui>, void>"
4139 /* Returns true if the mapped_index_base::find_name_component_bounds
4140 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4141 in completion mode. */
4144 check_find_bounds_finds (mapped_index_base
&index
,
4145 const char *search_name
,
4146 gdb::array_view
<const char *> expected_syms
)
4148 lookup_name_info
lookup_name (search_name
,
4149 symbol_name_match_type::FULL
, true);
4151 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4154 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4155 if (distance
!= expected_syms
.size ())
4158 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4160 auto nc_elem
= bounds
.first
+ exp_elem
;
4161 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4162 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4169 /* Test the lower-level mapped_index::find_name_component_bounds
4173 test_mapped_index_find_name_component_bounds ()
4175 mock_mapped_index
mock_index (test_symbols
);
4177 mock_index
.build_name_components ();
4179 /* Test the lower-level mapped_index::find_name_component_bounds
4180 method in completion mode. */
4182 static const char *expected_syms
[] = {
4187 SELF_CHECK (check_find_bounds_finds (mock_index
,
4188 "t1_func", expected_syms
));
4191 /* Check that the increment-last-char in the name matching algorithm
4192 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4194 static const char *expected_syms1
[] = {
4198 SELF_CHECK (check_find_bounds_finds (mock_index
,
4199 "\377", expected_syms1
));
4201 static const char *expected_syms2
[] = {
4204 SELF_CHECK (check_find_bounds_finds (mock_index
,
4205 "\377\377", expected_syms2
));
4209 /* Test dw2_expand_symtabs_matching_symbol. */
4212 test_dw2_expand_symtabs_matching_symbol ()
4214 mock_mapped_index
mock_index (test_symbols
);
4216 /* We let all tests run until the end even if some fails, for debug
4218 bool any_mismatch
= false;
4220 /* Create the expected symbols list (an initializer_list). Needed
4221 because lists have commas, and we need to pass them to CHECK,
4222 which is a macro. */
4223 #define EXPECT(...) { __VA_ARGS__ }
4225 /* Wrapper for check_match that passes down the current
4226 __FILE__/__LINE__. */
4227 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4228 any_mismatch |= !check_match (__FILE__, __LINE__, \
4230 NAME, MATCH_TYPE, COMPLETION_MODE, \
4233 /* Identity checks. */
4234 for (const char *sym
: test_symbols
)
4236 /* Should be able to match all existing symbols. */
4237 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4240 /* Should be able to match all existing symbols with
4242 std::string with_params
= std::string (sym
) + "(int)";
4243 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4246 /* Should be able to match all existing symbols with
4247 parameters and qualifiers. */
4248 with_params
= std::string (sym
) + " ( int ) const";
4249 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4252 /* This should really find sym, but cp-name-parser.y doesn't
4253 know about lvalue/rvalue qualifiers yet. */
4254 with_params
= std::string (sym
) + " ( int ) &&";
4255 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4259 /* Check that the name matching algorithm for completion doesn't get
4260 confused with Latin1 'ÿ' / 0xff. */
4262 static const char str
[] = "\377";
4263 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4264 EXPECT ("\377", "\377\377123"));
4267 /* Check that the increment-last-char in the matching algorithm for
4268 completion doesn't match "t1_fund" when completing "t1_func". */
4270 static const char str
[] = "t1_func";
4271 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4272 EXPECT ("t1_func", "t1_func1"));
4275 /* Check that completion mode works at each prefix of the expected
4278 static const char str
[] = "function(int)";
4279 size_t len
= strlen (str
);
4282 for (size_t i
= 1; i
< len
; i
++)
4284 lookup
.assign (str
, i
);
4285 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4286 EXPECT ("function"));
4290 /* While "w" is a prefix of both components, the match function
4291 should still only be called once. */
4293 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4295 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4299 /* Same, with a "complicated" symbol. */
4301 static const char str
[] = Z_SYM_NAME
;
4302 size_t len
= strlen (str
);
4305 for (size_t i
= 1; i
< len
; i
++)
4307 lookup
.assign (str
, i
);
4308 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4309 EXPECT (Z_SYM_NAME
));
4313 /* In FULL mode, an incomplete symbol doesn't match. */
4315 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4319 /* A complete symbol with parameters matches any overload, since the
4320 index has no overload info. */
4322 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4323 EXPECT ("std::zfunction", "std::zfunction2"));
4324 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4325 EXPECT ("std::zfunction", "std::zfunction2"));
4326 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4327 EXPECT ("std::zfunction", "std::zfunction2"));
4330 /* Check that whitespace is ignored appropriately. A symbol with a
4331 template argument list. */
4333 static const char expected
[] = "ns::foo<int>";
4334 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4336 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4340 /* Check that whitespace is ignored appropriately. A symbol with a
4341 template argument list that includes a pointer. */
4343 static const char expected
[] = "ns::foo<char*>";
4344 /* Try both completion and non-completion modes. */
4345 static const bool completion_mode
[2] = {false, true};
4346 for (size_t i
= 0; i
< 2; i
++)
4348 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4349 completion_mode
[i
], EXPECT (expected
));
4350 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4351 completion_mode
[i
], EXPECT (expected
));
4353 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4354 completion_mode
[i
], EXPECT (expected
));
4355 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4356 completion_mode
[i
], EXPECT (expected
));
4361 /* Check method qualifiers are ignored. */
4362 static const char expected
[] = "ns::foo<char*>";
4363 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4364 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4365 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4366 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4367 CHECK_MATCH ("foo < char * > ( int ) const",
4368 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4369 CHECK_MATCH ("foo < char * > ( int ) &&",
4370 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4373 /* Test lookup names that don't match anything. */
4375 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4378 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4382 /* Some wild matching tests, exercising "(anonymous namespace)",
4383 which should not be confused with a parameter list. */
4385 static const char *syms
[] = {
4389 "A :: B :: C ( int )",
4394 for (const char *s
: syms
)
4396 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4397 EXPECT ("(anonymous namespace)::A::B::C"));
4402 static const char expected
[] = "ns2::tmpl<int>::foo2";
4403 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4405 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4409 SELF_CHECK (!any_mismatch
);
4418 test_mapped_index_find_name_component_bounds ();
4419 test_dw2_expand_symtabs_matching_symbol ();
4422 }} // namespace selftests::dw2_expand_symtabs_matching
4424 #endif /* GDB_SELF_TEST */
4426 /* If FILE_MATCHER is NULL or if PER_CU has
4427 dwarf2_per_cu_quick_data::MARK set (see
4428 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4429 EXPANSION_NOTIFY on it. */
4432 dw2_expand_symtabs_matching_one
4433 (struct dwarf2_per_cu_data
*per_cu
,
4434 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4435 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4437 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4439 bool symtab_was_null
4440 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4442 dw2_instantiate_symtab (per_cu
, false);
4444 if (expansion_notify
!= NULL
4446 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4447 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4451 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4452 matched, to expand corresponding CUs that were marked. IDX is the
4453 index of the symbol name that matched. */
4456 dw2_expand_marked_cus
4457 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4458 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4459 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4462 offset_type
*vec
, vec_len
, vec_idx
;
4463 bool global_seen
= false;
4464 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4466 vec
= (offset_type
*) (index
.constant_pool
4467 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4468 vec_len
= MAYBE_SWAP (vec
[0]);
4469 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4471 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4472 /* This value is only valid for index versions >= 7. */
4473 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4474 gdb_index_symbol_kind symbol_kind
=
4475 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4476 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4477 /* Only check the symbol attributes if they're present.
4478 Indices prior to version 7 don't record them,
4479 and indices >= 7 may elide them for certain symbols
4480 (gold does this). */
4483 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4485 /* Work around gold/15646. */
4488 if (!is_static
&& global_seen
)
4494 /* Only check the symbol's kind if it has one. */
4499 case VARIABLES_DOMAIN
:
4500 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4503 case FUNCTIONS_DOMAIN
:
4504 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4508 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4511 case MODULES_DOMAIN
:
4512 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4520 /* Don't crash on bad data. */
4521 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4522 + dwarf2_per_objfile
->all_type_units
.size ()))
4524 complaint (_(".gdb_index entry has bad CU index"
4526 objfile_name (dwarf2_per_objfile
->objfile
));
4530 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4531 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4536 /* If FILE_MATCHER is non-NULL, set all the
4537 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4538 that match FILE_MATCHER. */
4541 dw_expand_symtabs_matching_file_matcher
4542 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4543 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4545 if (file_matcher
== NULL
)
4548 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4550 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4552 NULL
, xcalloc
, xfree
));
4553 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4555 NULL
, xcalloc
, xfree
));
4557 /* The rule is CUs specify all the files, including those used by
4558 any TU, so there's no need to scan TUs here. */
4560 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4564 per_cu
->v
.quick
->mark
= 0;
4566 /* We only need to look at symtabs not already expanded. */
4567 if (per_cu
->v
.quick
->compunit_symtab
)
4570 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4571 if (file_data
== NULL
)
4574 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4576 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4578 per_cu
->v
.quick
->mark
= 1;
4582 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4584 const char *this_real_name
;
4586 if (file_matcher (file_data
->file_names
[j
], false))
4588 per_cu
->v
.quick
->mark
= 1;
4592 /* Before we invoke realpath, which can get expensive when many
4593 files are involved, do a quick comparison of the basenames. */
4594 if (!basenames_may_differ
4595 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4599 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4600 if (file_matcher (this_real_name
, false))
4602 per_cu
->v
.quick
->mark
= 1;
4607 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4608 ? visited_found
.get ()
4609 : visited_not_found
.get (),
4616 dw2_expand_symtabs_matching
4617 (struct objfile
*objfile
,
4618 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4619 const lookup_name_info
&lookup_name
,
4620 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4621 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4622 enum search_domain kind
)
4624 struct dwarf2_per_objfile
*dwarf2_per_objfile
4625 = get_dwarf2_per_objfile (objfile
);
4627 /* index_table is NULL if OBJF_READNOW. */
4628 if (!dwarf2_per_objfile
->index_table
)
4631 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4633 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4635 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4637 kind
, [&] (offset_type idx
)
4639 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4640 expansion_notify
, kind
);
4645 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4648 static struct compunit_symtab
*
4649 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4654 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4655 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4658 if (cust
->includes
== NULL
)
4661 for (i
= 0; cust
->includes
[i
]; ++i
)
4663 struct compunit_symtab
*s
= cust
->includes
[i
];
4665 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4673 static struct compunit_symtab
*
4674 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4675 struct bound_minimal_symbol msymbol
,
4677 struct obj_section
*section
,
4680 struct dwarf2_per_cu_data
*data
;
4681 struct compunit_symtab
*result
;
4683 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4686 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4687 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4688 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4692 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4693 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4694 paddress (get_objfile_arch (objfile
), pc
));
4697 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4700 gdb_assert (result
!= NULL
);
4705 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4706 void *data
, int need_fullname
)
4708 struct dwarf2_per_objfile
*dwarf2_per_objfile
4709 = get_dwarf2_per_objfile (objfile
);
4711 if (!dwarf2_per_objfile
->filenames_cache
)
4713 dwarf2_per_objfile
->filenames_cache
.emplace ();
4715 htab_up
visited (htab_create_alloc (10,
4716 htab_hash_pointer
, htab_eq_pointer
,
4717 NULL
, xcalloc
, xfree
));
4719 /* The rule is CUs specify all the files, including those used
4720 by any TU, so there's no need to scan TUs here. We can
4721 ignore file names coming from already-expanded CUs. */
4723 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4725 if (per_cu
->v
.quick
->compunit_symtab
)
4727 void **slot
= htab_find_slot (visited
.get (),
4728 per_cu
->v
.quick
->file_names
,
4731 *slot
= per_cu
->v
.quick
->file_names
;
4735 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4737 /* We only need to look at symtabs not already expanded. */
4738 if (per_cu
->v
.quick
->compunit_symtab
)
4741 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4742 if (file_data
== NULL
)
4745 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4748 /* Already visited. */
4753 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4755 const char *filename
= file_data
->file_names
[j
];
4756 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4761 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4763 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4766 this_real_name
= gdb_realpath (filename
);
4767 (*fun
) (filename
, this_real_name
.get (), data
);
4772 dw2_has_symbols (struct objfile
*objfile
)
4777 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4780 dw2_find_last_source_symtab
,
4781 dw2_forget_cached_source_info
,
4782 dw2_map_symtabs_matching_filename
,
4786 dw2_expand_symtabs_for_function
,
4787 dw2_expand_all_symtabs
,
4788 dw2_expand_symtabs_with_fullname
,
4789 dw2_map_matching_symbols
,
4790 dw2_expand_symtabs_matching
,
4791 dw2_find_pc_sect_compunit_symtab
,
4793 dw2_map_symbol_filenames
4796 /* DWARF-5 debug_names reader. */
4798 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4799 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4801 /* A helper function that reads the .debug_names section in SECTION
4802 and fills in MAP. FILENAME is the name of the file containing the
4803 section; it is used for error reporting.
4805 Returns true if all went well, false otherwise. */
4808 read_debug_names_from_section (struct objfile
*objfile
,
4809 const char *filename
,
4810 struct dwarf2_section_info
*section
,
4811 mapped_debug_names
&map
)
4813 if (section
->empty ())
4816 /* Older elfutils strip versions could keep the section in the main
4817 executable while splitting it for the separate debug info file. */
4818 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4821 section
->read (objfile
);
4823 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4825 const gdb_byte
*addr
= section
->buffer
;
4827 bfd
*const abfd
= section
->get_bfd_owner ();
4829 unsigned int bytes_read
;
4830 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4833 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4834 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4835 if (bytes_read
+ length
!= section
->size
)
4837 /* There may be multiple per-CU indices. */
4838 warning (_("Section .debug_names in %s length %s does not match "
4839 "section length %s, ignoring .debug_names."),
4840 filename
, plongest (bytes_read
+ length
),
4841 pulongest (section
->size
));
4845 /* The version number. */
4846 uint16_t version
= read_2_bytes (abfd
, addr
);
4850 warning (_("Section .debug_names in %s has unsupported version %d, "
4851 "ignoring .debug_names."),
4857 uint16_t padding
= read_2_bytes (abfd
, addr
);
4861 warning (_("Section .debug_names in %s has unsupported padding %d, "
4862 "ignoring .debug_names."),
4867 /* comp_unit_count - The number of CUs in the CU list. */
4868 map
.cu_count
= read_4_bytes (abfd
, addr
);
4871 /* local_type_unit_count - The number of TUs in the local TU
4873 map
.tu_count
= read_4_bytes (abfd
, addr
);
4876 /* foreign_type_unit_count - The number of TUs in the foreign TU
4878 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4880 if (foreign_tu_count
!= 0)
4882 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4883 "ignoring .debug_names."),
4884 filename
, static_cast<unsigned long> (foreign_tu_count
));
4888 /* bucket_count - The number of hash buckets in the hash lookup
4890 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4893 /* name_count - The number of unique names in the index. */
4894 map
.name_count
= read_4_bytes (abfd
, addr
);
4897 /* abbrev_table_size - The size in bytes of the abbreviations
4899 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4902 /* augmentation_string_size - The size in bytes of the augmentation
4903 string. This value is rounded up to a multiple of 4. */
4904 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4906 map
.augmentation_is_gdb
= ((augmentation_string_size
4907 == sizeof (dwarf5_augmentation
))
4908 && memcmp (addr
, dwarf5_augmentation
,
4909 sizeof (dwarf5_augmentation
)) == 0);
4910 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4911 addr
+= augmentation_string_size
;
4914 map
.cu_table_reordered
= addr
;
4915 addr
+= map
.cu_count
* map
.offset_size
;
4917 /* List of Local TUs */
4918 map
.tu_table_reordered
= addr
;
4919 addr
+= map
.tu_count
* map
.offset_size
;
4921 /* Hash Lookup Table */
4922 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4923 addr
+= map
.bucket_count
* 4;
4924 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4925 addr
+= map
.name_count
* 4;
4928 map
.name_table_string_offs_reordered
= addr
;
4929 addr
+= map
.name_count
* map
.offset_size
;
4930 map
.name_table_entry_offs_reordered
= addr
;
4931 addr
+= map
.name_count
* map
.offset_size
;
4933 const gdb_byte
*abbrev_table_start
= addr
;
4936 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4941 const auto insertpair
4942 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4943 if (!insertpair
.second
)
4945 warning (_("Section .debug_names in %s has duplicate index %s, "
4946 "ignoring .debug_names."),
4947 filename
, pulongest (index_num
));
4950 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4951 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4956 mapped_debug_names::index_val::attr attr
;
4957 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4959 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4961 if (attr
.form
== DW_FORM_implicit_const
)
4963 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4967 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4969 indexval
.attr_vec
.push_back (std::move (attr
));
4972 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4974 warning (_("Section .debug_names in %s has abbreviation_table "
4975 "of size %s vs. written as %u, ignoring .debug_names."),
4976 filename
, plongest (addr
- abbrev_table_start
),
4980 map
.entry_pool
= addr
;
4985 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4989 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4990 const mapped_debug_names
&map
,
4991 dwarf2_section_info
§ion
,
4994 sect_offset sect_off_prev
;
4995 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4997 sect_offset sect_off_next
;
4998 if (i
< map
.cu_count
)
5001 = (sect_offset
) (extract_unsigned_integer
5002 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5004 map
.dwarf5_byte_order
));
5007 sect_off_next
= (sect_offset
) section
.size
;
5010 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5011 dwarf2_per_cu_data
*per_cu
5012 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5013 sect_off_prev
, length
);
5014 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5016 sect_off_prev
= sect_off_next
;
5020 /* Read the CU list from the mapped index, and use it to create all
5021 the CU objects for this dwarf2_per_objfile. */
5024 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5025 const mapped_debug_names
&map
,
5026 const mapped_debug_names
&dwz_map
)
5028 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5029 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5031 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5032 dwarf2_per_objfile
->info
,
5033 false /* is_dwz */);
5035 if (dwz_map
.cu_count
== 0)
5038 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5039 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5043 /* Read .debug_names. If everything went ok, initialize the "quick"
5044 elements of all the CUs and return true. Otherwise, return false. */
5047 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5049 std::unique_ptr
<mapped_debug_names
> map
5050 (new mapped_debug_names (dwarf2_per_objfile
));
5051 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5054 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5055 &dwarf2_per_objfile
->debug_names
,
5059 /* Don't use the index if it's empty. */
5060 if (map
->name_count
== 0)
5063 /* If there is a .dwz file, read it so we can get its CU list as
5065 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5068 if (!read_debug_names_from_section (objfile
,
5069 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5070 &dwz
->debug_names
, dwz_map
))
5072 warning (_("could not read '.debug_names' section from %s; skipping"),
5073 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5078 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5080 if (map
->tu_count
!= 0)
5082 /* We can only handle a single .debug_types when we have an
5084 if (dwarf2_per_objfile
->types
.size () != 1)
5087 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5089 create_signatured_type_table_from_debug_names
5090 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5093 create_addrmap_from_aranges (dwarf2_per_objfile
,
5094 &dwarf2_per_objfile
->debug_aranges
);
5096 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5097 dwarf2_per_objfile
->using_index
= 1;
5098 dwarf2_per_objfile
->quick_file_names_table
=
5099 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5104 /* Type used to manage iterating over all CUs looking for a symbol for
5107 class dw2_debug_names_iterator
5110 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5111 gdb::optional
<block_enum
> block_index
,
5114 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5115 m_addr (find_vec_in_debug_names (map
, name
))
5118 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5119 search_domain search
, uint32_t namei
)
5122 m_addr (find_vec_in_debug_names (map
, namei
))
5125 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5126 block_enum block_index
, domain_enum domain
,
5128 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5129 m_addr (find_vec_in_debug_names (map
, namei
))
5132 /* Return the next matching CU or NULL if there are no more. */
5133 dwarf2_per_cu_data
*next ();
5136 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5138 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5141 /* The internalized form of .debug_names. */
5142 const mapped_debug_names
&m_map
;
5144 /* If set, only look for symbols that match that block. Valid values are
5145 GLOBAL_BLOCK and STATIC_BLOCK. */
5146 const gdb::optional
<block_enum
> m_block_index
;
5148 /* The kind of symbol we're looking for. */
5149 const domain_enum m_domain
= UNDEF_DOMAIN
;
5150 const search_domain m_search
= ALL_DOMAIN
;
5152 /* The list of CUs from the index entry of the symbol, or NULL if
5154 const gdb_byte
*m_addr
;
5158 mapped_debug_names::namei_to_name (uint32_t namei
) const
5160 const ULONGEST namei_string_offs
5161 = extract_unsigned_integer ((name_table_string_offs_reordered
5162 + namei
* offset_size
),
5165 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5169 /* Find a slot in .debug_names for the object named NAME. If NAME is
5170 found, return pointer to its pool data. If NAME cannot be found,
5174 dw2_debug_names_iterator::find_vec_in_debug_names
5175 (const mapped_debug_names
&map
, const char *name
)
5177 int (*cmp
) (const char *, const char *);
5179 gdb::unique_xmalloc_ptr
<char> without_params
;
5180 if (current_language
->la_language
== language_cplus
5181 || current_language
->la_language
== language_fortran
5182 || current_language
->la_language
== language_d
)
5184 /* NAME is already canonical. Drop any qualifiers as
5185 .debug_names does not contain any. */
5187 if (strchr (name
, '(') != NULL
)
5189 without_params
= cp_remove_params (name
);
5190 if (without_params
!= NULL
)
5191 name
= without_params
.get ();
5195 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5197 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5199 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5200 (map
.bucket_table_reordered
5201 + (full_hash
% map
.bucket_count
)), 4,
5202 map
.dwarf5_byte_order
);
5206 if (namei
>= map
.name_count
)
5208 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5210 namei
, map
.name_count
,
5211 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5217 const uint32_t namei_full_hash
5218 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5219 (map
.hash_table_reordered
+ namei
), 4,
5220 map
.dwarf5_byte_order
);
5221 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5224 if (full_hash
== namei_full_hash
)
5226 const char *const namei_string
= map
.namei_to_name (namei
);
5228 #if 0 /* An expensive sanity check. */
5229 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5231 complaint (_("Wrong .debug_names hash for string at index %u "
5233 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5238 if (cmp (namei_string
, name
) == 0)
5240 const ULONGEST namei_entry_offs
5241 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5242 + namei
* map
.offset_size
),
5243 map
.offset_size
, map
.dwarf5_byte_order
);
5244 return map
.entry_pool
+ namei_entry_offs
;
5249 if (namei
>= map
.name_count
)
5255 dw2_debug_names_iterator::find_vec_in_debug_names
5256 (const mapped_debug_names
&map
, uint32_t namei
)
5258 if (namei
>= map
.name_count
)
5260 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5262 namei
, map
.name_count
,
5263 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5267 const ULONGEST namei_entry_offs
5268 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5269 + namei
* map
.offset_size
),
5270 map
.offset_size
, map
.dwarf5_byte_order
);
5271 return map
.entry_pool
+ namei_entry_offs
;
5274 /* See dw2_debug_names_iterator. */
5276 dwarf2_per_cu_data
*
5277 dw2_debug_names_iterator::next ()
5282 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5284 bfd
*const abfd
= objfile
->obfd
;
5288 unsigned int bytes_read
;
5289 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5290 m_addr
+= bytes_read
;
5294 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5295 if (indexval_it
== m_map
.abbrev_map
.cend ())
5297 complaint (_("Wrong .debug_names undefined abbrev code %s "
5299 pulongest (abbrev
), objfile_name (objfile
));
5302 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5303 enum class symbol_linkage
{
5307 } symbol_linkage_
= symbol_linkage::unknown
;
5308 dwarf2_per_cu_data
*per_cu
= NULL
;
5309 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5314 case DW_FORM_implicit_const
:
5315 ull
= attr
.implicit_const
;
5317 case DW_FORM_flag_present
:
5321 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5322 m_addr
+= bytes_read
;
5325 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5326 dwarf_form_name (attr
.form
),
5327 objfile_name (objfile
));
5330 switch (attr
.dw_idx
)
5332 case DW_IDX_compile_unit
:
5333 /* Don't crash on bad data. */
5334 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5336 complaint (_(".debug_names entry has bad CU index %s"
5339 objfile_name (dwarf2_per_objfile
->objfile
));
5342 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5344 case DW_IDX_type_unit
:
5345 /* Don't crash on bad data. */
5346 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5348 complaint (_(".debug_names entry has bad TU index %s"
5351 objfile_name (dwarf2_per_objfile
->objfile
));
5354 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5356 case DW_IDX_GNU_internal
:
5357 if (!m_map
.augmentation_is_gdb
)
5359 symbol_linkage_
= symbol_linkage::static_
;
5361 case DW_IDX_GNU_external
:
5362 if (!m_map
.augmentation_is_gdb
)
5364 symbol_linkage_
= symbol_linkage::extern_
;
5369 /* Skip if already read in. */
5370 if (per_cu
->v
.quick
->compunit_symtab
)
5373 /* Check static vs global. */
5374 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5376 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5377 const bool symbol_is_static
=
5378 symbol_linkage_
== symbol_linkage::static_
;
5379 if (want_static
!= symbol_is_static
)
5383 /* Match dw2_symtab_iter_next, symbol_kind
5384 and debug_names::psymbol_tag. */
5388 switch (indexval
.dwarf_tag
)
5390 case DW_TAG_variable
:
5391 case DW_TAG_subprogram
:
5392 /* Some types are also in VAR_DOMAIN. */
5393 case DW_TAG_typedef
:
5394 case DW_TAG_structure_type
:
5401 switch (indexval
.dwarf_tag
)
5403 case DW_TAG_typedef
:
5404 case DW_TAG_structure_type
:
5411 switch (indexval
.dwarf_tag
)
5414 case DW_TAG_variable
:
5421 switch (indexval
.dwarf_tag
)
5433 /* Match dw2_expand_symtabs_matching, symbol_kind and
5434 debug_names::psymbol_tag. */
5437 case VARIABLES_DOMAIN
:
5438 switch (indexval
.dwarf_tag
)
5440 case DW_TAG_variable
:
5446 case FUNCTIONS_DOMAIN
:
5447 switch (indexval
.dwarf_tag
)
5449 case DW_TAG_subprogram
:
5456 switch (indexval
.dwarf_tag
)
5458 case DW_TAG_typedef
:
5459 case DW_TAG_structure_type
:
5465 case MODULES_DOMAIN
:
5466 switch (indexval
.dwarf_tag
)
5480 static struct compunit_symtab
*
5481 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5482 const char *name
, domain_enum domain
)
5484 struct dwarf2_per_objfile
*dwarf2_per_objfile
5485 = get_dwarf2_per_objfile (objfile
);
5487 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5490 /* index is NULL if OBJF_READNOW. */
5493 const auto &map
= *mapp
;
5495 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5497 struct compunit_symtab
*stab_best
= NULL
;
5498 struct dwarf2_per_cu_data
*per_cu
;
5499 while ((per_cu
= iter
.next ()) != NULL
)
5501 struct symbol
*sym
, *with_opaque
= NULL
;
5502 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5503 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5504 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5506 sym
= block_find_symbol (block
, name
, domain
,
5507 block_find_non_opaque_type_preferred
,
5510 /* Some caution must be observed with overloaded functions and
5511 methods, since the index will not contain any overload
5512 information (but NAME might contain it). */
5515 && strcmp_iw (sym
->search_name (), name
) == 0)
5517 if (with_opaque
!= NULL
5518 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5521 /* Keep looking through other CUs. */
5527 /* This dumps minimal information about .debug_names. It is called
5528 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5529 uses this to verify that .debug_names has been loaded. */
5532 dw2_debug_names_dump (struct objfile
*objfile
)
5534 struct dwarf2_per_objfile
*dwarf2_per_objfile
5535 = get_dwarf2_per_objfile (objfile
);
5537 gdb_assert (dwarf2_per_objfile
->using_index
);
5538 printf_filtered (".debug_names:");
5539 if (dwarf2_per_objfile
->debug_names_table
)
5540 printf_filtered (" exists\n");
5542 printf_filtered (" faked for \"readnow\"\n");
5543 printf_filtered ("\n");
5547 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5548 const char *func_name
)
5550 struct dwarf2_per_objfile
*dwarf2_per_objfile
5551 = get_dwarf2_per_objfile (objfile
);
5553 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5554 if (dwarf2_per_objfile
->debug_names_table
)
5556 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5558 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5560 struct dwarf2_per_cu_data
*per_cu
;
5561 while ((per_cu
= iter
.next ()) != NULL
)
5562 dw2_instantiate_symtab (per_cu
, false);
5567 dw2_debug_names_map_matching_symbols
5568 (struct objfile
*objfile
,
5569 const lookup_name_info
&name
, domain_enum domain
,
5571 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5572 symbol_compare_ftype
*ordered_compare
)
5574 struct dwarf2_per_objfile
*dwarf2_per_objfile
5575 = get_dwarf2_per_objfile (objfile
);
5577 /* debug_names_table is NULL if OBJF_READNOW. */
5578 if (!dwarf2_per_objfile
->debug_names_table
)
5581 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5582 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5584 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5585 auto matcher
= [&] (const char *symname
)
5587 if (ordered_compare
== nullptr)
5589 return ordered_compare (symname
, match_name
) == 0;
5592 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5593 [&] (offset_type namei
)
5595 /* The name was matched, now expand corresponding CUs that were
5597 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5599 struct dwarf2_per_cu_data
*per_cu
;
5600 while ((per_cu
= iter
.next ()) != NULL
)
5601 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5605 /* It's a shame we couldn't do this inside the
5606 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5607 that have already been expanded. Instead, this loop matches what
5608 the psymtab code does. */
5609 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5611 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5612 if (cust
!= nullptr)
5614 const struct block
*block
5615 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5616 if (!iterate_over_symbols_terminated (block
, name
,
5624 dw2_debug_names_expand_symtabs_matching
5625 (struct objfile
*objfile
,
5626 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5627 const lookup_name_info
&lookup_name
,
5628 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5629 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5630 enum search_domain kind
)
5632 struct dwarf2_per_objfile
*dwarf2_per_objfile
5633 = get_dwarf2_per_objfile (objfile
);
5635 /* debug_names_table is NULL if OBJF_READNOW. */
5636 if (!dwarf2_per_objfile
->debug_names_table
)
5639 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5641 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5643 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5645 kind
, [&] (offset_type namei
)
5647 /* The name was matched, now expand corresponding CUs that were
5649 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5651 struct dwarf2_per_cu_data
*per_cu
;
5652 while ((per_cu
= iter
.next ()) != NULL
)
5653 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5659 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5662 dw2_find_last_source_symtab
,
5663 dw2_forget_cached_source_info
,
5664 dw2_map_symtabs_matching_filename
,
5665 dw2_debug_names_lookup_symbol
,
5667 dw2_debug_names_dump
,
5668 dw2_debug_names_expand_symtabs_for_function
,
5669 dw2_expand_all_symtabs
,
5670 dw2_expand_symtabs_with_fullname
,
5671 dw2_debug_names_map_matching_symbols
,
5672 dw2_debug_names_expand_symtabs_matching
,
5673 dw2_find_pc_sect_compunit_symtab
,
5675 dw2_map_symbol_filenames
5678 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5679 to either a dwarf2_per_objfile or dwz_file object. */
5681 template <typename T
>
5682 static gdb::array_view
<const gdb_byte
>
5683 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5685 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5687 if (section
->empty ())
5690 /* Older elfutils strip versions could keep the section in the main
5691 executable while splitting it for the separate debug info file. */
5692 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5695 section
->read (obj
);
5697 /* dwarf2_section_info::size is a bfd_size_type, while
5698 gdb::array_view works with size_t. On 32-bit hosts, with
5699 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5700 is 32-bit. So we need an explicit narrowing conversion here.
5701 This is fine, because it's impossible to allocate or mmap an
5702 array/buffer larger than what size_t can represent. */
5703 return gdb::make_array_view (section
->buffer
, section
->size
);
5706 /* Lookup the index cache for the contents of the index associated to
5709 static gdb::array_view
<const gdb_byte
>
5710 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5712 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5713 if (build_id
== nullptr)
5716 return global_index_cache
.lookup_gdb_index (build_id
,
5717 &dwarf2_obj
->index_cache_res
);
5720 /* Same as the above, but for DWZ. */
5722 static gdb::array_view
<const gdb_byte
>
5723 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5725 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5726 if (build_id
== nullptr)
5729 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5732 /* See symfile.h. */
5735 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5737 struct dwarf2_per_objfile
*dwarf2_per_objfile
5738 = get_dwarf2_per_objfile (objfile
);
5740 /* If we're about to read full symbols, don't bother with the
5741 indices. In this case we also don't care if some other debug
5742 format is making psymtabs, because they are all about to be
5744 if ((objfile
->flags
& OBJF_READNOW
))
5746 dwarf2_per_objfile
->using_index
= 1;
5747 create_all_comp_units (dwarf2_per_objfile
);
5748 create_all_type_units (dwarf2_per_objfile
);
5749 dwarf2_per_objfile
->quick_file_names_table
5750 = create_quick_file_names_table
5751 (dwarf2_per_objfile
->all_comp_units
.size ());
5753 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5754 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5756 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5758 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5759 struct dwarf2_per_cu_quick_data
);
5762 /* Return 1 so that gdb sees the "quick" functions. However,
5763 these functions will be no-ops because we will have expanded
5765 *index_kind
= dw_index_kind::GDB_INDEX
;
5769 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5771 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5775 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5776 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5777 get_gdb_index_contents_from_section
<dwz_file
>))
5779 *index_kind
= dw_index_kind::GDB_INDEX
;
5783 /* ... otherwise, try to find the index in the index cache. */
5784 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5785 get_gdb_index_contents_from_cache
,
5786 get_gdb_index_contents_from_cache_dwz
))
5788 global_index_cache
.hit ();
5789 *index_kind
= dw_index_kind::GDB_INDEX
;
5793 global_index_cache
.miss ();
5799 /* Build a partial symbol table. */
5802 dwarf2_build_psymtabs (struct objfile
*objfile
)
5804 struct dwarf2_per_objfile
*dwarf2_per_objfile
5805 = get_dwarf2_per_objfile (objfile
);
5807 init_psymbol_list (objfile
, 1024);
5811 /* This isn't really ideal: all the data we allocate on the
5812 objfile's obstack is still uselessly kept around. However,
5813 freeing it seems unsafe. */
5814 psymtab_discarder
psymtabs (objfile
);
5815 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5818 /* (maybe) store an index in the cache. */
5819 global_index_cache
.store (dwarf2_per_objfile
);
5821 catch (const gdb_exception_error
&except
)
5823 exception_print (gdb_stderr
, except
);
5827 /* Find the base address of the compilation unit for range lists and
5828 location lists. It will normally be specified by DW_AT_low_pc.
5829 In DWARF-3 draft 4, the base address could be overridden by
5830 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5831 compilation units with discontinuous ranges. */
5834 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5836 struct attribute
*attr
;
5839 cu
->base_address
= 0;
5841 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5842 if (attr
!= nullptr)
5844 cu
->base_address
= attr
->value_as_address ();
5849 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5850 if (attr
!= nullptr)
5852 cu
->base_address
= attr
->value_as_address ();
5858 /* Helper function that returns the proper abbrev section for
5861 static struct dwarf2_section_info
*
5862 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5864 struct dwarf2_section_info
*abbrev
;
5865 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5867 if (this_cu
->is_dwz
)
5868 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5870 abbrev
= &dwarf2_per_objfile
->abbrev
;
5875 /* Fetch the abbreviation table offset from a comp or type unit header. */
5878 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5879 struct dwarf2_section_info
*section
,
5880 sect_offset sect_off
)
5882 bfd
*abfd
= section
->get_bfd_owner ();
5883 const gdb_byte
*info_ptr
;
5884 unsigned int initial_length_size
, offset_size
;
5887 section
->read (dwarf2_per_objfile
->objfile
);
5888 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5889 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5890 offset_size
= initial_length_size
== 4 ? 4 : 8;
5891 info_ptr
+= initial_length_size
;
5893 version
= read_2_bytes (abfd
, info_ptr
);
5897 /* Skip unit type and address size. */
5901 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5904 /* A partial symtab that is used only for include files. */
5905 struct dwarf2_include_psymtab
: public partial_symtab
5907 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5908 : partial_symtab (filename
, objfile
)
5912 void read_symtab (struct objfile
*objfile
) override
5914 expand_psymtab (objfile
);
5917 void expand_psymtab (struct objfile
*objfile
) override
5921 /* It's an include file, no symbols to read for it.
5922 Everything is in the parent symtab. */
5923 read_dependencies (objfile
);
5927 bool readin_p () const override
5932 struct compunit_symtab
*get_compunit_symtab () const override
5939 bool m_readin
= false;
5942 /* Allocate a new partial symtab for file named NAME and mark this new
5943 partial symtab as being an include of PST. */
5946 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5947 struct objfile
*objfile
)
5949 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5951 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5953 /* It shares objfile->objfile_obstack. */
5954 subpst
->dirname
= pst
->dirname
;
5957 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5958 subpst
->dependencies
[0] = pst
;
5959 subpst
->number_of_dependencies
= 1;
5962 /* Read the Line Number Program data and extract the list of files
5963 included by the source file represented by PST. Build an include
5964 partial symtab for each of these included files. */
5967 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5968 struct die_info
*die
,
5969 dwarf2_psymtab
*pst
)
5972 struct attribute
*attr
;
5974 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5975 if (attr
!= nullptr)
5976 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5978 return; /* No linetable, so no includes. */
5980 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5981 that we pass in the raw text_low here; that is ok because we're
5982 only decoding the line table to make include partial symtabs, and
5983 so the addresses aren't really used. */
5984 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5985 pst
->raw_text_low (), 1);
5989 hash_signatured_type (const void *item
)
5991 const struct signatured_type
*sig_type
5992 = (const struct signatured_type
*) item
;
5994 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5995 return sig_type
->signature
;
5999 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6001 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6002 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6004 return lhs
->signature
== rhs
->signature
;
6007 /* Allocate a hash table for signatured types. */
6010 allocate_signatured_type_table ()
6012 return htab_up (htab_create_alloc (41,
6013 hash_signatured_type
,
6015 NULL
, xcalloc
, xfree
));
6018 /* A helper function to add a signatured type CU to a table. */
6021 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6023 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6024 std::vector
<signatured_type
*> *all_type_units
6025 = (std::vector
<signatured_type
*> *) datum
;
6027 all_type_units
->push_back (sigt
);
6032 /* A helper for create_debug_types_hash_table. Read types from SECTION
6033 and fill them into TYPES_HTAB. It will process only type units,
6034 therefore DW_UT_type. */
6037 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6038 struct dwo_file
*dwo_file
,
6039 dwarf2_section_info
*section
, htab_up
&types_htab
,
6040 rcuh_kind section_kind
)
6042 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6043 struct dwarf2_section_info
*abbrev_section
;
6045 const gdb_byte
*info_ptr
, *end_ptr
;
6047 abbrev_section
= (dwo_file
!= NULL
6048 ? &dwo_file
->sections
.abbrev
6049 : &dwarf2_per_objfile
->abbrev
);
6051 if (dwarf_read_debug
)
6052 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6053 section
->get_name (),
6054 abbrev_section
->get_file_name ());
6056 section
->read (objfile
);
6057 info_ptr
= section
->buffer
;
6059 if (info_ptr
== NULL
)
6062 /* We can't set abfd until now because the section may be empty or
6063 not present, in which case the bfd is unknown. */
6064 abfd
= section
->get_bfd_owner ();
6066 /* We don't use cutu_reader here because we don't need to read
6067 any dies: the signature is in the header. */
6069 end_ptr
= info_ptr
+ section
->size
;
6070 while (info_ptr
< end_ptr
)
6072 struct signatured_type
*sig_type
;
6073 struct dwo_unit
*dwo_tu
;
6075 const gdb_byte
*ptr
= info_ptr
;
6076 struct comp_unit_head header
;
6077 unsigned int length
;
6079 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6081 /* Initialize it due to a false compiler warning. */
6082 header
.signature
= -1;
6083 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6085 /* We need to read the type's signature in order to build the hash
6086 table, but we don't need anything else just yet. */
6088 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6089 abbrev_section
, ptr
, section_kind
);
6091 length
= header
.get_length ();
6093 /* Skip dummy type units. */
6094 if (ptr
>= info_ptr
+ length
6095 || peek_abbrev_code (abfd
, ptr
) == 0
6096 || header
.unit_type
!= DW_UT_type
)
6102 if (types_htab
== NULL
)
6105 types_htab
= allocate_dwo_unit_table ();
6107 types_htab
= allocate_signatured_type_table ();
6113 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6115 dwo_tu
->dwo_file
= dwo_file
;
6116 dwo_tu
->signature
= header
.signature
;
6117 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6118 dwo_tu
->section
= section
;
6119 dwo_tu
->sect_off
= sect_off
;
6120 dwo_tu
->length
= length
;
6124 /* N.B.: type_offset is not usable if this type uses a DWO file.
6125 The real type_offset is in the DWO file. */
6127 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6128 struct signatured_type
);
6129 sig_type
->signature
= header
.signature
;
6130 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6131 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6132 sig_type
->per_cu
.is_debug_types
= 1;
6133 sig_type
->per_cu
.section
= section
;
6134 sig_type
->per_cu
.sect_off
= sect_off
;
6135 sig_type
->per_cu
.length
= length
;
6138 slot
= htab_find_slot (types_htab
.get (),
6139 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6141 gdb_assert (slot
!= NULL
);
6144 sect_offset dup_sect_off
;
6148 const struct dwo_unit
*dup_tu
6149 = (const struct dwo_unit
*) *slot
;
6151 dup_sect_off
= dup_tu
->sect_off
;
6155 const struct signatured_type
*dup_tu
6156 = (const struct signatured_type
*) *slot
;
6158 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6161 complaint (_("debug type entry at offset %s is duplicate to"
6162 " the entry at offset %s, signature %s"),
6163 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6164 hex_string (header
.signature
));
6166 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6168 if (dwarf_read_debug
> 1)
6169 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6170 sect_offset_str (sect_off
),
6171 hex_string (header
.signature
));
6177 /* Create the hash table of all entries in the .debug_types
6178 (or .debug_types.dwo) section(s).
6179 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6180 otherwise it is NULL.
6182 The result is a pointer to the hash table or NULL if there are no types.
6184 Note: This function processes DWO files only, not DWP files. */
6187 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6188 struct dwo_file
*dwo_file
,
6189 gdb::array_view
<dwarf2_section_info
> type_sections
,
6190 htab_up
&types_htab
)
6192 for (dwarf2_section_info
§ion
: type_sections
)
6193 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6194 types_htab
, rcuh_kind::TYPE
);
6197 /* Create the hash table of all entries in the .debug_types section,
6198 and initialize all_type_units.
6199 The result is zero if there is an error (e.g. missing .debug_types section),
6200 otherwise non-zero. */
6203 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6207 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6208 &dwarf2_per_objfile
->info
, types_htab
,
6209 rcuh_kind::COMPILE
);
6210 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6211 dwarf2_per_objfile
->types
, types_htab
);
6212 if (types_htab
== NULL
)
6214 dwarf2_per_objfile
->signatured_types
= NULL
;
6218 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6220 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6221 dwarf2_per_objfile
->all_type_units
.reserve
6222 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6224 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6225 add_signatured_type_cu_to_table
,
6226 &dwarf2_per_objfile
->all_type_units
);
6231 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6232 If SLOT is non-NULL, it is the entry to use in the hash table.
6233 Otherwise we find one. */
6235 static struct signatured_type
*
6236 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6239 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6241 if (dwarf2_per_objfile
->all_type_units
.size ()
6242 == dwarf2_per_objfile
->all_type_units
.capacity ())
6243 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6245 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6246 struct signatured_type
);
6248 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6249 sig_type
->signature
= sig
;
6250 sig_type
->per_cu
.is_debug_types
= 1;
6251 if (dwarf2_per_objfile
->using_index
)
6253 sig_type
->per_cu
.v
.quick
=
6254 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6255 struct dwarf2_per_cu_quick_data
);
6260 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6263 gdb_assert (*slot
== NULL
);
6265 /* The rest of sig_type must be filled in by the caller. */
6269 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6270 Fill in SIG_ENTRY with DWO_ENTRY. */
6273 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6274 struct signatured_type
*sig_entry
,
6275 struct dwo_unit
*dwo_entry
)
6277 /* Make sure we're not clobbering something we don't expect to. */
6278 gdb_assert (! sig_entry
->per_cu
.queued
);
6279 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6280 if (dwarf2_per_objfile
->using_index
)
6282 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6283 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6286 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6287 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6288 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6289 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6290 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6292 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6293 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6294 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6295 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6296 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6297 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6298 sig_entry
->dwo_unit
= dwo_entry
;
6301 /* Subroutine of lookup_signatured_type.
6302 If we haven't read the TU yet, create the signatured_type data structure
6303 for a TU to be read in directly from a DWO file, bypassing the stub.
6304 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6305 using .gdb_index, then when reading a CU we want to stay in the DWO file
6306 containing that CU. Otherwise we could end up reading several other DWO
6307 files (due to comdat folding) to process the transitive closure of all the
6308 mentioned TUs, and that can be slow. The current DWO file will have every
6309 type signature that it needs.
6310 We only do this for .gdb_index because in the psymtab case we already have
6311 to read all the DWOs to build the type unit groups. */
6313 static struct signatured_type
*
6314 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6316 struct dwarf2_per_objfile
*dwarf2_per_objfile
6317 = cu
->per_cu
->dwarf2_per_objfile
;
6318 struct dwo_file
*dwo_file
;
6319 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6320 struct signatured_type find_sig_entry
, *sig_entry
;
6323 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6325 /* If TU skeletons have been removed then we may not have read in any
6327 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6328 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6330 /* We only ever need to read in one copy of a signatured type.
6331 Use the global signatured_types array to do our own comdat-folding
6332 of types. If this is the first time we're reading this TU, and
6333 the TU has an entry in .gdb_index, replace the recorded data from
6334 .gdb_index with this TU. */
6336 find_sig_entry
.signature
= sig
;
6337 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6338 &find_sig_entry
, INSERT
);
6339 sig_entry
= (struct signatured_type
*) *slot
;
6341 /* We can get here with the TU already read, *or* in the process of being
6342 read. Don't reassign the global entry to point to this DWO if that's
6343 the case. Also note that if the TU is already being read, it may not
6344 have come from a DWO, the program may be a mix of Fission-compiled
6345 code and non-Fission-compiled code. */
6347 /* Have we already tried to read this TU?
6348 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6349 needn't exist in the global table yet). */
6350 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6353 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6354 dwo_unit of the TU itself. */
6355 dwo_file
= cu
->dwo_unit
->dwo_file
;
6357 /* Ok, this is the first time we're reading this TU. */
6358 if (dwo_file
->tus
== NULL
)
6360 find_dwo_entry
.signature
= sig
;
6361 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6363 if (dwo_entry
== NULL
)
6366 /* If the global table doesn't have an entry for this TU, add one. */
6367 if (sig_entry
== NULL
)
6368 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6370 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6371 sig_entry
->per_cu
.tu_read
= 1;
6375 /* Subroutine of lookup_signatured_type.
6376 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6377 then try the DWP file. If the TU stub (skeleton) has been removed then
6378 it won't be in .gdb_index. */
6380 static struct signatured_type
*
6381 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6383 struct dwarf2_per_objfile
*dwarf2_per_objfile
6384 = cu
->per_cu
->dwarf2_per_objfile
;
6385 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6386 struct dwo_unit
*dwo_entry
;
6387 struct signatured_type find_sig_entry
, *sig_entry
;
6390 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6391 gdb_assert (dwp_file
!= NULL
);
6393 /* If TU skeletons have been removed then we may not have read in any
6395 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6396 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6398 find_sig_entry
.signature
= sig
;
6399 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6400 &find_sig_entry
, INSERT
);
6401 sig_entry
= (struct signatured_type
*) *slot
;
6403 /* Have we already tried to read this TU?
6404 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6405 needn't exist in the global table yet). */
6406 if (sig_entry
!= NULL
)
6409 if (dwp_file
->tus
== NULL
)
6411 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6412 sig
, 1 /* is_debug_types */);
6413 if (dwo_entry
== NULL
)
6416 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6417 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6422 /* Lookup a signature based type for DW_FORM_ref_sig8.
6423 Returns NULL if signature SIG is not present in the table.
6424 It is up to the caller to complain about this. */
6426 static struct signatured_type
*
6427 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6429 struct dwarf2_per_objfile
*dwarf2_per_objfile
6430 = cu
->per_cu
->dwarf2_per_objfile
;
6433 && dwarf2_per_objfile
->using_index
)
6435 /* We're in a DWO/DWP file, and we're using .gdb_index.
6436 These cases require special processing. */
6437 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6438 return lookup_dwo_signatured_type (cu
, sig
);
6440 return lookup_dwp_signatured_type (cu
, sig
);
6444 struct signatured_type find_entry
, *entry
;
6446 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6448 find_entry
.signature
= sig
;
6449 entry
= ((struct signatured_type
*)
6450 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6456 /* Return the address base of the compile unit, which, if exists, is stored
6457 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6458 static gdb::optional
<ULONGEST
>
6459 lookup_addr_base (struct die_info
*comp_unit_die
)
6461 struct attribute
*attr
;
6462 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6463 if (attr
== nullptr)
6464 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6465 if (attr
== nullptr)
6466 return gdb::optional
<ULONGEST
> ();
6467 return DW_UNSND (attr
);
6470 /* Return range lists base of the compile unit, which, if exists, is stored
6471 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6473 lookup_ranges_base (struct die_info
*comp_unit_die
)
6475 struct attribute
*attr
;
6476 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6477 if (attr
== nullptr)
6478 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6479 if (attr
== nullptr)
6481 return DW_UNSND (attr
);
6484 /* Low level DIE reading support. */
6486 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6489 init_cu_die_reader (struct die_reader_specs
*reader
,
6490 struct dwarf2_cu
*cu
,
6491 struct dwarf2_section_info
*section
,
6492 struct dwo_file
*dwo_file
,
6493 struct abbrev_table
*abbrev_table
)
6495 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6496 reader
->abfd
= section
->get_bfd_owner ();
6498 reader
->dwo_file
= dwo_file
;
6499 reader
->die_section
= section
;
6500 reader
->buffer
= section
->buffer
;
6501 reader
->buffer_end
= section
->buffer
+ section
->size
;
6502 reader
->abbrev_table
= abbrev_table
;
6505 /* Subroutine of cutu_reader to simplify it.
6506 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6507 There's just a lot of work to do, and cutu_reader is big enough
6510 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6511 from it to the DIE in the DWO. If NULL we are skipping the stub.
6512 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6513 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6514 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6515 STUB_COMP_DIR may be non-NULL.
6516 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6517 are filled in with the info of the DIE from the DWO file.
6518 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6519 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6520 kept around for at least as long as *RESULT_READER.
6522 The result is non-zero if a valid (non-dummy) DIE was found. */
6525 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6526 struct dwo_unit
*dwo_unit
,
6527 struct die_info
*stub_comp_unit_die
,
6528 const char *stub_comp_dir
,
6529 struct die_reader_specs
*result_reader
,
6530 const gdb_byte
**result_info_ptr
,
6531 struct die_info
**result_comp_unit_die
,
6532 abbrev_table_up
*result_dwo_abbrev_table
)
6534 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6535 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6536 struct dwarf2_cu
*cu
= this_cu
->cu
;
6538 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6539 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6540 int i
,num_extra_attrs
;
6541 struct dwarf2_section_info
*dwo_abbrev_section
;
6542 struct die_info
*comp_unit_die
;
6544 /* At most one of these may be provided. */
6545 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6547 /* These attributes aren't processed until later:
6548 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6549 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6550 referenced later. However, these attributes are found in the stub
6551 which we won't have later. In order to not impose this complication
6552 on the rest of the code, we read them here and copy them to the
6561 if (stub_comp_unit_die
!= NULL
)
6563 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6565 if (! this_cu
->is_debug_types
)
6566 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6567 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6568 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6569 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6570 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6572 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6574 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6575 here (if needed). We need the value before we can process
6577 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6579 else if (stub_comp_dir
!= NULL
)
6581 /* Reconstruct the comp_dir attribute to simplify the code below. */
6582 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6583 comp_dir
->name
= DW_AT_comp_dir
;
6584 comp_dir
->form
= DW_FORM_string
;
6585 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6586 DW_STRING (comp_dir
) = stub_comp_dir
;
6589 /* Set up for reading the DWO CU/TU. */
6590 cu
->dwo_unit
= dwo_unit
;
6591 dwarf2_section_info
*section
= dwo_unit
->section
;
6592 section
->read (objfile
);
6593 abfd
= section
->get_bfd_owner ();
6594 begin_info_ptr
= info_ptr
= (section
->buffer
6595 + to_underlying (dwo_unit
->sect_off
));
6596 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6598 if (this_cu
->is_debug_types
)
6600 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6602 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6603 &cu
->header
, section
,
6605 info_ptr
, rcuh_kind::TYPE
);
6606 /* This is not an assert because it can be caused by bad debug info. */
6607 if (sig_type
->signature
!= cu
->header
.signature
)
6609 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6610 " TU at offset %s [in module %s]"),
6611 hex_string (sig_type
->signature
),
6612 hex_string (cu
->header
.signature
),
6613 sect_offset_str (dwo_unit
->sect_off
),
6614 bfd_get_filename (abfd
));
6616 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6617 /* For DWOs coming from DWP files, we don't know the CU length
6618 nor the type's offset in the TU until now. */
6619 dwo_unit
->length
= cu
->header
.get_length ();
6620 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6622 /* Establish the type offset that can be used to lookup the type.
6623 For DWO files, we don't know it until now. */
6624 sig_type
->type_offset_in_section
6625 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6629 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6630 &cu
->header
, section
,
6632 info_ptr
, rcuh_kind::COMPILE
);
6633 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6634 /* For DWOs coming from DWP files, we don't know the CU length
6636 dwo_unit
->length
= cu
->header
.get_length ();
6639 *result_dwo_abbrev_table
6640 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6641 cu
->header
.abbrev_sect_off
);
6642 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6643 result_dwo_abbrev_table
->get ());
6645 /* Read in the die, but leave space to copy over the attributes
6646 from the stub. This has the benefit of simplifying the rest of
6647 the code - all the work to maintain the illusion of a single
6648 DW_TAG_{compile,type}_unit DIE is done here. */
6649 num_extra_attrs
= ((stmt_list
!= NULL
)
6653 + (comp_dir
!= NULL
));
6654 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6657 /* Copy over the attributes from the stub to the DIE we just read in. */
6658 comp_unit_die
= *result_comp_unit_die
;
6659 i
= comp_unit_die
->num_attrs
;
6660 if (stmt_list
!= NULL
)
6661 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6663 comp_unit_die
->attrs
[i
++] = *low_pc
;
6664 if (high_pc
!= NULL
)
6665 comp_unit_die
->attrs
[i
++] = *high_pc
;
6667 comp_unit_die
->attrs
[i
++] = *ranges
;
6668 if (comp_dir
!= NULL
)
6669 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6670 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6672 if (dwarf_die_debug
)
6674 fprintf_unfiltered (gdb_stdlog
,
6675 "Read die from %s@0x%x of %s:\n",
6676 section
->get_name (),
6677 (unsigned) (begin_info_ptr
- section
->buffer
),
6678 bfd_get_filename (abfd
));
6679 dump_die (comp_unit_die
, dwarf_die_debug
);
6682 /* Skip dummy compilation units. */
6683 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6684 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6687 *result_info_ptr
= info_ptr
;
6691 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6692 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6693 signature is part of the header. */
6694 static gdb::optional
<ULONGEST
>
6695 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6697 if (cu
->header
.version
>= 5)
6698 return cu
->header
.signature
;
6699 struct attribute
*attr
;
6700 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6701 if (attr
== nullptr)
6702 return gdb::optional
<ULONGEST
> ();
6703 return DW_UNSND (attr
);
6706 /* Subroutine of cutu_reader to simplify it.
6707 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6708 Returns NULL if the specified DWO unit cannot be found. */
6710 static struct dwo_unit
*
6711 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6712 struct die_info
*comp_unit_die
,
6713 const char *dwo_name
)
6715 struct dwarf2_cu
*cu
= this_cu
->cu
;
6716 struct dwo_unit
*dwo_unit
;
6717 const char *comp_dir
;
6719 gdb_assert (cu
!= NULL
);
6721 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6722 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6723 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6725 if (this_cu
->is_debug_types
)
6727 struct signatured_type
*sig_type
;
6729 /* Since this_cu is the first member of struct signatured_type,
6730 we can go from a pointer to one to a pointer to the other. */
6731 sig_type
= (struct signatured_type
*) this_cu
;
6732 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6736 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6737 if (!signature
.has_value ())
6738 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6740 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6741 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6748 /* Subroutine of cutu_reader to simplify it.
6749 See it for a description of the parameters.
6750 Read a TU directly from a DWO file, bypassing the stub. */
6753 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6754 int use_existing_cu
)
6756 struct signatured_type
*sig_type
;
6758 /* Verify we can do the following downcast, and that we have the
6760 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6761 sig_type
= (struct signatured_type
*) this_cu
;
6762 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6764 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6766 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6767 /* There's no need to do the rereading_dwo_cu handling that
6768 cutu_reader does since we don't read the stub. */
6772 /* If !use_existing_cu, this_cu->cu must be NULL. */
6773 gdb_assert (this_cu
->cu
== NULL
);
6774 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6777 /* A future optimization, if needed, would be to use an existing
6778 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6779 could share abbrev tables. */
6781 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6782 NULL
/* stub_comp_unit_die */,
6783 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6786 &m_dwo_abbrev_table
) == 0)
6793 /* Initialize a CU (or TU) and read its DIEs.
6794 If the CU defers to a DWO file, read the DWO file as well.
6796 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6797 Otherwise the table specified in the comp unit header is read in and used.
6798 This is an optimization for when we already have the abbrev table.
6800 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6801 Otherwise, a new CU is allocated with xmalloc. */
6803 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6804 struct abbrev_table
*abbrev_table
,
6805 int use_existing_cu
,
6807 : die_reader_specs
{},
6810 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6811 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6812 struct dwarf2_section_info
*section
= this_cu
->section
;
6813 bfd
*abfd
= section
->get_bfd_owner ();
6814 struct dwarf2_cu
*cu
;
6815 const gdb_byte
*begin_info_ptr
;
6816 struct signatured_type
*sig_type
= NULL
;
6817 struct dwarf2_section_info
*abbrev_section
;
6818 /* Non-zero if CU currently points to a DWO file and we need to
6819 reread it. When this happens we need to reread the skeleton die
6820 before we can reread the DWO file (this only applies to CUs, not TUs). */
6821 int rereading_dwo_cu
= 0;
6823 if (dwarf_die_debug
)
6824 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6825 this_cu
->is_debug_types
? "type" : "comp",
6826 sect_offset_str (this_cu
->sect_off
));
6828 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6829 file (instead of going through the stub), short-circuit all of this. */
6830 if (this_cu
->reading_dwo_directly
)
6832 /* Narrow down the scope of possibilities to have to understand. */
6833 gdb_assert (this_cu
->is_debug_types
);
6834 gdb_assert (abbrev_table
== NULL
);
6835 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6839 /* This is cheap if the section is already read in. */
6840 section
->read (objfile
);
6842 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6844 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6846 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6849 /* If this CU is from a DWO file we need to start over, we need to
6850 refetch the attributes from the skeleton CU.
6851 This could be optimized by retrieving those attributes from when we
6852 were here the first time: the previous comp_unit_die was stored in
6853 comp_unit_obstack. But there's no data yet that we need this
6855 if (cu
->dwo_unit
!= NULL
)
6856 rereading_dwo_cu
= 1;
6860 /* If !use_existing_cu, this_cu->cu must be NULL. */
6861 gdb_assert (this_cu
->cu
== NULL
);
6862 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6863 cu
= m_new_cu
.get ();
6866 /* Get the header. */
6867 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6869 /* We already have the header, there's no need to read it in again. */
6870 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6874 if (this_cu
->is_debug_types
)
6876 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6877 &cu
->header
, section
,
6878 abbrev_section
, info_ptr
,
6881 /* Since per_cu is the first member of struct signatured_type,
6882 we can go from a pointer to one to a pointer to the other. */
6883 sig_type
= (struct signatured_type
*) this_cu
;
6884 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6885 gdb_assert (sig_type
->type_offset_in_tu
6886 == cu
->header
.type_cu_offset_in_tu
);
6887 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6889 /* LENGTH has not been set yet for type units if we're
6890 using .gdb_index. */
6891 this_cu
->length
= cu
->header
.get_length ();
6893 /* Establish the type offset that can be used to lookup the type. */
6894 sig_type
->type_offset_in_section
=
6895 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6897 this_cu
->dwarf_version
= cu
->header
.version
;
6901 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6902 &cu
->header
, section
,
6905 rcuh_kind::COMPILE
);
6907 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6908 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6909 this_cu
->dwarf_version
= cu
->header
.version
;
6913 /* Skip dummy compilation units. */
6914 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6915 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6921 /* If we don't have them yet, read the abbrevs for this compilation unit.
6922 And if we need to read them now, make sure they're freed when we're
6924 if (abbrev_table
!= NULL
)
6925 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6928 m_abbrev_table_holder
6929 = abbrev_table::read (objfile
, abbrev_section
,
6930 cu
->header
.abbrev_sect_off
);
6931 abbrev_table
= m_abbrev_table_holder
.get ();
6934 /* Read the top level CU/TU die. */
6935 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6936 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6938 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6944 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6945 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6946 table from the DWO file and pass the ownership over to us. It will be
6947 referenced from READER, so we must make sure to free it after we're done
6950 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6951 DWO CU, that this test will fail (the attribute will not be present). */
6952 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6953 if (dwo_name
!= nullptr)
6955 struct dwo_unit
*dwo_unit
;
6956 struct die_info
*dwo_comp_unit_die
;
6958 if (comp_unit_die
->has_children
)
6960 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6961 " has children (offset %s) [in module %s]"),
6962 sect_offset_str (this_cu
->sect_off
),
6963 bfd_get_filename (abfd
));
6965 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6966 if (dwo_unit
!= NULL
)
6968 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6969 comp_unit_die
, NULL
,
6972 &m_dwo_abbrev_table
) == 0)
6978 comp_unit_die
= dwo_comp_unit_die
;
6982 /* Yikes, we couldn't find the rest of the DIE, we only have
6983 the stub. A complaint has already been logged. There's
6984 not much more we can do except pass on the stub DIE to
6985 die_reader_func. We don't want to throw an error on bad
6992 cutu_reader::keep ()
6994 /* Done, clean up. */
6995 gdb_assert (!dummy_p
);
6996 if (m_new_cu
!= NULL
)
6998 struct dwarf2_per_objfile
*dwarf2_per_objfile
6999 = m_this_cu
->dwarf2_per_objfile
;
7000 /* Link this CU into read_in_chain. */
7001 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7002 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7003 /* The chain owns it now. */
7004 m_new_cu
.release ();
7008 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7009 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7010 assumed to have already done the lookup to find the DWO file).
7012 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7013 THIS_CU->is_debug_types, but nothing else.
7015 We fill in THIS_CU->length.
7017 THIS_CU->cu is always freed when done.
7018 This is done in order to not leave THIS_CU->cu in a state where we have
7019 to care whether it refers to the "main" CU or the DWO CU.
7021 When parent_cu is passed, it is used to provide a default value for
7022 str_offsets_base and addr_base from the parent. */
7024 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7025 struct dwarf2_cu
*parent_cu
,
7026 struct dwo_file
*dwo_file
)
7027 : die_reader_specs
{},
7030 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7031 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7032 struct dwarf2_section_info
*section
= this_cu
->section
;
7033 bfd
*abfd
= section
->get_bfd_owner ();
7034 struct dwarf2_section_info
*abbrev_section
;
7035 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7037 if (dwarf_die_debug
)
7038 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7039 this_cu
->is_debug_types
? "type" : "comp",
7040 sect_offset_str (this_cu
->sect_off
));
7042 gdb_assert (this_cu
->cu
== NULL
);
7044 abbrev_section
= (dwo_file
!= NULL
7045 ? &dwo_file
->sections
.abbrev
7046 : get_abbrev_section_for_cu (this_cu
));
7048 /* This is cheap if the section is already read in. */
7049 section
->read (objfile
);
7051 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7053 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7054 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7055 &m_new_cu
->header
, section
,
7056 abbrev_section
, info_ptr
,
7057 (this_cu
->is_debug_types
7059 : rcuh_kind::COMPILE
));
7061 if (parent_cu
!= nullptr)
7063 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7064 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7066 this_cu
->length
= m_new_cu
->header
.get_length ();
7068 /* Skip dummy compilation units. */
7069 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7070 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7076 m_abbrev_table_holder
7077 = abbrev_table::read (objfile
, abbrev_section
,
7078 m_new_cu
->header
.abbrev_sect_off
);
7080 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7081 m_abbrev_table_holder
.get ());
7082 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7086 /* Type Unit Groups.
7088 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7089 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7090 so that all types coming from the same compilation (.o file) are grouped
7091 together. A future step could be to put the types in the same symtab as
7092 the CU the types ultimately came from. */
7095 hash_type_unit_group (const void *item
)
7097 const struct type_unit_group
*tu_group
7098 = (const struct type_unit_group
*) item
;
7100 return hash_stmt_list_entry (&tu_group
->hash
);
7104 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7106 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7107 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7109 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7112 /* Allocate a hash table for type unit groups. */
7115 allocate_type_unit_groups_table ()
7117 return htab_up (htab_create_alloc (3,
7118 hash_type_unit_group
,
7120 NULL
, xcalloc
, xfree
));
7123 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7124 partial symtabs. We combine several TUs per psymtab to not let the size
7125 of any one psymtab grow too big. */
7126 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7127 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7129 /* Helper routine for get_type_unit_group.
7130 Create the type_unit_group object used to hold one or more TUs. */
7132 static struct type_unit_group
*
7133 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7135 struct dwarf2_per_objfile
*dwarf2_per_objfile
7136 = cu
->per_cu
->dwarf2_per_objfile
;
7137 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7138 struct dwarf2_per_cu_data
*per_cu
;
7139 struct type_unit_group
*tu_group
;
7141 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7142 struct type_unit_group
);
7143 per_cu
= &tu_group
->per_cu
;
7144 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7146 if (dwarf2_per_objfile
->using_index
)
7148 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7149 struct dwarf2_per_cu_quick_data
);
7153 unsigned int line_offset
= to_underlying (line_offset_struct
);
7154 dwarf2_psymtab
*pst
;
7157 /* Give the symtab a useful name for debug purposes. */
7158 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7159 name
= string_printf ("<type_units_%d>",
7160 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7162 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7164 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7165 pst
->anonymous
= true;
7168 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7169 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7174 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7175 STMT_LIST is a DW_AT_stmt_list attribute. */
7177 static struct type_unit_group
*
7178 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7180 struct dwarf2_per_objfile
*dwarf2_per_objfile
7181 = cu
->per_cu
->dwarf2_per_objfile
;
7182 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7183 struct type_unit_group
*tu_group
;
7185 unsigned int line_offset
;
7186 struct type_unit_group type_unit_group_for_lookup
;
7188 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7189 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7191 /* Do we need to create a new group, or can we use an existing one? */
7195 line_offset
= DW_UNSND (stmt_list
);
7196 ++tu_stats
->nr_symtab_sharers
;
7200 /* Ugh, no stmt_list. Rare, but we have to handle it.
7201 We can do various things here like create one group per TU or
7202 spread them over multiple groups to split up the expansion work.
7203 To avoid worst case scenarios (too many groups or too large groups)
7204 we, umm, group them in bunches. */
7205 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7206 | (tu_stats
->nr_stmt_less_type_units
7207 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7208 ++tu_stats
->nr_stmt_less_type_units
;
7211 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7212 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7213 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7214 &type_unit_group_for_lookup
, INSERT
);
7217 tu_group
= (struct type_unit_group
*) *slot
;
7218 gdb_assert (tu_group
!= NULL
);
7222 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7223 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7225 ++tu_stats
->nr_symtabs
;
7231 /* Partial symbol tables. */
7233 /* Create a psymtab named NAME and assign it to PER_CU.
7235 The caller must fill in the following details:
7236 dirname, textlow, texthigh. */
7238 static dwarf2_psymtab
*
7239 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7241 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7242 dwarf2_psymtab
*pst
;
7244 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7246 pst
->psymtabs_addrmap_supported
= true;
7248 /* This is the glue that links PST into GDB's symbol API. */
7249 pst
->per_cu_data
= per_cu
;
7250 per_cu
->v
.psymtab
= pst
;
7255 /* DIE reader function for process_psymtab_comp_unit. */
7258 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7259 const gdb_byte
*info_ptr
,
7260 struct die_info
*comp_unit_die
,
7261 enum language pretend_language
)
7263 struct dwarf2_cu
*cu
= reader
->cu
;
7264 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7265 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7266 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7268 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7269 dwarf2_psymtab
*pst
;
7270 enum pc_bounds_kind cu_bounds_kind
;
7271 const char *filename
;
7273 gdb_assert (! per_cu
->is_debug_types
);
7275 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7277 /* Allocate a new partial symbol table structure. */
7278 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7279 static const char artificial
[] = "<artificial>";
7280 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7281 if (filename
== NULL
)
7283 else if (strcmp (filename
, artificial
) == 0)
7285 debug_filename
.reset (concat (artificial
, "@",
7286 sect_offset_str (per_cu
->sect_off
),
7288 filename
= debug_filename
.get ();
7291 pst
= create_partial_symtab (per_cu
, filename
);
7293 /* This must be done before calling dwarf2_build_include_psymtabs. */
7294 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7296 baseaddr
= objfile
->text_section_offset ();
7298 dwarf2_find_base_address (comp_unit_die
, cu
);
7300 /* Possibly set the default values of LOWPC and HIGHPC from
7302 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7303 &best_highpc
, cu
, pst
);
7304 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7307 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7310 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7312 /* Store the contiguous range if it is not empty; it can be
7313 empty for CUs with no code. */
7314 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7318 /* Check if comp unit has_children.
7319 If so, read the rest of the partial symbols from this comp unit.
7320 If not, there's no more debug_info for this comp unit. */
7321 if (comp_unit_die
->has_children
)
7323 struct partial_die_info
*first_die
;
7324 CORE_ADDR lowpc
, highpc
;
7326 lowpc
= ((CORE_ADDR
) -1);
7327 highpc
= ((CORE_ADDR
) 0);
7329 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7331 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7332 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7334 /* If we didn't find a lowpc, set it to highpc to avoid
7335 complaints from `maint check'. */
7336 if (lowpc
== ((CORE_ADDR
) -1))
7339 /* If the compilation unit didn't have an explicit address range,
7340 then use the information extracted from its child dies. */
7341 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7344 best_highpc
= highpc
;
7347 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7348 best_lowpc
+ baseaddr
)
7350 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7351 best_highpc
+ baseaddr
)
7354 end_psymtab_common (objfile
, pst
);
7356 if (!cu
->per_cu
->imported_symtabs_empty ())
7359 int len
= cu
->per_cu
->imported_symtabs_size ();
7361 /* Fill in 'dependencies' here; we fill in 'users' in a
7363 pst
->number_of_dependencies
= len
;
7365 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7366 for (i
= 0; i
< len
; ++i
)
7368 pst
->dependencies
[i
]
7369 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7372 cu
->per_cu
->imported_symtabs_free ();
7375 /* Get the list of files included in the current compilation unit,
7376 and build a psymtab for each of them. */
7377 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7379 if (dwarf_read_debug
)
7380 fprintf_unfiltered (gdb_stdlog
,
7381 "Psymtab for %s unit @%s: %s - %s"
7382 ", %d global, %d static syms\n",
7383 per_cu
->is_debug_types
? "type" : "comp",
7384 sect_offset_str (per_cu
->sect_off
),
7385 paddress (gdbarch
, pst
->text_low (objfile
)),
7386 paddress (gdbarch
, pst
->text_high (objfile
)),
7387 pst
->n_global_syms
, pst
->n_static_syms
);
7390 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7391 Process compilation unit THIS_CU for a psymtab. */
7394 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7395 bool want_partial_unit
,
7396 enum language pretend_language
)
7398 /* If this compilation unit was already read in, free the
7399 cached copy in order to read it in again. This is
7400 necessary because we skipped some symbols when we first
7401 read in the compilation unit (see load_partial_dies).
7402 This problem could be avoided, but the benefit is unclear. */
7403 if (this_cu
->cu
!= NULL
)
7404 free_one_cached_comp_unit (this_cu
);
7406 cutu_reader
reader (this_cu
, NULL
, 0, false);
7408 switch (reader
.comp_unit_die
->tag
)
7410 case DW_TAG_compile_unit
:
7411 this_cu
->unit_type
= DW_UT_compile
;
7413 case DW_TAG_partial_unit
:
7414 this_cu
->unit_type
= DW_UT_partial
;
7424 else if (this_cu
->is_debug_types
)
7425 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7426 reader
.comp_unit_die
);
7427 else if (want_partial_unit
7428 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7429 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7430 reader
.comp_unit_die
,
7433 this_cu
->lang
= this_cu
->cu
->language
;
7435 /* Age out any secondary CUs. */
7436 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7439 /* Reader function for build_type_psymtabs. */
7442 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7443 const gdb_byte
*info_ptr
,
7444 struct die_info
*type_unit_die
)
7446 struct dwarf2_per_objfile
*dwarf2_per_objfile
7447 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7448 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7449 struct dwarf2_cu
*cu
= reader
->cu
;
7450 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7451 struct signatured_type
*sig_type
;
7452 struct type_unit_group
*tu_group
;
7453 struct attribute
*attr
;
7454 struct partial_die_info
*first_die
;
7455 CORE_ADDR lowpc
, highpc
;
7456 dwarf2_psymtab
*pst
;
7458 gdb_assert (per_cu
->is_debug_types
);
7459 sig_type
= (struct signatured_type
*) per_cu
;
7461 if (! type_unit_die
->has_children
)
7464 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7465 tu_group
= get_type_unit_group (cu
, attr
);
7467 if (tu_group
->tus
== nullptr)
7468 tu_group
->tus
= new std::vector
<signatured_type
*>;
7469 tu_group
->tus
->push_back (sig_type
);
7471 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7472 pst
= create_partial_symtab (per_cu
, "");
7473 pst
->anonymous
= true;
7475 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7477 lowpc
= (CORE_ADDR
) -1;
7478 highpc
= (CORE_ADDR
) 0;
7479 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7481 end_psymtab_common (objfile
, pst
);
7484 /* Struct used to sort TUs by their abbreviation table offset. */
7486 struct tu_abbrev_offset
7488 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7489 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7492 signatured_type
*sig_type
;
7493 sect_offset abbrev_offset
;
7496 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7499 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7500 const struct tu_abbrev_offset
&b
)
7502 return a
.abbrev_offset
< b
.abbrev_offset
;
7505 /* Efficiently read all the type units.
7506 This does the bulk of the work for build_type_psymtabs.
7508 The efficiency is because we sort TUs by the abbrev table they use and
7509 only read each abbrev table once. In one program there are 200K TUs
7510 sharing 8K abbrev tables.
7512 The main purpose of this function is to support building the
7513 dwarf2_per_objfile->type_unit_groups table.
7514 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7515 can collapse the search space by grouping them by stmt_list.
7516 The savings can be significant, in the same program from above the 200K TUs
7517 share 8K stmt_list tables.
7519 FUNC is expected to call get_type_unit_group, which will create the
7520 struct type_unit_group if necessary and add it to
7521 dwarf2_per_objfile->type_unit_groups. */
7524 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7526 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7527 abbrev_table_up abbrev_table
;
7528 sect_offset abbrev_offset
;
7530 /* It's up to the caller to not call us multiple times. */
7531 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7533 if (dwarf2_per_objfile
->all_type_units
.empty ())
7536 /* TUs typically share abbrev tables, and there can be way more TUs than
7537 abbrev tables. Sort by abbrev table to reduce the number of times we
7538 read each abbrev table in.
7539 Alternatives are to punt or to maintain a cache of abbrev tables.
7540 This is simpler and efficient enough for now.
7542 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7543 symtab to use). Typically TUs with the same abbrev offset have the same
7544 stmt_list value too so in practice this should work well.
7546 The basic algorithm here is:
7548 sort TUs by abbrev table
7549 for each TU with same abbrev table:
7550 read abbrev table if first user
7551 read TU top level DIE
7552 [IWBN if DWO skeletons had DW_AT_stmt_list]
7555 if (dwarf_read_debug
)
7556 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7558 /* Sort in a separate table to maintain the order of all_type_units
7559 for .gdb_index: TU indices directly index all_type_units. */
7560 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7561 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7563 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7564 sorted_by_abbrev
.emplace_back
7565 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7566 sig_type
->per_cu
.section
,
7567 sig_type
->per_cu
.sect_off
));
7569 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7570 sort_tu_by_abbrev_offset
);
7572 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7574 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7576 /* Switch to the next abbrev table if necessary. */
7577 if (abbrev_table
== NULL
7578 || tu
.abbrev_offset
!= abbrev_offset
)
7580 abbrev_offset
= tu
.abbrev_offset
;
7582 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7583 &dwarf2_per_objfile
->abbrev
,
7585 ++tu_stats
->nr_uniq_abbrev_tables
;
7588 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7590 if (!reader
.dummy_p
)
7591 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7592 reader
.comp_unit_die
);
7596 /* Print collected type unit statistics. */
7599 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7601 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7603 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7604 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7605 dwarf2_per_objfile
->all_type_units
.size ());
7606 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7607 tu_stats
->nr_uniq_abbrev_tables
);
7608 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7609 tu_stats
->nr_symtabs
);
7610 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7611 tu_stats
->nr_symtab_sharers
);
7612 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7613 tu_stats
->nr_stmt_less_type_units
);
7614 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7615 tu_stats
->nr_all_type_units_reallocs
);
7618 /* Traversal function for build_type_psymtabs. */
7621 build_type_psymtab_dependencies (void **slot
, void *info
)
7623 struct dwarf2_per_objfile
*dwarf2_per_objfile
7624 = (struct dwarf2_per_objfile
*) info
;
7625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7626 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7627 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7628 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7629 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7632 gdb_assert (len
> 0);
7633 gdb_assert (per_cu
->type_unit_group_p ());
7635 pst
->number_of_dependencies
= len
;
7636 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7637 for (i
= 0; i
< len
; ++i
)
7639 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7640 gdb_assert (iter
->per_cu
.is_debug_types
);
7641 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7642 iter
->type_unit_group
= tu_group
;
7645 delete tu_group
->tus
;
7646 tu_group
->tus
= nullptr;
7651 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7652 Build partial symbol tables for the .debug_types comp-units. */
7655 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7657 if (! create_all_type_units (dwarf2_per_objfile
))
7660 build_type_psymtabs_1 (dwarf2_per_objfile
);
7663 /* Traversal function for process_skeletonless_type_unit.
7664 Read a TU in a DWO file and build partial symbols for it. */
7667 process_skeletonless_type_unit (void **slot
, void *info
)
7669 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7670 struct dwarf2_per_objfile
*dwarf2_per_objfile
7671 = (struct dwarf2_per_objfile
*) info
;
7672 struct signatured_type find_entry
, *entry
;
7674 /* If this TU doesn't exist in the global table, add it and read it in. */
7676 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7677 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7679 find_entry
.signature
= dwo_unit
->signature
;
7680 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7681 &find_entry
, INSERT
);
7682 /* If we've already seen this type there's nothing to do. What's happening
7683 is we're doing our own version of comdat-folding here. */
7687 /* This does the job that create_all_type_units would have done for
7689 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7690 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7693 /* This does the job that build_type_psymtabs_1 would have done. */
7694 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7695 if (!reader
.dummy_p
)
7696 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7697 reader
.comp_unit_die
);
7702 /* Traversal function for process_skeletonless_type_units. */
7705 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7707 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7709 if (dwo_file
->tus
!= NULL
)
7710 htab_traverse_noresize (dwo_file
->tus
.get (),
7711 process_skeletonless_type_unit
, info
);
7716 /* Scan all TUs of DWO files, verifying we've processed them.
7717 This is needed in case a TU was emitted without its skeleton.
7718 Note: This can't be done until we know what all the DWO files are. */
7721 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7723 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7724 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7725 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7727 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7728 process_dwo_file_for_skeletonless_type_units
,
7729 dwarf2_per_objfile
);
7733 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7736 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7738 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7740 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7745 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7747 /* Set the 'user' field only if it is not already set. */
7748 if (pst
->dependencies
[j
]->user
== NULL
)
7749 pst
->dependencies
[j
]->user
= pst
;
7754 /* Build the partial symbol table by doing a quick pass through the
7755 .debug_info and .debug_abbrev sections. */
7758 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7760 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7762 if (dwarf_read_debug
)
7764 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7765 objfile_name (objfile
));
7768 scoped_restore restore_reading_psyms
7769 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7772 dwarf2_per_objfile
->info
.read (objfile
);
7774 /* Any cached compilation units will be linked by the per-objfile
7775 read_in_chain. Make sure to free them when we're done. */
7776 free_cached_comp_units
freer (dwarf2_per_objfile
);
7778 build_type_psymtabs (dwarf2_per_objfile
);
7780 create_all_comp_units (dwarf2_per_objfile
);
7782 /* Create a temporary address map on a temporary obstack. We later
7783 copy this to the final obstack. */
7784 auto_obstack temp_obstack
;
7786 scoped_restore save_psymtabs_addrmap
7787 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7788 addrmap_create_mutable (&temp_obstack
));
7790 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7791 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7793 /* This has to wait until we read the CUs, we need the list of DWOs. */
7794 process_skeletonless_type_units (dwarf2_per_objfile
);
7796 /* Now that all TUs have been processed we can fill in the dependencies. */
7797 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7799 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7800 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7803 if (dwarf_read_debug
)
7804 print_tu_stats (dwarf2_per_objfile
);
7806 set_partial_user (dwarf2_per_objfile
);
7808 objfile
->partial_symtabs
->psymtabs_addrmap
7809 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7810 objfile
->partial_symtabs
->obstack ());
7811 /* At this point we want to keep the address map. */
7812 save_psymtabs_addrmap
.release ();
7814 if (dwarf_read_debug
)
7815 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7816 objfile_name (objfile
));
7819 /* Load the partial DIEs for a secondary CU into memory.
7820 This is also used when rereading a primary CU with load_all_dies. */
7823 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7825 cutu_reader
reader (this_cu
, NULL
, 1, false);
7827 if (!reader
.dummy_p
)
7829 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7832 /* Check if comp unit has_children.
7833 If so, read the rest of the partial symbols from this comp unit.
7834 If not, there's no more debug_info for this comp unit. */
7835 if (reader
.comp_unit_die
->has_children
)
7836 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7843 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7844 struct dwarf2_section_info
*section
,
7845 struct dwarf2_section_info
*abbrev_section
,
7846 unsigned int is_dwz
)
7848 const gdb_byte
*info_ptr
;
7849 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7851 if (dwarf_read_debug
)
7852 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7853 section
->get_name (),
7854 section
->get_file_name ());
7856 section
->read (objfile
);
7858 info_ptr
= section
->buffer
;
7860 while (info_ptr
< section
->buffer
+ section
->size
)
7862 struct dwarf2_per_cu_data
*this_cu
;
7864 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7866 comp_unit_head cu_header
;
7867 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7868 abbrev_section
, info_ptr
,
7869 rcuh_kind::COMPILE
);
7871 /* Save the compilation unit for later lookup. */
7872 if (cu_header
.unit_type
!= DW_UT_type
)
7874 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7875 struct dwarf2_per_cu_data
);
7876 memset (this_cu
, 0, sizeof (*this_cu
));
7880 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7881 struct signatured_type
);
7882 memset (sig_type
, 0, sizeof (*sig_type
));
7883 sig_type
->signature
= cu_header
.signature
;
7884 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7885 this_cu
= &sig_type
->per_cu
;
7887 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7888 this_cu
->sect_off
= sect_off
;
7889 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7890 this_cu
->is_dwz
= is_dwz
;
7891 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7892 this_cu
->section
= section
;
7894 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7896 info_ptr
= info_ptr
+ this_cu
->length
;
7900 /* Create a list of all compilation units in OBJFILE.
7901 This is only done for -readnow and building partial symtabs. */
7904 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7906 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7907 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7908 &dwarf2_per_objfile
->abbrev
, 0);
7910 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7912 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7916 /* Process all loaded DIEs for compilation unit CU, starting at
7917 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7918 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7919 DW_AT_ranges). See the comments of add_partial_subprogram on how
7920 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7923 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7924 CORE_ADDR
*highpc
, int set_addrmap
,
7925 struct dwarf2_cu
*cu
)
7927 struct partial_die_info
*pdi
;
7929 /* Now, march along the PDI's, descending into ones which have
7930 interesting children but skipping the children of the other ones,
7931 until we reach the end of the compilation unit. */
7939 /* Anonymous namespaces or modules have no name but have interesting
7940 children, so we need to look at them. Ditto for anonymous
7943 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7944 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7945 || pdi
->tag
== DW_TAG_imported_unit
7946 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7950 case DW_TAG_subprogram
:
7951 case DW_TAG_inlined_subroutine
:
7952 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7954 case DW_TAG_constant
:
7955 case DW_TAG_variable
:
7956 case DW_TAG_typedef
:
7957 case DW_TAG_union_type
:
7958 if (!pdi
->is_declaration
)
7960 add_partial_symbol (pdi
, cu
);
7963 case DW_TAG_class_type
:
7964 case DW_TAG_interface_type
:
7965 case DW_TAG_structure_type
:
7966 if (!pdi
->is_declaration
)
7968 add_partial_symbol (pdi
, cu
);
7970 if ((cu
->language
== language_rust
7971 || cu
->language
== language_cplus
) && pdi
->has_children
)
7972 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7975 case DW_TAG_enumeration_type
:
7976 if (!pdi
->is_declaration
)
7977 add_partial_enumeration (pdi
, cu
);
7979 case DW_TAG_base_type
:
7980 case DW_TAG_subrange_type
:
7981 /* File scope base type definitions are added to the partial
7983 add_partial_symbol (pdi
, cu
);
7985 case DW_TAG_namespace
:
7986 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7989 if (!pdi
->is_declaration
)
7990 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7992 case DW_TAG_imported_unit
:
7994 struct dwarf2_per_cu_data
*per_cu
;
7996 /* For now we don't handle imported units in type units. */
7997 if (cu
->per_cu
->is_debug_types
)
7999 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8000 " supported in type units [in module %s]"),
8001 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8004 per_cu
= dwarf2_find_containing_comp_unit
8005 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8006 cu
->per_cu
->dwarf2_per_objfile
);
8008 /* Go read the partial unit, if needed. */
8009 if (per_cu
->v
.psymtab
== NULL
)
8010 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8012 cu
->per_cu
->imported_symtabs_push (per_cu
);
8015 case DW_TAG_imported_declaration
:
8016 add_partial_symbol (pdi
, cu
);
8023 /* If the die has a sibling, skip to the sibling. */
8025 pdi
= pdi
->die_sibling
;
8029 /* Functions used to compute the fully scoped name of a partial DIE.
8031 Normally, this is simple. For C++, the parent DIE's fully scoped
8032 name is concatenated with "::" and the partial DIE's name.
8033 Enumerators are an exception; they use the scope of their parent
8034 enumeration type, i.e. the name of the enumeration type is not
8035 prepended to the enumerator.
8037 There are two complexities. One is DW_AT_specification; in this
8038 case "parent" means the parent of the target of the specification,
8039 instead of the direct parent of the DIE. The other is compilers
8040 which do not emit DW_TAG_namespace; in this case we try to guess
8041 the fully qualified name of structure types from their members'
8042 linkage names. This must be done using the DIE's children rather
8043 than the children of any DW_AT_specification target. We only need
8044 to do this for structures at the top level, i.e. if the target of
8045 any DW_AT_specification (if any; otherwise the DIE itself) does not
8048 /* Compute the scope prefix associated with PDI's parent, in
8049 compilation unit CU. The result will be allocated on CU's
8050 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8051 field. NULL is returned if no prefix is necessary. */
8053 partial_die_parent_scope (struct partial_die_info
*pdi
,
8054 struct dwarf2_cu
*cu
)
8056 const char *grandparent_scope
;
8057 struct partial_die_info
*parent
, *real_pdi
;
8059 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8060 then this means the parent of the specification DIE. */
8063 while (real_pdi
->has_specification
)
8065 auto res
= find_partial_die (real_pdi
->spec_offset
,
8066 real_pdi
->spec_is_dwz
, cu
);
8071 parent
= real_pdi
->die_parent
;
8075 if (parent
->scope_set
)
8076 return parent
->scope
;
8080 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8082 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8083 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8084 Work around this problem here. */
8085 if (cu
->language
== language_cplus
8086 && parent
->tag
== DW_TAG_namespace
8087 && strcmp (parent
->name
, "::") == 0
8088 && grandparent_scope
== NULL
)
8090 parent
->scope
= NULL
;
8091 parent
->scope_set
= 1;
8095 /* Nested subroutines in Fortran get a prefix. */
8096 if (pdi
->tag
== DW_TAG_enumerator
)
8097 /* Enumerators should not get the name of the enumeration as a prefix. */
8098 parent
->scope
= grandparent_scope
;
8099 else if (parent
->tag
== DW_TAG_namespace
8100 || parent
->tag
== DW_TAG_module
8101 || parent
->tag
== DW_TAG_structure_type
8102 || parent
->tag
== DW_TAG_class_type
8103 || parent
->tag
== DW_TAG_interface_type
8104 || parent
->tag
== DW_TAG_union_type
8105 || parent
->tag
== DW_TAG_enumeration_type
8106 || (cu
->language
== language_fortran
8107 && parent
->tag
== DW_TAG_subprogram
8108 && pdi
->tag
== DW_TAG_subprogram
))
8110 if (grandparent_scope
== NULL
)
8111 parent
->scope
= parent
->name
;
8113 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8115 parent
->name
, 0, cu
);
8119 /* FIXME drow/2004-04-01: What should we be doing with
8120 function-local names? For partial symbols, we should probably be
8122 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8123 dwarf_tag_name (parent
->tag
),
8124 sect_offset_str (pdi
->sect_off
));
8125 parent
->scope
= grandparent_scope
;
8128 parent
->scope_set
= 1;
8129 return parent
->scope
;
8132 /* Return the fully scoped name associated with PDI, from compilation unit
8133 CU. The result will be allocated with malloc. */
8135 static gdb::unique_xmalloc_ptr
<char>
8136 partial_die_full_name (struct partial_die_info
*pdi
,
8137 struct dwarf2_cu
*cu
)
8139 const char *parent_scope
;
8141 /* If this is a template instantiation, we can not work out the
8142 template arguments from partial DIEs. So, unfortunately, we have
8143 to go through the full DIEs. At least any work we do building
8144 types here will be reused if full symbols are loaded later. */
8145 if (pdi
->has_template_arguments
)
8149 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8151 struct die_info
*die
;
8152 struct attribute attr
;
8153 struct dwarf2_cu
*ref_cu
= cu
;
8155 /* DW_FORM_ref_addr is using section offset. */
8156 attr
.name
= (enum dwarf_attribute
) 0;
8157 attr
.form
= DW_FORM_ref_addr
;
8158 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8159 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8161 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8165 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8166 if (parent_scope
== NULL
)
8169 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8174 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8176 struct dwarf2_per_objfile
*dwarf2_per_objfile
8177 = cu
->per_cu
->dwarf2_per_objfile
;
8178 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8179 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8181 const char *actual_name
= NULL
;
8184 baseaddr
= objfile
->text_section_offset ();
8186 gdb::unique_xmalloc_ptr
<char> built_actual_name
8187 = partial_die_full_name (pdi
, cu
);
8188 if (built_actual_name
!= NULL
)
8189 actual_name
= built_actual_name
.get ();
8191 if (actual_name
== NULL
)
8192 actual_name
= pdi
->name
;
8196 case DW_TAG_inlined_subroutine
:
8197 case DW_TAG_subprogram
:
8198 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8200 if (pdi
->is_external
8201 || cu
->language
== language_ada
8202 || (cu
->language
== language_fortran
8203 && pdi
->die_parent
!= NULL
8204 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8206 /* Normally, only "external" DIEs are part of the global scope.
8207 But in Ada and Fortran, we want to be able to access nested
8208 procedures globally. So all Ada and Fortran subprograms are
8209 stored in the global scope. */
8210 add_psymbol_to_list (actual_name
,
8211 built_actual_name
!= NULL
,
8212 VAR_DOMAIN
, LOC_BLOCK
,
8213 SECT_OFF_TEXT (objfile
),
8214 psymbol_placement::GLOBAL
,
8216 cu
->language
, objfile
);
8220 add_psymbol_to_list (actual_name
,
8221 built_actual_name
!= NULL
,
8222 VAR_DOMAIN
, LOC_BLOCK
,
8223 SECT_OFF_TEXT (objfile
),
8224 psymbol_placement::STATIC
,
8225 addr
, cu
->language
, objfile
);
8228 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8229 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8231 case DW_TAG_constant
:
8232 add_psymbol_to_list (actual_name
,
8233 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8234 -1, (pdi
->is_external
8235 ? psymbol_placement::GLOBAL
8236 : psymbol_placement::STATIC
),
8237 0, cu
->language
, objfile
);
8239 case DW_TAG_variable
:
8241 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8245 && !dwarf2_per_objfile
->has_section_at_zero
)
8247 /* A global or static variable may also have been stripped
8248 out by the linker if unused, in which case its address
8249 will be nullified; do not add such variables into partial
8250 symbol table then. */
8252 else if (pdi
->is_external
)
8255 Don't enter into the minimal symbol tables as there is
8256 a minimal symbol table entry from the ELF symbols already.
8257 Enter into partial symbol table if it has a location
8258 descriptor or a type.
8259 If the location descriptor is missing, new_symbol will create
8260 a LOC_UNRESOLVED symbol, the address of the variable will then
8261 be determined from the minimal symbol table whenever the variable
8263 The address for the partial symbol table entry is not
8264 used by GDB, but it comes in handy for debugging partial symbol
8267 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8268 add_psymbol_to_list (actual_name
,
8269 built_actual_name
!= NULL
,
8270 VAR_DOMAIN
, LOC_STATIC
,
8271 SECT_OFF_TEXT (objfile
),
8272 psymbol_placement::GLOBAL
,
8273 addr
, cu
->language
, objfile
);
8277 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8279 /* Static Variable. Skip symbols whose value we cannot know (those
8280 without location descriptors or constant values). */
8281 if (!has_loc
&& !pdi
->has_const_value
)
8284 add_psymbol_to_list (actual_name
,
8285 built_actual_name
!= NULL
,
8286 VAR_DOMAIN
, LOC_STATIC
,
8287 SECT_OFF_TEXT (objfile
),
8288 psymbol_placement::STATIC
,
8290 cu
->language
, objfile
);
8293 case DW_TAG_typedef
:
8294 case DW_TAG_base_type
:
8295 case DW_TAG_subrange_type
:
8296 add_psymbol_to_list (actual_name
,
8297 built_actual_name
!= NULL
,
8298 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8299 psymbol_placement::STATIC
,
8300 0, cu
->language
, objfile
);
8302 case DW_TAG_imported_declaration
:
8303 case DW_TAG_namespace
:
8304 add_psymbol_to_list (actual_name
,
8305 built_actual_name
!= NULL
,
8306 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8307 psymbol_placement::GLOBAL
,
8308 0, cu
->language
, objfile
);
8311 /* With Fortran 77 there might be a "BLOCK DATA" module
8312 available without any name. If so, we skip the module as it
8313 doesn't bring any value. */
8314 if (actual_name
!= nullptr)
8315 add_psymbol_to_list (actual_name
,
8316 built_actual_name
!= NULL
,
8317 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8318 psymbol_placement::GLOBAL
,
8319 0, cu
->language
, objfile
);
8321 case DW_TAG_class_type
:
8322 case DW_TAG_interface_type
:
8323 case DW_TAG_structure_type
:
8324 case DW_TAG_union_type
:
8325 case DW_TAG_enumeration_type
:
8326 /* Skip external references. The DWARF standard says in the section
8327 about "Structure, Union, and Class Type Entries": "An incomplete
8328 structure, union or class type is represented by a structure,
8329 union or class entry that does not have a byte size attribute
8330 and that has a DW_AT_declaration attribute." */
8331 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8334 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8335 static vs. global. */
8336 add_psymbol_to_list (actual_name
,
8337 built_actual_name
!= NULL
,
8338 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8339 cu
->language
== language_cplus
8340 ? psymbol_placement::GLOBAL
8341 : psymbol_placement::STATIC
,
8342 0, cu
->language
, objfile
);
8345 case DW_TAG_enumerator
:
8346 add_psymbol_to_list (actual_name
,
8347 built_actual_name
!= NULL
,
8348 VAR_DOMAIN
, LOC_CONST
, -1,
8349 cu
->language
== language_cplus
8350 ? psymbol_placement::GLOBAL
8351 : psymbol_placement::STATIC
,
8352 0, cu
->language
, objfile
);
8359 /* Read a partial die corresponding to a namespace; also, add a symbol
8360 corresponding to that namespace to the symbol table. NAMESPACE is
8361 the name of the enclosing namespace. */
8364 add_partial_namespace (struct partial_die_info
*pdi
,
8365 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8366 int set_addrmap
, struct dwarf2_cu
*cu
)
8368 /* Add a symbol for the namespace. */
8370 add_partial_symbol (pdi
, cu
);
8372 /* Now scan partial symbols in that namespace. */
8374 if (pdi
->has_children
)
8375 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8378 /* Read a partial die corresponding to a Fortran module. */
8381 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8382 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8384 /* Add a symbol for the namespace. */
8386 add_partial_symbol (pdi
, cu
);
8388 /* Now scan partial symbols in that module. */
8390 if (pdi
->has_children
)
8391 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8394 /* Read a partial die corresponding to a subprogram or an inlined
8395 subprogram and create a partial symbol for that subprogram.
8396 When the CU language allows it, this routine also defines a partial
8397 symbol for each nested subprogram that this subprogram contains.
8398 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8399 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8401 PDI may also be a lexical block, in which case we simply search
8402 recursively for subprograms defined inside that lexical block.
8403 Again, this is only performed when the CU language allows this
8404 type of definitions. */
8407 add_partial_subprogram (struct partial_die_info
*pdi
,
8408 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8409 int set_addrmap
, struct dwarf2_cu
*cu
)
8411 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8413 if (pdi
->has_pc_info
)
8415 if (pdi
->lowpc
< *lowpc
)
8416 *lowpc
= pdi
->lowpc
;
8417 if (pdi
->highpc
> *highpc
)
8418 *highpc
= pdi
->highpc
;
8421 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8422 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8424 CORE_ADDR this_highpc
;
8425 CORE_ADDR this_lowpc
;
8427 baseaddr
= objfile
->text_section_offset ();
8429 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8430 pdi
->lowpc
+ baseaddr
)
8433 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8434 pdi
->highpc
+ baseaddr
)
8436 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8437 this_lowpc
, this_highpc
- 1,
8438 cu
->per_cu
->v
.psymtab
);
8442 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8444 if (!pdi
->is_declaration
)
8445 /* Ignore subprogram DIEs that do not have a name, they are
8446 illegal. Do not emit a complaint at this point, we will
8447 do so when we convert this psymtab into a symtab. */
8449 add_partial_symbol (pdi
, cu
);
8453 if (! pdi
->has_children
)
8456 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8458 pdi
= pdi
->die_child
;
8462 if (pdi
->tag
== DW_TAG_subprogram
8463 || pdi
->tag
== DW_TAG_inlined_subroutine
8464 || pdi
->tag
== DW_TAG_lexical_block
)
8465 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8466 pdi
= pdi
->die_sibling
;
8471 /* Read a partial die corresponding to an enumeration type. */
8474 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8475 struct dwarf2_cu
*cu
)
8477 struct partial_die_info
*pdi
;
8479 if (enum_pdi
->name
!= NULL
)
8480 add_partial_symbol (enum_pdi
, cu
);
8482 pdi
= enum_pdi
->die_child
;
8485 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8486 complaint (_("malformed enumerator DIE ignored"));
8488 add_partial_symbol (pdi
, cu
);
8489 pdi
= pdi
->die_sibling
;
8493 /* Return the initial uleb128 in the die at INFO_PTR. */
8496 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8498 unsigned int bytes_read
;
8500 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8503 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8504 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8506 Return the corresponding abbrev, or NULL if the number is zero (indicating
8507 an empty DIE). In either case *BYTES_READ will be set to the length of
8508 the initial number. */
8510 static struct abbrev_info
*
8511 peek_die_abbrev (const die_reader_specs
&reader
,
8512 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8514 dwarf2_cu
*cu
= reader
.cu
;
8515 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8516 unsigned int abbrev_number
8517 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8519 if (abbrev_number
== 0)
8522 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8525 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8526 " at offset %s [in module %s]"),
8527 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8528 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8534 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8535 Returns a pointer to the end of a series of DIEs, terminated by an empty
8536 DIE. Any children of the skipped DIEs will also be skipped. */
8538 static const gdb_byte
*
8539 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8543 unsigned int bytes_read
;
8544 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8547 return info_ptr
+ bytes_read
;
8549 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8553 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8554 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8555 abbrev corresponding to that skipped uleb128 should be passed in
8556 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8559 static const gdb_byte
*
8560 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8561 struct abbrev_info
*abbrev
)
8563 unsigned int bytes_read
;
8564 struct attribute attr
;
8565 bfd
*abfd
= reader
->abfd
;
8566 struct dwarf2_cu
*cu
= reader
->cu
;
8567 const gdb_byte
*buffer
= reader
->buffer
;
8568 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8569 unsigned int form
, i
;
8571 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8573 /* The only abbrev we care about is DW_AT_sibling. */
8574 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8577 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8579 if (attr
.form
== DW_FORM_ref_addr
)
8580 complaint (_("ignoring absolute DW_AT_sibling"));
8583 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8584 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8586 if (sibling_ptr
< info_ptr
)
8587 complaint (_("DW_AT_sibling points backwards"));
8588 else if (sibling_ptr
> reader
->buffer_end
)
8589 reader
->die_section
->overflow_complaint ();
8595 /* If it isn't DW_AT_sibling, skip this attribute. */
8596 form
= abbrev
->attrs
[i
].form
;
8600 case DW_FORM_ref_addr
:
8601 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8602 and later it is offset sized. */
8603 if (cu
->header
.version
== 2)
8604 info_ptr
+= cu
->header
.addr_size
;
8606 info_ptr
+= cu
->header
.offset_size
;
8608 case DW_FORM_GNU_ref_alt
:
8609 info_ptr
+= cu
->header
.offset_size
;
8612 info_ptr
+= cu
->header
.addr_size
;
8620 case DW_FORM_flag_present
:
8621 case DW_FORM_implicit_const
:
8638 case DW_FORM_ref_sig8
:
8641 case DW_FORM_data16
:
8644 case DW_FORM_string
:
8645 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8646 info_ptr
+= bytes_read
;
8648 case DW_FORM_sec_offset
:
8650 case DW_FORM_GNU_strp_alt
:
8651 info_ptr
+= cu
->header
.offset_size
;
8653 case DW_FORM_exprloc
:
8655 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8656 info_ptr
+= bytes_read
;
8658 case DW_FORM_block1
:
8659 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8661 case DW_FORM_block2
:
8662 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8664 case DW_FORM_block4
:
8665 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8671 case DW_FORM_ref_udata
:
8672 case DW_FORM_GNU_addr_index
:
8673 case DW_FORM_GNU_str_index
:
8674 case DW_FORM_rnglistx
:
8675 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8677 case DW_FORM_indirect
:
8678 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8679 info_ptr
+= bytes_read
;
8680 /* We need to continue parsing from here, so just go back to
8682 goto skip_attribute
;
8685 error (_("Dwarf Error: Cannot handle %s "
8686 "in DWARF reader [in module %s]"),
8687 dwarf_form_name (form
),
8688 bfd_get_filename (abfd
));
8692 if (abbrev
->has_children
)
8693 return skip_children (reader
, info_ptr
);
8698 /* Locate ORIG_PDI's sibling.
8699 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8701 static const gdb_byte
*
8702 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8703 struct partial_die_info
*orig_pdi
,
8704 const gdb_byte
*info_ptr
)
8706 /* Do we know the sibling already? */
8708 if (orig_pdi
->sibling
)
8709 return orig_pdi
->sibling
;
8711 /* Are there any children to deal with? */
8713 if (!orig_pdi
->has_children
)
8716 /* Skip the children the long way. */
8718 return skip_children (reader
, info_ptr
);
8721 /* Expand this partial symbol table into a full symbol table. SELF is
8725 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8727 struct dwarf2_per_objfile
*dwarf2_per_objfile
8728 = get_dwarf2_per_objfile (objfile
);
8730 gdb_assert (!readin
);
8731 /* If this psymtab is constructed from a debug-only objfile, the
8732 has_section_at_zero flag will not necessarily be correct. We
8733 can get the correct value for this flag by looking at the data
8734 associated with the (presumably stripped) associated objfile. */
8735 if (objfile
->separate_debug_objfile_backlink
)
8737 struct dwarf2_per_objfile
*dpo_backlink
8738 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8740 dwarf2_per_objfile
->has_section_at_zero
8741 = dpo_backlink
->has_section_at_zero
;
8744 expand_psymtab (objfile
);
8746 process_cu_includes (dwarf2_per_objfile
);
8749 /* Reading in full CUs. */
8751 /* Add PER_CU to the queue. */
8754 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8755 enum language pretend_language
)
8758 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8761 /* If PER_CU is not yet queued, add it to the queue.
8762 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8764 The result is non-zero if PER_CU was queued, otherwise the result is zero
8765 meaning either PER_CU is already queued or it is already loaded.
8767 N.B. There is an invariant here that if a CU is queued then it is loaded.
8768 The caller is required to load PER_CU if we return non-zero. */
8771 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8772 struct dwarf2_per_cu_data
*per_cu
,
8773 enum language pretend_language
)
8775 /* We may arrive here during partial symbol reading, if we need full
8776 DIEs to process an unusual case (e.g. template arguments). Do
8777 not queue PER_CU, just tell our caller to load its DIEs. */
8778 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8780 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8785 /* Mark the dependence relation so that we don't flush PER_CU
8787 if (dependent_cu
!= NULL
)
8788 dwarf2_add_dependence (dependent_cu
, per_cu
);
8790 /* If it's already on the queue, we have nothing to do. */
8794 /* If the compilation unit is already loaded, just mark it as
8796 if (per_cu
->cu
!= NULL
)
8798 per_cu
->cu
->last_used
= 0;
8802 /* Add it to the queue. */
8803 queue_comp_unit (per_cu
, pretend_language
);
8808 /* Process the queue. */
8811 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8813 if (dwarf_read_debug
)
8815 fprintf_unfiltered (gdb_stdlog
,
8816 "Expanding one or more symtabs of objfile %s ...\n",
8817 objfile_name (dwarf2_per_objfile
->objfile
));
8820 /* The queue starts out with one item, but following a DIE reference
8821 may load a new CU, adding it to the end of the queue. */
8822 while (!dwarf2_per_objfile
->queue
.empty ())
8824 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8826 if ((dwarf2_per_objfile
->using_index
8827 ? !item
.per_cu
->v
.quick
->compunit_symtab
8828 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8829 /* Skip dummy CUs. */
8830 && item
.per_cu
->cu
!= NULL
)
8832 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8833 unsigned int debug_print_threshold
;
8836 if (per_cu
->is_debug_types
)
8838 struct signatured_type
*sig_type
=
8839 (struct signatured_type
*) per_cu
;
8841 sprintf (buf
, "TU %s at offset %s",
8842 hex_string (sig_type
->signature
),
8843 sect_offset_str (per_cu
->sect_off
));
8844 /* There can be 100s of TUs.
8845 Only print them in verbose mode. */
8846 debug_print_threshold
= 2;
8850 sprintf (buf
, "CU at offset %s",
8851 sect_offset_str (per_cu
->sect_off
));
8852 debug_print_threshold
= 1;
8855 if (dwarf_read_debug
>= debug_print_threshold
)
8856 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8858 if (per_cu
->is_debug_types
)
8859 process_full_type_unit (per_cu
, item
.pretend_language
);
8861 process_full_comp_unit (per_cu
, item
.pretend_language
);
8863 if (dwarf_read_debug
>= debug_print_threshold
)
8864 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8867 item
.per_cu
->queued
= 0;
8868 dwarf2_per_objfile
->queue
.pop ();
8871 if (dwarf_read_debug
)
8873 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8874 objfile_name (dwarf2_per_objfile
->objfile
));
8878 /* Read in full symbols for PST, and anything it depends on. */
8881 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8886 read_dependencies (objfile
);
8888 dw2_do_instantiate_symtab (per_cu_data
, false);
8889 gdb_assert (get_compunit_symtab () != nullptr);
8892 /* Trivial hash function for die_info: the hash value of a DIE
8893 is its offset in .debug_info for this objfile. */
8896 die_hash (const void *item
)
8898 const struct die_info
*die
= (const struct die_info
*) item
;
8900 return to_underlying (die
->sect_off
);
8903 /* Trivial comparison function for die_info structures: two DIEs
8904 are equal if they have the same offset. */
8907 die_eq (const void *item_lhs
, const void *item_rhs
)
8909 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8910 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8912 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8915 /* Load the DIEs associated with PER_CU into memory. */
8918 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8920 enum language pretend_language
)
8922 gdb_assert (! this_cu
->is_debug_types
);
8924 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8928 struct dwarf2_cu
*cu
= reader
.cu
;
8929 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8931 gdb_assert (cu
->die_hash
== NULL
);
8933 htab_create_alloc_ex (cu
->header
.length
/ 12,
8937 &cu
->comp_unit_obstack
,
8938 hashtab_obstack_allocate
,
8939 dummy_obstack_deallocate
);
8941 if (reader
.comp_unit_die
->has_children
)
8942 reader
.comp_unit_die
->child
8943 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8944 &info_ptr
, reader
.comp_unit_die
);
8945 cu
->dies
= reader
.comp_unit_die
;
8946 /* comp_unit_die is not stored in die_hash, no need. */
8948 /* We try not to read any attributes in this function, because not
8949 all CUs needed for references have been loaded yet, and symbol
8950 table processing isn't initialized. But we have to set the CU language,
8951 or we won't be able to build types correctly.
8952 Similarly, if we do not read the producer, we can not apply
8953 producer-specific interpretation. */
8954 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8959 /* Add a DIE to the delayed physname list. */
8962 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8963 const char *name
, struct die_info
*die
,
8964 struct dwarf2_cu
*cu
)
8966 struct delayed_method_info mi
;
8968 mi
.fnfield_index
= fnfield_index
;
8972 cu
->method_list
.push_back (mi
);
8975 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8976 "const" / "volatile". If so, decrements LEN by the length of the
8977 modifier and return true. Otherwise return false. */
8981 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8983 size_t mod_len
= sizeof (mod
) - 1;
8984 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8992 /* Compute the physnames of any methods on the CU's method list.
8994 The computation of method physnames is delayed in order to avoid the
8995 (bad) condition that one of the method's formal parameters is of an as yet
8999 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9001 /* Only C++ delays computing physnames. */
9002 if (cu
->method_list
.empty ())
9004 gdb_assert (cu
->language
== language_cplus
);
9006 for (const delayed_method_info
&mi
: cu
->method_list
)
9008 const char *physname
;
9009 struct fn_fieldlist
*fn_flp
9010 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9011 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9012 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9013 = physname
? physname
: "";
9015 /* Since there's no tag to indicate whether a method is a
9016 const/volatile overload, extract that information out of the
9018 if (physname
!= NULL
)
9020 size_t len
= strlen (physname
);
9024 if (physname
[len
] == ')') /* shortcut */
9026 else if (check_modifier (physname
, len
, " const"))
9027 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9028 else if (check_modifier (physname
, len
, " volatile"))
9029 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9036 /* The list is no longer needed. */
9037 cu
->method_list
.clear ();
9040 /* Go objects should be embedded in a DW_TAG_module DIE,
9041 and it's not clear if/how imported objects will appear.
9042 To keep Go support simple until that's worked out,
9043 go back through what we've read and create something usable.
9044 We could do this while processing each DIE, and feels kinda cleaner,
9045 but that way is more invasive.
9046 This is to, for example, allow the user to type "p var" or "b main"
9047 without having to specify the package name, and allow lookups
9048 of module.object to work in contexts that use the expression
9052 fixup_go_packaging (struct dwarf2_cu
*cu
)
9054 gdb::unique_xmalloc_ptr
<char> package_name
;
9055 struct pending
*list
;
9058 for (list
= *cu
->get_builder ()->get_global_symbols ();
9062 for (i
= 0; i
< list
->nsyms
; ++i
)
9064 struct symbol
*sym
= list
->symbol
[i
];
9066 if (sym
->language () == language_go
9067 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9069 gdb::unique_xmalloc_ptr
<char> this_package_name
9070 (go_symbol_package_name (sym
));
9072 if (this_package_name
== NULL
)
9074 if (package_name
== NULL
)
9075 package_name
= std::move (this_package_name
);
9078 struct objfile
*objfile
9079 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9080 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9081 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9082 (symbol_symtab (sym
) != NULL
9083 ? symtab_to_filename_for_display
9084 (symbol_symtab (sym
))
9085 : objfile_name (objfile
)),
9086 this_package_name
.get (), package_name
.get ());
9092 if (package_name
!= NULL
)
9094 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9095 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9096 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9097 saved_package_name
);
9100 sym
= allocate_symbol (objfile
);
9101 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9102 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9103 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9104 e.g., "main" finds the "main" module and not C's main(). */
9105 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9106 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9107 SYMBOL_TYPE (sym
) = type
;
9109 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9113 /* Allocate a fully-qualified name consisting of the two parts on the
9117 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9119 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9122 /* A helper that allocates a struct discriminant_info to attach to a
9125 static struct discriminant_info
*
9126 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9129 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9130 gdb_assert (discriminant_index
== -1
9131 || (discriminant_index
>= 0
9132 && discriminant_index
< TYPE_NFIELDS (type
)));
9133 gdb_assert (default_index
== -1
9134 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9136 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9138 struct discriminant_info
*disc
9139 = ((struct discriminant_info
*)
9141 offsetof (struct discriminant_info
, discriminants
)
9142 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9143 disc
->default_index
= default_index
;
9144 disc
->discriminant_index
= discriminant_index
;
9146 struct dynamic_prop prop
;
9147 prop
.kind
= PROP_UNDEFINED
;
9148 prop
.data
.baton
= disc
;
9150 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9155 /* Some versions of rustc emitted enums in an unusual way.
9157 Ordinary enums were emitted as unions. The first element of each
9158 structure in the union was named "RUST$ENUM$DISR". This element
9159 held the discriminant.
9161 These versions of Rust also implemented the "non-zero"
9162 optimization. When the enum had two values, and one is empty and
9163 the other holds a pointer that cannot be zero, the pointer is used
9164 as the discriminant, with a zero value meaning the empty variant.
9165 Here, the union's first member is of the form
9166 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9167 where the fieldnos are the indices of the fields that should be
9168 traversed in order to find the field (which may be several fields deep)
9169 and the variantname is the name of the variant of the case when the
9172 This function recognizes whether TYPE is of one of these forms,
9173 and, if so, smashes it to be a variant type. */
9176 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9178 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9180 /* We don't need to deal with empty enums. */
9181 if (TYPE_NFIELDS (type
) == 0)
9184 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9185 if (TYPE_NFIELDS (type
) == 1
9186 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9188 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9190 /* Decode the field name to find the offset of the
9192 ULONGEST bit_offset
= 0;
9193 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9194 while (name
[0] >= '0' && name
[0] <= '9')
9197 unsigned long index
= strtoul (name
, &tail
, 10);
9200 || index
>= TYPE_NFIELDS (field_type
)
9201 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9202 != FIELD_LOC_KIND_BITPOS
))
9204 complaint (_("Could not parse Rust enum encoding string \"%s\""
9206 TYPE_FIELD_NAME (type
, 0),
9207 objfile_name (objfile
));
9212 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9213 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9216 /* Make a union to hold the variants. */
9217 struct type
*union_type
= alloc_type (objfile
);
9218 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9219 TYPE_NFIELDS (union_type
) = 3;
9220 TYPE_FIELDS (union_type
)
9221 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9222 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9223 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9225 /* Put the discriminant must at index 0. */
9226 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9227 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9228 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9229 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9231 /* The order of fields doesn't really matter, so put the real
9232 field at index 1 and the data-less field at index 2. */
9233 struct discriminant_info
*disc
9234 = alloc_discriminant_info (union_type
, 0, 1);
9235 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9236 TYPE_FIELD_NAME (union_type
, 1)
9237 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9238 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9239 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9240 TYPE_FIELD_NAME (union_type
, 1));
9242 const char *dataless_name
9243 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9245 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9247 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9248 /* NAME points into the original discriminant name, which
9249 already has the correct lifetime. */
9250 TYPE_FIELD_NAME (union_type
, 2) = name
;
9251 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9252 disc
->discriminants
[2] = 0;
9254 /* Smash this type to be a structure type. We have to do this
9255 because the type has already been recorded. */
9256 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9257 TYPE_NFIELDS (type
) = 1;
9259 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9261 /* Install the variant part. */
9262 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9263 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9264 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9266 /* A union with a single anonymous field is probably an old-style
9268 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9270 /* Smash this type to be a structure type. We have to do this
9271 because the type has already been recorded. */
9272 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9274 /* Make a union to hold the variants. */
9275 struct type
*union_type
= alloc_type (objfile
);
9276 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9277 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9278 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9279 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9280 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9282 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9283 const char *variant_name
9284 = rust_last_path_segment (TYPE_NAME (field_type
));
9285 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9286 TYPE_NAME (field_type
)
9287 = rust_fully_qualify (&objfile
->objfile_obstack
,
9288 TYPE_NAME (type
), variant_name
);
9290 /* Install the union in the outer struct type. */
9291 TYPE_NFIELDS (type
) = 1;
9293 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9294 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9295 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9296 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9298 alloc_discriminant_info (union_type
, -1, 0);
9302 struct type
*disr_type
= nullptr;
9303 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9305 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9307 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9309 /* All fields of a true enum will be structs. */
9312 else if (TYPE_NFIELDS (disr_type
) == 0)
9314 /* Could be data-less variant, so keep going. */
9315 disr_type
= nullptr;
9317 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9318 "RUST$ENUM$DISR") != 0)
9320 /* Not a Rust enum. */
9330 /* If we got here without a discriminant, then it's probably
9332 if (disr_type
== nullptr)
9335 /* Smash this type to be a structure type. We have to do this
9336 because the type has already been recorded. */
9337 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9339 /* Make a union to hold the variants. */
9340 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9341 struct type
*union_type
= alloc_type (objfile
);
9342 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9343 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9344 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9345 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9346 TYPE_FIELDS (union_type
)
9347 = (struct field
*) TYPE_ZALLOC (union_type
,
9348 (TYPE_NFIELDS (union_type
)
9349 * sizeof (struct field
)));
9351 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9352 TYPE_NFIELDS (type
) * sizeof (struct field
));
9354 /* Install the discriminant at index 0 in the union. */
9355 TYPE_FIELD (union_type
, 0) = *disr_field
;
9356 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9357 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9359 /* Install the union in the outer struct type. */
9360 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9361 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9362 TYPE_NFIELDS (type
) = 1;
9364 /* Set the size and offset of the union type. */
9365 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9367 /* We need a way to find the correct discriminant given a
9368 variant name. For convenience we build a map here. */
9369 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9370 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9371 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9373 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9376 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9377 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9381 int n_fields
= TYPE_NFIELDS (union_type
);
9382 struct discriminant_info
*disc
9383 = alloc_discriminant_info (union_type
, 0, -1);
9384 /* Skip the discriminant here. */
9385 for (int i
= 1; i
< n_fields
; ++i
)
9387 /* Find the final word in the name of this variant's type.
9388 That name can be used to look up the correct
9390 const char *variant_name
9391 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9394 auto iter
= discriminant_map
.find (variant_name
);
9395 if (iter
!= discriminant_map
.end ())
9396 disc
->discriminants
[i
] = iter
->second
;
9398 /* Remove the discriminant field, if it exists. */
9399 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9400 if (TYPE_NFIELDS (sub_type
) > 0)
9402 --TYPE_NFIELDS (sub_type
);
9403 ++TYPE_FIELDS (sub_type
);
9405 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9406 TYPE_NAME (sub_type
)
9407 = rust_fully_qualify (&objfile
->objfile_obstack
,
9408 TYPE_NAME (type
), variant_name
);
9413 /* Rewrite some Rust unions to be structures with variants parts. */
9416 rust_union_quirks (struct dwarf2_cu
*cu
)
9418 gdb_assert (cu
->language
== language_rust
);
9419 for (type
*type_
: cu
->rust_unions
)
9420 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9421 /* We don't need this any more. */
9422 cu
->rust_unions
.clear ();
9425 /* Return the symtab for PER_CU. This works properly regardless of
9426 whether we're using the index or psymtabs. */
9428 static struct compunit_symtab
*
9429 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9431 return (per_cu
->dwarf2_per_objfile
->using_index
9432 ? per_cu
->v
.quick
->compunit_symtab
9433 : per_cu
->v
.psymtab
->compunit_symtab
);
9436 /* A helper function for computing the list of all symbol tables
9437 included by PER_CU. */
9440 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9441 htab_t all_children
, htab_t all_type_symtabs
,
9442 struct dwarf2_per_cu_data
*per_cu
,
9443 struct compunit_symtab
*immediate_parent
)
9446 struct compunit_symtab
*cust
;
9448 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9451 /* This inclusion and its children have been processed. */
9456 /* Only add a CU if it has a symbol table. */
9457 cust
= get_compunit_symtab (per_cu
);
9460 /* If this is a type unit only add its symbol table if we haven't
9461 seen it yet (type unit per_cu's can share symtabs). */
9462 if (per_cu
->is_debug_types
)
9464 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9468 result
->push_back (cust
);
9469 if (cust
->user
== NULL
)
9470 cust
->user
= immediate_parent
;
9475 result
->push_back (cust
);
9476 if (cust
->user
== NULL
)
9477 cust
->user
= immediate_parent
;
9481 if (!per_cu
->imported_symtabs_empty ())
9482 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9484 recursively_compute_inclusions (result
, all_children
,
9485 all_type_symtabs
, ptr
, cust
);
9489 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9493 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9495 gdb_assert (! per_cu
->is_debug_types
);
9497 if (!per_cu
->imported_symtabs_empty ())
9500 std::vector
<compunit_symtab
*> result_symtabs
;
9501 htab_t all_children
, all_type_symtabs
;
9502 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9504 /* If we don't have a symtab, we can just skip this case. */
9508 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9509 NULL
, xcalloc
, xfree
);
9510 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9511 NULL
, xcalloc
, xfree
);
9513 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9515 recursively_compute_inclusions (&result_symtabs
, all_children
,
9516 all_type_symtabs
, ptr
, cust
);
9519 /* Now we have a transitive closure of all the included symtabs. */
9520 len
= result_symtabs
.size ();
9522 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9523 struct compunit_symtab
*, len
+ 1);
9524 memcpy (cust
->includes
, result_symtabs
.data (),
9525 len
* sizeof (compunit_symtab
*));
9526 cust
->includes
[len
] = NULL
;
9528 htab_delete (all_children
);
9529 htab_delete (all_type_symtabs
);
9533 /* Compute the 'includes' field for the symtabs of all the CUs we just
9537 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9539 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9541 if (! iter
->is_debug_types
)
9542 compute_compunit_symtab_includes (iter
);
9545 dwarf2_per_objfile
->just_read_cus
.clear ();
9548 /* Generate full symbol information for PER_CU, whose DIEs have
9549 already been loaded into memory. */
9552 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9553 enum language pretend_language
)
9555 struct dwarf2_cu
*cu
= per_cu
->cu
;
9556 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9557 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9558 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9559 CORE_ADDR lowpc
, highpc
;
9560 struct compunit_symtab
*cust
;
9562 struct block
*static_block
;
9565 baseaddr
= objfile
->text_section_offset ();
9567 /* Clear the list here in case something was left over. */
9568 cu
->method_list
.clear ();
9570 cu
->language
= pretend_language
;
9571 cu
->language_defn
= language_def (cu
->language
);
9573 /* Do line number decoding in read_file_scope () */
9574 process_die (cu
->dies
, cu
);
9576 /* For now fudge the Go package. */
9577 if (cu
->language
== language_go
)
9578 fixup_go_packaging (cu
);
9580 /* Now that we have processed all the DIEs in the CU, all the types
9581 should be complete, and it should now be safe to compute all of the
9583 compute_delayed_physnames (cu
);
9585 if (cu
->language
== language_rust
)
9586 rust_union_quirks (cu
);
9588 /* Some compilers don't define a DW_AT_high_pc attribute for the
9589 compilation unit. If the DW_AT_high_pc is missing, synthesize
9590 it, by scanning the DIE's below the compilation unit. */
9591 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9593 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9594 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9596 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9597 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9598 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9599 addrmap to help ensure it has an accurate map of pc values belonging to
9601 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9603 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9604 SECT_OFF_TEXT (objfile
),
9609 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9611 /* Set symtab language to language from DW_AT_language. If the
9612 compilation is from a C file generated by language preprocessors, do
9613 not set the language if it was already deduced by start_subfile. */
9614 if (!(cu
->language
== language_c
9615 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9616 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9618 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9619 produce DW_AT_location with location lists but it can be possibly
9620 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9621 there were bugs in prologue debug info, fixed later in GCC-4.5
9622 by "unwind info for epilogues" patch (which is not directly related).
9624 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9625 needed, it would be wrong due to missing DW_AT_producer there.
9627 Still one can confuse GDB by using non-standard GCC compilation
9628 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9630 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9631 cust
->locations_valid
= 1;
9633 if (gcc_4_minor
>= 5)
9634 cust
->epilogue_unwind_valid
= 1;
9636 cust
->call_site_htab
= cu
->call_site_htab
;
9639 if (dwarf2_per_objfile
->using_index
)
9640 per_cu
->v
.quick
->compunit_symtab
= cust
;
9643 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9644 pst
->compunit_symtab
= cust
;
9648 /* Push it for inclusion processing later. */
9649 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9651 /* Not needed any more. */
9652 cu
->reset_builder ();
9655 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9656 already been loaded into memory. */
9659 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9660 enum language pretend_language
)
9662 struct dwarf2_cu
*cu
= per_cu
->cu
;
9663 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9664 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9665 struct compunit_symtab
*cust
;
9666 struct signatured_type
*sig_type
;
9668 gdb_assert (per_cu
->is_debug_types
);
9669 sig_type
= (struct signatured_type
*) per_cu
;
9671 /* Clear the list here in case something was left over. */
9672 cu
->method_list
.clear ();
9674 cu
->language
= pretend_language
;
9675 cu
->language_defn
= language_def (cu
->language
);
9677 /* The symbol tables are set up in read_type_unit_scope. */
9678 process_die (cu
->dies
, cu
);
9680 /* For now fudge the Go package. */
9681 if (cu
->language
== language_go
)
9682 fixup_go_packaging (cu
);
9684 /* Now that we have processed all the DIEs in the CU, all the types
9685 should be complete, and it should now be safe to compute all of the
9687 compute_delayed_physnames (cu
);
9689 if (cu
->language
== language_rust
)
9690 rust_union_quirks (cu
);
9692 /* TUs share symbol tables.
9693 If this is the first TU to use this symtab, complete the construction
9694 of it with end_expandable_symtab. Otherwise, complete the addition of
9695 this TU's symbols to the existing symtab. */
9696 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9698 buildsym_compunit
*builder
= cu
->get_builder ();
9699 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9700 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9704 /* Set symtab language to language from DW_AT_language. If the
9705 compilation is from a C file generated by language preprocessors,
9706 do not set the language if it was already deduced by
9708 if (!(cu
->language
== language_c
9709 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9710 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9715 cu
->get_builder ()->augment_type_symtab ();
9716 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9719 if (dwarf2_per_objfile
->using_index
)
9720 per_cu
->v
.quick
->compunit_symtab
= cust
;
9723 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9724 pst
->compunit_symtab
= cust
;
9728 /* Not needed any more. */
9729 cu
->reset_builder ();
9732 /* Process an imported unit DIE. */
9735 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9737 struct attribute
*attr
;
9739 /* For now we don't handle imported units in type units. */
9740 if (cu
->per_cu
->is_debug_types
)
9742 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9743 " supported in type units [in module %s]"),
9744 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9747 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9750 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9751 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9752 dwarf2_per_cu_data
*per_cu
9753 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9754 cu
->per_cu
->dwarf2_per_objfile
);
9756 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9757 into another compilation unit, at root level. Regard this as a hint,
9759 if (die
->parent
&& die
->parent
->parent
== NULL
9760 && per_cu
->unit_type
== DW_UT_compile
9761 && per_cu
->lang
== language_cplus
)
9764 /* If necessary, add it to the queue and load its DIEs. */
9765 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9766 load_full_comp_unit (per_cu
, false, cu
->language
);
9768 cu
->per_cu
->imported_symtabs_push (per_cu
);
9772 /* RAII object that represents a process_die scope: i.e.,
9773 starts/finishes processing a DIE. */
9774 class process_die_scope
9777 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9778 : m_die (die
), m_cu (cu
)
9780 /* We should only be processing DIEs not already in process. */
9781 gdb_assert (!m_die
->in_process
);
9782 m_die
->in_process
= true;
9785 ~process_die_scope ()
9787 m_die
->in_process
= false;
9789 /* If we're done processing the DIE for the CU that owns the line
9790 header, we don't need the line header anymore. */
9791 if (m_cu
->line_header_die_owner
== m_die
)
9793 delete m_cu
->line_header
;
9794 m_cu
->line_header
= NULL
;
9795 m_cu
->line_header_die_owner
= NULL
;
9804 /* Process a die and its children. */
9807 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9809 process_die_scope
scope (die
, cu
);
9813 case DW_TAG_padding
:
9815 case DW_TAG_compile_unit
:
9816 case DW_TAG_partial_unit
:
9817 read_file_scope (die
, cu
);
9819 case DW_TAG_type_unit
:
9820 read_type_unit_scope (die
, cu
);
9822 case DW_TAG_subprogram
:
9823 /* Nested subprograms in Fortran get a prefix. */
9824 if (cu
->language
== language_fortran
9825 && die
->parent
!= NULL
9826 && die
->parent
->tag
== DW_TAG_subprogram
)
9827 cu
->processing_has_namespace_info
= true;
9829 case DW_TAG_inlined_subroutine
:
9830 read_func_scope (die
, cu
);
9832 case DW_TAG_lexical_block
:
9833 case DW_TAG_try_block
:
9834 case DW_TAG_catch_block
:
9835 read_lexical_block_scope (die
, cu
);
9837 case DW_TAG_call_site
:
9838 case DW_TAG_GNU_call_site
:
9839 read_call_site_scope (die
, cu
);
9841 case DW_TAG_class_type
:
9842 case DW_TAG_interface_type
:
9843 case DW_TAG_structure_type
:
9844 case DW_TAG_union_type
:
9845 process_structure_scope (die
, cu
);
9847 case DW_TAG_enumeration_type
:
9848 process_enumeration_scope (die
, cu
);
9851 /* These dies have a type, but processing them does not create
9852 a symbol or recurse to process the children. Therefore we can
9853 read them on-demand through read_type_die. */
9854 case DW_TAG_subroutine_type
:
9855 case DW_TAG_set_type
:
9856 case DW_TAG_array_type
:
9857 case DW_TAG_pointer_type
:
9858 case DW_TAG_ptr_to_member_type
:
9859 case DW_TAG_reference_type
:
9860 case DW_TAG_rvalue_reference_type
:
9861 case DW_TAG_string_type
:
9864 case DW_TAG_base_type
:
9865 case DW_TAG_subrange_type
:
9866 case DW_TAG_typedef
:
9867 /* Add a typedef symbol for the type definition, if it has a
9869 new_symbol (die
, read_type_die (die
, cu
), cu
);
9871 case DW_TAG_common_block
:
9872 read_common_block (die
, cu
);
9874 case DW_TAG_common_inclusion
:
9876 case DW_TAG_namespace
:
9877 cu
->processing_has_namespace_info
= true;
9878 read_namespace (die
, cu
);
9881 cu
->processing_has_namespace_info
= true;
9882 read_module (die
, cu
);
9884 case DW_TAG_imported_declaration
:
9885 cu
->processing_has_namespace_info
= true;
9886 if (read_namespace_alias (die
, cu
))
9888 /* The declaration is not a global namespace alias. */
9890 case DW_TAG_imported_module
:
9891 cu
->processing_has_namespace_info
= true;
9892 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9893 || cu
->language
!= language_fortran
))
9894 complaint (_("Tag '%s' has unexpected children"),
9895 dwarf_tag_name (die
->tag
));
9896 read_import_statement (die
, cu
);
9899 case DW_TAG_imported_unit
:
9900 process_imported_unit_die (die
, cu
);
9903 case DW_TAG_variable
:
9904 read_variable (die
, cu
);
9908 new_symbol (die
, NULL
, cu
);
9913 /* DWARF name computation. */
9915 /* A helper function for dwarf2_compute_name which determines whether DIE
9916 needs to have the name of the scope prepended to the name listed in the
9920 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9922 struct attribute
*attr
;
9926 case DW_TAG_namespace
:
9927 case DW_TAG_typedef
:
9928 case DW_TAG_class_type
:
9929 case DW_TAG_interface_type
:
9930 case DW_TAG_structure_type
:
9931 case DW_TAG_union_type
:
9932 case DW_TAG_enumeration_type
:
9933 case DW_TAG_enumerator
:
9934 case DW_TAG_subprogram
:
9935 case DW_TAG_inlined_subroutine
:
9937 case DW_TAG_imported_declaration
:
9940 case DW_TAG_variable
:
9941 case DW_TAG_constant
:
9942 /* We only need to prefix "globally" visible variables. These include
9943 any variable marked with DW_AT_external or any variable that
9944 lives in a namespace. [Variables in anonymous namespaces
9945 require prefixing, but they are not DW_AT_external.] */
9947 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9949 struct dwarf2_cu
*spec_cu
= cu
;
9951 return die_needs_namespace (die_specification (die
, &spec_cu
),
9955 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9956 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9957 && die
->parent
->tag
!= DW_TAG_module
)
9959 /* A variable in a lexical block of some kind does not need a
9960 namespace, even though in C++ such variables may be external
9961 and have a mangled name. */
9962 if (die
->parent
->tag
== DW_TAG_lexical_block
9963 || die
->parent
->tag
== DW_TAG_try_block
9964 || die
->parent
->tag
== DW_TAG_catch_block
9965 || die
->parent
->tag
== DW_TAG_subprogram
)
9974 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9975 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9976 defined for the given DIE. */
9978 static struct attribute
*
9979 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9981 struct attribute
*attr
;
9983 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9985 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9990 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9991 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9992 defined for the given DIE. */
9995 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9997 const char *linkage_name
;
9999 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10000 if (linkage_name
== NULL
)
10001 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10003 return linkage_name
;
10006 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10007 compute the physname for the object, which include a method's:
10008 - formal parameters (C++),
10009 - receiver type (Go),
10011 The term "physname" is a bit confusing.
10012 For C++, for example, it is the demangled name.
10013 For Go, for example, it's the mangled name.
10015 For Ada, return the DIE's linkage name rather than the fully qualified
10016 name. PHYSNAME is ignored..
10018 The result is allocated on the objfile_obstack and canonicalized. */
10020 static const char *
10021 dwarf2_compute_name (const char *name
,
10022 struct die_info
*die
, struct dwarf2_cu
*cu
,
10025 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10028 name
= dwarf2_name (die
, cu
);
10030 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10031 but otherwise compute it by typename_concat inside GDB.
10032 FIXME: Actually this is not really true, or at least not always true.
10033 It's all very confusing. compute_and_set_names doesn't try to demangle
10034 Fortran names because there is no mangling standard. So new_symbol
10035 will set the demangled name to the result of dwarf2_full_name, and it is
10036 the demangled name that GDB uses if it exists. */
10037 if (cu
->language
== language_ada
10038 || (cu
->language
== language_fortran
&& physname
))
10040 /* For Ada unit, we prefer the linkage name over the name, as
10041 the former contains the exported name, which the user expects
10042 to be able to reference. Ideally, we want the user to be able
10043 to reference this entity using either natural or linkage name,
10044 but we haven't started looking at this enhancement yet. */
10045 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10047 if (linkage_name
!= NULL
)
10048 return linkage_name
;
10051 /* These are the only languages we know how to qualify names in. */
10053 && (cu
->language
== language_cplus
10054 || cu
->language
== language_fortran
|| cu
->language
== language_d
10055 || cu
->language
== language_rust
))
10057 if (die_needs_namespace (die
, cu
))
10059 const char *prefix
;
10060 const char *canonical_name
= NULL
;
10064 prefix
= determine_prefix (die
, cu
);
10065 if (*prefix
!= '\0')
10067 gdb::unique_xmalloc_ptr
<char> prefixed_name
10068 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10070 buf
.puts (prefixed_name
.get ());
10075 /* Template parameters may be specified in the DIE's DW_AT_name, or
10076 as children with DW_TAG_template_type_param or
10077 DW_TAG_value_type_param. If the latter, add them to the name
10078 here. If the name already has template parameters, then
10079 skip this step; some versions of GCC emit both, and
10080 it is more efficient to use the pre-computed name.
10082 Something to keep in mind about this process: it is very
10083 unlikely, or in some cases downright impossible, to produce
10084 something that will match the mangled name of a function.
10085 If the definition of the function has the same debug info,
10086 we should be able to match up with it anyway. But fallbacks
10087 using the minimal symbol, for instance to find a method
10088 implemented in a stripped copy of libstdc++, will not work.
10089 If we do not have debug info for the definition, we will have to
10090 match them up some other way.
10092 When we do name matching there is a related problem with function
10093 templates; two instantiated function templates are allowed to
10094 differ only by their return types, which we do not add here. */
10096 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10098 struct attribute
*attr
;
10099 struct die_info
*child
;
10102 die
->building_fullname
= 1;
10104 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10108 const gdb_byte
*bytes
;
10109 struct dwarf2_locexpr_baton
*baton
;
10112 if (child
->tag
!= DW_TAG_template_type_param
10113 && child
->tag
!= DW_TAG_template_value_param
)
10124 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10127 complaint (_("template parameter missing DW_AT_type"));
10128 buf
.puts ("UNKNOWN_TYPE");
10131 type
= die_type (child
, cu
);
10133 if (child
->tag
== DW_TAG_template_type_param
)
10135 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10136 &type_print_raw_options
);
10140 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10143 complaint (_("template parameter missing "
10144 "DW_AT_const_value"));
10145 buf
.puts ("UNKNOWN_VALUE");
10149 dwarf2_const_value_attr (attr
, type
, name
,
10150 &cu
->comp_unit_obstack
, cu
,
10151 &value
, &bytes
, &baton
);
10153 if (TYPE_NOSIGN (type
))
10154 /* GDB prints characters as NUMBER 'CHAR'. If that's
10155 changed, this can use value_print instead. */
10156 c_printchar (value
, type
, &buf
);
10159 struct value_print_options opts
;
10162 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10166 else if (bytes
!= NULL
)
10168 v
= allocate_value (type
);
10169 memcpy (value_contents_writeable (v
), bytes
,
10170 TYPE_LENGTH (type
));
10173 v
= value_from_longest (type
, value
);
10175 /* Specify decimal so that we do not depend on
10177 get_formatted_print_options (&opts
, 'd');
10179 value_print (v
, &buf
, &opts
);
10184 die
->building_fullname
= 0;
10188 /* Close the argument list, with a space if necessary
10189 (nested templates). */
10190 if (!buf
.empty () && buf
.string ().back () == '>')
10197 /* For C++ methods, append formal parameter type
10198 information, if PHYSNAME. */
10200 if (physname
&& die
->tag
== DW_TAG_subprogram
10201 && cu
->language
== language_cplus
)
10203 struct type
*type
= read_type_die (die
, cu
);
10205 c_type_print_args (type
, &buf
, 1, cu
->language
,
10206 &type_print_raw_options
);
10208 if (cu
->language
== language_cplus
)
10210 /* Assume that an artificial first parameter is
10211 "this", but do not crash if it is not. RealView
10212 marks unnamed (and thus unused) parameters as
10213 artificial; there is no way to differentiate
10215 if (TYPE_NFIELDS (type
) > 0
10216 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10217 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10218 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10220 buf
.puts (" const");
10224 const std::string
&intermediate_name
= buf
.string ();
10226 if (cu
->language
== language_cplus
)
10228 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10231 /* If we only computed INTERMEDIATE_NAME, or if
10232 INTERMEDIATE_NAME is already canonical, then we need to
10234 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10235 name
= objfile
->intern (intermediate_name
);
10237 name
= canonical_name
;
10244 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10245 If scope qualifiers are appropriate they will be added. The result
10246 will be allocated on the storage_obstack, or NULL if the DIE does
10247 not have a name. NAME may either be from a previous call to
10248 dwarf2_name or NULL.
10250 The output string will be canonicalized (if C++). */
10252 static const char *
10253 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10255 return dwarf2_compute_name (name
, die
, cu
, 0);
10258 /* Construct a physname for the given DIE in CU. NAME may either be
10259 from a previous call to dwarf2_name or NULL. The result will be
10260 allocated on the objfile_objstack or NULL if the DIE does not have a
10263 The output string will be canonicalized (if C++). */
10265 static const char *
10266 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10268 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10269 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10272 /* In this case dwarf2_compute_name is just a shortcut not building anything
10274 if (!die_needs_namespace (die
, cu
))
10275 return dwarf2_compute_name (name
, die
, cu
, 1);
10277 mangled
= dw2_linkage_name (die
, cu
);
10279 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10280 See https://github.com/rust-lang/rust/issues/32925. */
10281 if (cu
->language
== language_rust
&& mangled
!= NULL
10282 && strchr (mangled
, '{') != NULL
)
10285 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10287 gdb::unique_xmalloc_ptr
<char> demangled
;
10288 if (mangled
!= NULL
)
10291 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10293 /* Do nothing (do not demangle the symbol name). */
10295 else if (cu
->language
== language_go
)
10297 /* This is a lie, but we already lie to the caller new_symbol.
10298 new_symbol assumes we return the mangled name.
10299 This just undoes that lie until things are cleaned up. */
10303 /* Use DMGL_RET_DROP for C++ template functions to suppress
10304 their return type. It is easier for GDB users to search
10305 for such functions as `name(params)' than `long name(params)'.
10306 In such case the minimal symbol names do not match the full
10307 symbol names but for template functions there is never a need
10308 to look up their definition from their declaration so
10309 the only disadvantage remains the minimal symbol variant
10310 `long name(params)' does not have the proper inferior type. */
10311 demangled
.reset (gdb_demangle (mangled
,
10312 (DMGL_PARAMS
| DMGL_ANSI
10313 | DMGL_RET_DROP
)));
10316 canon
= demangled
.get ();
10324 if (canon
== NULL
|| check_physname
)
10326 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10328 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10330 /* It may not mean a bug in GDB. The compiler could also
10331 compute DW_AT_linkage_name incorrectly. But in such case
10332 GDB would need to be bug-to-bug compatible. */
10334 complaint (_("Computed physname <%s> does not match demangled <%s> "
10335 "(from linkage <%s>) - DIE at %s [in module %s]"),
10336 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10337 objfile_name (objfile
));
10339 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10340 is available here - over computed PHYSNAME. It is safer
10341 against both buggy GDB and buggy compilers. */
10355 retval
= objfile
->intern (retval
);
10360 /* Inspect DIE in CU for a namespace alias. If one exists, record
10361 a new symbol for it.
10363 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10366 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10368 struct attribute
*attr
;
10370 /* If the die does not have a name, this is not a namespace
10372 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10376 struct die_info
*d
= die
;
10377 struct dwarf2_cu
*imported_cu
= cu
;
10379 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10380 keep inspecting DIEs until we hit the underlying import. */
10381 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10382 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10384 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10388 d
= follow_die_ref (d
, attr
, &imported_cu
);
10389 if (d
->tag
!= DW_TAG_imported_declaration
)
10393 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10395 complaint (_("DIE at %s has too many recursively imported "
10396 "declarations"), sect_offset_str (d
->sect_off
));
10403 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10405 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10406 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10408 /* This declaration is a global namespace alias. Add
10409 a symbol for it whose type is the aliased namespace. */
10410 new_symbol (die
, type
, cu
);
10419 /* Return the using directives repository (global or local?) to use in the
10420 current context for CU.
10422 For Ada, imported declarations can materialize renamings, which *may* be
10423 global. However it is impossible (for now?) in DWARF to distinguish
10424 "external" imported declarations and "static" ones. As all imported
10425 declarations seem to be static in all other languages, make them all CU-wide
10426 global only in Ada. */
10428 static struct using_direct
**
10429 using_directives (struct dwarf2_cu
*cu
)
10431 if (cu
->language
== language_ada
10432 && cu
->get_builder ()->outermost_context_p ())
10433 return cu
->get_builder ()->get_global_using_directives ();
10435 return cu
->get_builder ()->get_local_using_directives ();
10438 /* Read the import statement specified by the given die and record it. */
10441 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10443 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10444 struct attribute
*import_attr
;
10445 struct die_info
*imported_die
, *child_die
;
10446 struct dwarf2_cu
*imported_cu
;
10447 const char *imported_name
;
10448 const char *imported_name_prefix
;
10449 const char *canonical_name
;
10450 const char *import_alias
;
10451 const char *imported_declaration
= NULL
;
10452 const char *import_prefix
;
10453 std::vector
<const char *> excludes
;
10455 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10456 if (import_attr
== NULL
)
10458 complaint (_("Tag '%s' has no DW_AT_import"),
10459 dwarf_tag_name (die
->tag
));
10464 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10465 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10466 if (imported_name
== NULL
)
10468 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10470 The import in the following code:
10484 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10485 <52> DW_AT_decl_file : 1
10486 <53> DW_AT_decl_line : 6
10487 <54> DW_AT_import : <0x75>
10488 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10489 <59> DW_AT_name : B
10490 <5b> DW_AT_decl_file : 1
10491 <5c> DW_AT_decl_line : 2
10492 <5d> DW_AT_type : <0x6e>
10494 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10495 <76> DW_AT_byte_size : 4
10496 <77> DW_AT_encoding : 5 (signed)
10498 imports the wrong die ( 0x75 instead of 0x58 ).
10499 This case will be ignored until the gcc bug is fixed. */
10503 /* Figure out the local name after import. */
10504 import_alias
= dwarf2_name (die
, cu
);
10506 /* Figure out where the statement is being imported to. */
10507 import_prefix
= determine_prefix (die
, cu
);
10509 /* Figure out what the scope of the imported die is and prepend it
10510 to the name of the imported die. */
10511 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10513 if (imported_die
->tag
!= DW_TAG_namespace
10514 && imported_die
->tag
!= DW_TAG_module
)
10516 imported_declaration
= imported_name
;
10517 canonical_name
= imported_name_prefix
;
10519 else if (strlen (imported_name_prefix
) > 0)
10520 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10521 imported_name_prefix
,
10522 (cu
->language
== language_d
? "." : "::"),
10523 imported_name
, (char *) NULL
);
10525 canonical_name
= imported_name
;
10527 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10528 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10529 child_die
= sibling_die (child_die
))
10531 /* DWARF-4: A Fortran use statement with a “rename list” may be
10532 represented by an imported module entry with an import attribute
10533 referring to the module and owned entries corresponding to those
10534 entities that are renamed as part of being imported. */
10536 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10538 complaint (_("child DW_TAG_imported_declaration expected "
10539 "- DIE at %s [in module %s]"),
10540 sect_offset_str (child_die
->sect_off
),
10541 objfile_name (objfile
));
10545 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10546 if (import_attr
== NULL
)
10548 complaint (_("Tag '%s' has no DW_AT_import"),
10549 dwarf_tag_name (child_die
->tag
));
10554 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10556 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10557 if (imported_name
== NULL
)
10559 complaint (_("child DW_TAG_imported_declaration has unknown "
10560 "imported name - DIE at %s [in module %s]"),
10561 sect_offset_str (child_die
->sect_off
),
10562 objfile_name (objfile
));
10566 excludes
.push_back (imported_name
);
10568 process_die (child_die
, cu
);
10571 add_using_directive (using_directives (cu
),
10575 imported_declaration
,
10578 &objfile
->objfile_obstack
);
10581 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10582 types, but gives them a size of zero. Starting with version 14,
10583 ICC is compatible with GCC. */
10586 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10588 if (!cu
->checked_producer
)
10589 check_producer (cu
);
10591 return cu
->producer_is_icc_lt_14
;
10594 /* ICC generates a DW_AT_type for C void functions. This was observed on
10595 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10596 which says that void functions should not have a DW_AT_type. */
10599 producer_is_icc (struct dwarf2_cu
*cu
)
10601 if (!cu
->checked_producer
)
10602 check_producer (cu
);
10604 return cu
->producer_is_icc
;
10607 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10608 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10609 this, it was first present in GCC release 4.3.0. */
10612 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10614 if (!cu
->checked_producer
)
10615 check_producer (cu
);
10617 return cu
->producer_is_gcc_lt_4_3
;
10620 static file_and_directory
10621 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10623 file_and_directory res
;
10625 /* Find the filename. Do not use dwarf2_name here, since the filename
10626 is not a source language identifier. */
10627 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10628 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10630 if (res
.comp_dir
== NULL
10631 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10632 && IS_ABSOLUTE_PATH (res
.name
))
10634 res
.comp_dir_storage
= ldirname (res
.name
);
10635 if (!res
.comp_dir_storage
.empty ())
10636 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10638 if (res
.comp_dir
!= NULL
)
10640 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10641 directory, get rid of it. */
10642 const char *cp
= strchr (res
.comp_dir
, ':');
10644 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10645 res
.comp_dir
= cp
+ 1;
10648 if (res
.name
== NULL
)
10649 res
.name
= "<unknown>";
10654 /* Handle DW_AT_stmt_list for a compilation unit.
10655 DIE is the DW_TAG_compile_unit die for CU.
10656 COMP_DIR is the compilation directory. LOWPC is passed to
10657 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10660 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10661 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10663 struct dwarf2_per_objfile
*dwarf2_per_objfile
10664 = cu
->per_cu
->dwarf2_per_objfile
;
10665 struct attribute
*attr
;
10666 struct line_header line_header_local
;
10667 hashval_t line_header_local_hash
;
10669 int decode_mapping
;
10671 gdb_assert (! cu
->per_cu
->is_debug_types
);
10673 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10677 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10679 /* The line header hash table is only created if needed (it exists to
10680 prevent redundant reading of the line table for partial_units).
10681 If we're given a partial_unit, we'll need it. If we're given a
10682 compile_unit, then use the line header hash table if it's already
10683 created, but don't create one just yet. */
10685 if (dwarf2_per_objfile
->line_header_hash
== NULL
10686 && die
->tag
== DW_TAG_partial_unit
)
10688 dwarf2_per_objfile
->line_header_hash
10689 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10690 line_header_eq_voidp
,
10691 free_line_header_voidp
,
10695 line_header_local
.sect_off
= line_offset
;
10696 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10697 line_header_local_hash
= line_header_hash (&line_header_local
);
10698 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10700 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10701 &line_header_local
,
10702 line_header_local_hash
, NO_INSERT
);
10704 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10705 is not present in *SLOT (since if there is something in *SLOT then
10706 it will be for a partial_unit). */
10707 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10709 gdb_assert (*slot
!= NULL
);
10710 cu
->line_header
= (struct line_header
*) *slot
;
10715 /* dwarf_decode_line_header does not yet provide sufficient information.
10716 We always have to call also dwarf_decode_lines for it. */
10717 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10721 cu
->line_header
= lh
.release ();
10722 cu
->line_header_die_owner
= die
;
10724 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10728 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10729 &line_header_local
,
10730 line_header_local_hash
, INSERT
);
10731 gdb_assert (slot
!= NULL
);
10733 if (slot
!= NULL
&& *slot
== NULL
)
10735 /* This newly decoded line number information unit will be owned
10736 by line_header_hash hash table. */
10737 *slot
= cu
->line_header
;
10738 cu
->line_header_die_owner
= NULL
;
10742 /* We cannot free any current entry in (*slot) as that struct line_header
10743 may be already used by multiple CUs. Create only temporary decoded
10744 line_header for this CU - it may happen at most once for each line
10745 number information unit. And if we're not using line_header_hash
10746 then this is what we want as well. */
10747 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10749 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10750 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10755 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10758 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10760 struct dwarf2_per_objfile
*dwarf2_per_objfile
10761 = cu
->per_cu
->dwarf2_per_objfile
;
10762 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10763 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10764 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10765 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10766 struct attribute
*attr
;
10767 struct die_info
*child_die
;
10768 CORE_ADDR baseaddr
;
10770 prepare_one_comp_unit (cu
, die
, cu
->language
);
10771 baseaddr
= objfile
->text_section_offset ();
10773 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10775 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10776 from finish_block. */
10777 if (lowpc
== ((CORE_ADDR
) -1))
10779 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10781 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10783 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10784 standardised yet. As a workaround for the language detection we fall
10785 back to the DW_AT_producer string. */
10786 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10787 cu
->language
= language_opencl
;
10789 /* Similar hack for Go. */
10790 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10791 set_cu_language (DW_LANG_Go
, cu
);
10793 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10795 /* Decode line number information if present. We do this before
10796 processing child DIEs, so that the line header table is available
10797 for DW_AT_decl_file. */
10798 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10800 /* Process all dies in compilation unit. */
10801 if (die
->child
!= NULL
)
10803 child_die
= die
->child
;
10804 while (child_die
&& child_die
->tag
)
10806 process_die (child_die
, cu
);
10807 child_die
= sibling_die (child_die
);
10811 /* Decode macro information, if present. Dwarf 2 macro information
10812 refers to information in the line number info statement program
10813 header, so we can only read it if we've read the header
10815 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10817 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10818 if (attr
&& cu
->line_header
)
10820 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10821 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10823 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10827 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10828 if (attr
&& cu
->line_header
)
10830 unsigned int macro_offset
= DW_UNSND (attr
);
10832 dwarf_decode_macros (cu
, macro_offset
, 0);
10838 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10840 struct type_unit_group
*tu_group
;
10842 struct attribute
*attr
;
10844 struct signatured_type
*sig_type
;
10846 gdb_assert (per_cu
->is_debug_types
);
10847 sig_type
= (struct signatured_type
*) per_cu
;
10849 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10851 /* If we're using .gdb_index (includes -readnow) then
10852 per_cu->type_unit_group may not have been set up yet. */
10853 if (sig_type
->type_unit_group
== NULL
)
10854 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10855 tu_group
= sig_type
->type_unit_group
;
10857 /* If we've already processed this stmt_list there's no real need to
10858 do it again, we could fake it and just recreate the part we need
10859 (file name,index -> symtab mapping). If data shows this optimization
10860 is useful we can do it then. */
10861 first_time
= tu_group
->compunit_symtab
== NULL
;
10863 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10868 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10869 lh
= dwarf_decode_line_header (line_offset
, this);
10874 start_symtab ("", NULL
, 0);
10877 gdb_assert (tu_group
->symtabs
== NULL
);
10878 gdb_assert (m_builder
== nullptr);
10879 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10880 m_builder
.reset (new struct buildsym_compunit
10881 (COMPUNIT_OBJFILE (cust
), "",
10882 COMPUNIT_DIRNAME (cust
),
10883 compunit_language (cust
),
10889 line_header
= lh
.release ();
10890 line_header_die_owner
= die
;
10894 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10896 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10897 still initializing it, and our caller (a few levels up)
10898 process_full_type_unit still needs to know if this is the first
10902 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10903 struct symtab
*, line_header
->file_names_size ());
10905 auto &file_names
= line_header
->file_names ();
10906 for (i
= 0; i
< file_names
.size (); ++i
)
10908 file_entry
&fe
= file_names
[i
];
10909 dwarf2_start_subfile (this, fe
.name
,
10910 fe
.include_dir (line_header
));
10911 buildsym_compunit
*b
= get_builder ();
10912 if (b
->get_current_subfile ()->symtab
== NULL
)
10914 /* NOTE: start_subfile will recognize when it's been
10915 passed a file it has already seen. So we can't
10916 assume there's a simple mapping from
10917 cu->line_header->file_names to subfiles, plus
10918 cu->line_header->file_names may contain dups. */
10919 b
->get_current_subfile ()->symtab
10920 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10923 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10924 tu_group
->symtabs
[i
] = fe
.symtab
;
10929 gdb_assert (m_builder
== nullptr);
10930 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10931 m_builder
.reset (new struct buildsym_compunit
10932 (COMPUNIT_OBJFILE (cust
), "",
10933 COMPUNIT_DIRNAME (cust
),
10934 compunit_language (cust
),
10937 auto &file_names
= line_header
->file_names ();
10938 for (i
= 0; i
< file_names
.size (); ++i
)
10940 file_entry
&fe
= file_names
[i
];
10941 fe
.symtab
= tu_group
->symtabs
[i
];
10945 /* The main symtab is allocated last. Type units don't have DW_AT_name
10946 so they don't have a "real" (so to speak) symtab anyway.
10947 There is later code that will assign the main symtab to all symbols
10948 that don't have one. We need to handle the case of a symbol with a
10949 missing symtab (DW_AT_decl_file) anyway. */
10952 /* Process DW_TAG_type_unit.
10953 For TUs we want to skip the first top level sibling if it's not the
10954 actual type being defined by this TU. In this case the first top
10955 level sibling is there to provide context only. */
10958 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10960 struct die_info
*child_die
;
10962 prepare_one_comp_unit (cu
, die
, language_minimal
);
10964 /* Initialize (or reinitialize) the machinery for building symtabs.
10965 We do this before processing child DIEs, so that the line header table
10966 is available for DW_AT_decl_file. */
10967 cu
->setup_type_unit_groups (die
);
10969 if (die
->child
!= NULL
)
10971 child_die
= die
->child
;
10972 while (child_die
&& child_die
->tag
)
10974 process_die (child_die
, cu
);
10975 child_die
= sibling_die (child_die
);
10982 http://gcc.gnu.org/wiki/DebugFission
10983 http://gcc.gnu.org/wiki/DebugFissionDWP
10985 To simplify handling of both DWO files ("object" files with the DWARF info)
10986 and DWP files (a file with the DWOs packaged up into one file), we treat
10987 DWP files as having a collection of virtual DWO files. */
10990 hash_dwo_file (const void *item
)
10992 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10995 hash
= htab_hash_string (dwo_file
->dwo_name
);
10996 if (dwo_file
->comp_dir
!= NULL
)
10997 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11002 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11004 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11005 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11007 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11009 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11010 return lhs
->comp_dir
== rhs
->comp_dir
;
11011 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11014 /* Allocate a hash table for DWO files. */
11017 allocate_dwo_file_hash_table ()
11019 auto delete_dwo_file
= [] (void *item
)
11021 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11026 return htab_up (htab_create_alloc (41,
11033 /* Lookup DWO file DWO_NAME. */
11036 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11037 const char *dwo_name
,
11038 const char *comp_dir
)
11040 struct dwo_file find_entry
;
11043 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11044 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11046 find_entry
.dwo_name
= dwo_name
;
11047 find_entry
.comp_dir
= comp_dir
;
11048 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11055 hash_dwo_unit (const void *item
)
11057 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11059 /* This drops the top 32 bits of the id, but is ok for a hash. */
11060 return dwo_unit
->signature
;
11064 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11066 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11067 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11069 /* The signature is assumed to be unique within the DWO file.
11070 So while object file CU dwo_id's always have the value zero,
11071 that's OK, assuming each object file DWO file has only one CU,
11072 and that's the rule for now. */
11073 return lhs
->signature
== rhs
->signature
;
11076 /* Allocate a hash table for DWO CUs,TUs.
11077 There is one of these tables for each of CUs,TUs for each DWO file. */
11080 allocate_dwo_unit_table ()
11082 /* Start out with a pretty small number.
11083 Generally DWO files contain only one CU and maybe some TUs. */
11084 return htab_up (htab_create_alloc (3,
11087 NULL
, xcalloc
, xfree
));
11090 /* die_reader_func for create_dwo_cu. */
11093 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11094 const gdb_byte
*info_ptr
,
11095 struct die_info
*comp_unit_die
,
11096 struct dwo_file
*dwo_file
,
11097 struct dwo_unit
*dwo_unit
)
11099 struct dwarf2_cu
*cu
= reader
->cu
;
11100 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11101 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11103 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11104 if (!signature
.has_value ())
11106 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11107 " its dwo_id [in module %s]"),
11108 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11112 dwo_unit
->dwo_file
= dwo_file
;
11113 dwo_unit
->signature
= *signature
;
11114 dwo_unit
->section
= section
;
11115 dwo_unit
->sect_off
= sect_off
;
11116 dwo_unit
->length
= cu
->per_cu
->length
;
11118 if (dwarf_read_debug
)
11119 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11120 sect_offset_str (sect_off
),
11121 hex_string (dwo_unit
->signature
));
11124 /* Create the dwo_units for the CUs in a DWO_FILE.
11125 Note: This function processes DWO files only, not DWP files. */
11128 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11129 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11130 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11132 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11133 const gdb_byte
*info_ptr
, *end_ptr
;
11135 section
.read (objfile
);
11136 info_ptr
= section
.buffer
;
11138 if (info_ptr
== NULL
)
11141 if (dwarf_read_debug
)
11143 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11144 section
.get_name (),
11145 section
.get_file_name ());
11148 end_ptr
= info_ptr
+ section
.size
;
11149 while (info_ptr
< end_ptr
)
11151 struct dwarf2_per_cu_data per_cu
;
11152 struct dwo_unit read_unit
{};
11153 struct dwo_unit
*dwo_unit
;
11155 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11157 memset (&per_cu
, 0, sizeof (per_cu
));
11158 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11159 per_cu
.is_debug_types
= 0;
11160 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11161 per_cu
.section
= §ion
;
11163 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11164 if (!reader
.dummy_p
)
11165 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11166 &dwo_file
, &read_unit
);
11167 info_ptr
+= per_cu
.length
;
11169 // If the unit could not be parsed, skip it.
11170 if (read_unit
.dwo_file
== NULL
)
11173 if (cus_htab
== NULL
)
11174 cus_htab
= allocate_dwo_unit_table ();
11176 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11177 *dwo_unit
= read_unit
;
11178 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11179 gdb_assert (slot
!= NULL
);
11182 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11183 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11185 complaint (_("debug cu entry at offset %s is duplicate to"
11186 " the entry at offset %s, signature %s"),
11187 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11188 hex_string (dwo_unit
->signature
));
11190 *slot
= (void *)dwo_unit
;
11194 /* DWP file .debug_{cu,tu}_index section format:
11195 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11199 Both index sections have the same format, and serve to map a 64-bit
11200 signature to a set of section numbers. Each section begins with a header,
11201 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11202 indexes, and a pool of 32-bit section numbers. The index sections will be
11203 aligned at 8-byte boundaries in the file.
11205 The index section header consists of:
11207 V, 32 bit version number
11209 N, 32 bit number of compilation units or type units in the index
11210 M, 32 bit number of slots in the hash table
11212 Numbers are recorded using the byte order of the application binary.
11214 The hash table begins at offset 16 in the section, and consists of an array
11215 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11216 order of the application binary). Unused slots in the hash table are 0.
11217 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11219 The parallel table begins immediately after the hash table
11220 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11221 array of 32-bit indexes (using the byte order of the application binary),
11222 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11223 table contains a 32-bit index into the pool of section numbers. For unused
11224 hash table slots, the corresponding entry in the parallel table will be 0.
11226 The pool of section numbers begins immediately following the hash table
11227 (at offset 16 + 12 * M from the beginning of the section). The pool of
11228 section numbers consists of an array of 32-bit words (using the byte order
11229 of the application binary). Each item in the array is indexed starting
11230 from 0. The hash table entry provides the index of the first section
11231 number in the set. Additional section numbers in the set follow, and the
11232 set is terminated by a 0 entry (section number 0 is not used in ELF).
11234 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11235 section must be the first entry in the set, and the .debug_abbrev.dwo must
11236 be the second entry. Other members of the set may follow in any order.
11242 DWP Version 2 combines all the .debug_info, etc. sections into one,
11243 and the entries in the index tables are now offsets into these sections.
11244 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11247 Index Section Contents:
11249 Hash Table of Signatures dwp_hash_table.hash_table
11250 Parallel Table of Indices dwp_hash_table.unit_table
11251 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11252 Table of Section Sizes dwp_hash_table.v2.sizes
11254 The index section header consists of:
11256 V, 32 bit version number
11257 L, 32 bit number of columns in the table of section offsets
11258 N, 32 bit number of compilation units or type units in the index
11259 M, 32 bit number of slots in the hash table
11261 Numbers are recorded using the byte order of the application binary.
11263 The hash table has the same format as version 1.
11264 The parallel table of indices has the same format as version 1,
11265 except that the entries are origin-1 indices into the table of sections
11266 offsets and the table of section sizes.
11268 The table of offsets begins immediately following the parallel table
11269 (at offset 16 + 12 * M from the beginning of the section). The table is
11270 a two-dimensional array of 32-bit words (using the byte order of the
11271 application binary), with L columns and N+1 rows, in row-major order.
11272 Each row in the array is indexed starting from 0. The first row provides
11273 a key to the remaining rows: each column in this row provides an identifier
11274 for a debug section, and the offsets in the same column of subsequent rows
11275 refer to that section. The section identifiers are:
11277 DW_SECT_INFO 1 .debug_info.dwo
11278 DW_SECT_TYPES 2 .debug_types.dwo
11279 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11280 DW_SECT_LINE 4 .debug_line.dwo
11281 DW_SECT_LOC 5 .debug_loc.dwo
11282 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11283 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11284 DW_SECT_MACRO 8 .debug_macro.dwo
11286 The offsets provided by the CU and TU index sections are the base offsets
11287 for the contributions made by each CU or TU to the corresponding section
11288 in the package file. Each CU and TU header contains an abbrev_offset
11289 field, used to find the abbreviations table for that CU or TU within the
11290 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11291 be interpreted as relative to the base offset given in the index section.
11292 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11293 should be interpreted as relative to the base offset for .debug_line.dwo,
11294 and offsets into other debug sections obtained from DWARF attributes should
11295 also be interpreted as relative to the corresponding base offset.
11297 The table of sizes begins immediately following the table of offsets.
11298 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11299 with L columns and N rows, in row-major order. Each row in the array is
11300 indexed starting from 1 (row 0 is shared by the two tables).
11304 Hash table lookup is handled the same in version 1 and 2:
11306 We assume that N and M will not exceed 2^32 - 1.
11307 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11309 Given a 64-bit compilation unit signature or a type signature S, an entry
11310 in the hash table is located as follows:
11312 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11313 the low-order k bits all set to 1.
11315 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11317 3) If the hash table entry at index H matches the signature, use that
11318 entry. If the hash table entry at index H is unused (all zeroes),
11319 terminate the search: the signature is not present in the table.
11321 4) Let H = (H + H') modulo M. Repeat at Step 3.
11323 Because M > N and H' and M are relatively prime, the search is guaranteed
11324 to stop at an unused slot or find the match. */
11326 /* Create a hash table to map DWO IDs to their CU/TU entry in
11327 .debug_{info,types}.dwo in DWP_FILE.
11328 Returns NULL if there isn't one.
11329 Note: This function processes DWP files only, not DWO files. */
11331 static struct dwp_hash_table
*
11332 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11333 struct dwp_file
*dwp_file
, int is_debug_types
)
11335 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11336 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11337 const gdb_byte
*index_ptr
, *index_end
;
11338 struct dwarf2_section_info
*index
;
11339 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11340 struct dwp_hash_table
*htab
;
11342 if (is_debug_types
)
11343 index
= &dwp_file
->sections
.tu_index
;
11345 index
= &dwp_file
->sections
.cu_index
;
11347 if (index
->empty ())
11349 index
->read (objfile
);
11351 index_ptr
= index
->buffer
;
11352 index_end
= index_ptr
+ index
->size
;
11354 version
= read_4_bytes (dbfd
, index_ptr
);
11357 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11361 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11363 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11366 if (version
!= 1 && version
!= 2)
11368 error (_("Dwarf Error: unsupported DWP file version (%s)"
11369 " [in module %s]"),
11370 pulongest (version
), dwp_file
->name
);
11372 if (nr_slots
!= (nr_slots
& -nr_slots
))
11374 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11375 " is not power of 2 [in module %s]"),
11376 pulongest (nr_slots
), dwp_file
->name
);
11379 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11380 htab
->version
= version
;
11381 htab
->nr_columns
= nr_columns
;
11382 htab
->nr_units
= nr_units
;
11383 htab
->nr_slots
= nr_slots
;
11384 htab
->hash_table
= index_ptr
;
11385 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11387 /* Exit early if the table is empty. */
11388 if (nr_slots
== 0 || nr_units
== 0
11389 || (version
== 2 && nr_columns
== 0))
11391 /* All must be zero. */
11392 if (nr_slots
!= 0 || nr_units
!= 0
11393 || (version
== 2 && nr_columns
!= 0))
11395 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11396 " all zero [in modules %s]"),
11404 htab
->section_pool
.v1
.indices
=
11405 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11406 /* It's harder to decide whether the section is too small in v1.
11407 V1 is deprecated anyway so we punt. */
11411 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11412 int *ids
= htab
->section_pool
.v2
.section_ids
;
11413 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11414 /* Reverse map for error checking. */
11415 int ids_seen
[DW_SECT_MAX
+ 1];
11418 if (nr_columns
< 2)
11420 error (_("Dwarf Error: bad DWP hash table, too few columns"
11421 " in section table [in module %s]"),
11424 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11426 error (_("Dwarf Error: bad DWP hash table, too many columns"
11427 " in section table [in module %s]"),
11430 memset (ids
, 255, sizeof_ids
);
11431 memset (ids_seen
, 255, sizeof (ids_seen
));
11432 for (i
= 0; i
< nr_columns
; ++i
)
11434 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11436 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11438 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11439 " in section table [in module %s]"),
11440 id
, dwp_file
->name
);
11442 if (ids_seen
[id
] != -1)
11444 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11445 " id %d in section table [in module %s]"),
11446 id
, dwp_file
->name
);
11451 /* Must have exactly one info or types section. */
11452 if (((ids_seen
[DW_SECT_INFO
] != -1)
11453 + (ids_seen
[DW_SECT_TYPES
] != -1))
11456 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11457 " DWO info/types section [in module %s]"),
11460 /* Must have an abbrev section. */
11461 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11463 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11464 " section [in module %s]"),
11467 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11468 htab
->section_pool
.v2
.sizes
=
11469 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11470 * nr_units
* nr_columns
);
11471 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11472 * nr_units
* nr_columns
))
11475 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11476 " [in module %s]"),
11484 /* Update SECTIONS with the data from SECTP.
11486 This function is like the other "locate" section routines that are
11487 passed to bfd_map_over_sections, but in this context the sections to
11488 read comes from the DWP V1 hash table, not the full ELF section table.
11490 The result is non-zero for success, or zero if an error was found. */
11493 locate_v1_virtual_dwo_sections (asection
*sectp
,
11494 struct virtual_v1_dwo_sections
*sections
)
11496 const struct dwop_section_names
*names
= &dwop_section_names
;
11498 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11500 /* There can be only one. */
11501 if (sections
->abbrev
.s
.section
!= NULL
)
11503 sections
->abbrev
.s
.section
= sectp
;
11504 sections
->abbrev
.size
= bfd_section_size (sectp
);
11506 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11507 || section_is_p (sectp
->name
, &names
->types_dwo
))
11509 /* There can be only one. */
11510 if (sections
->info_or_types
.s
.section
!= NULL
)
11512 sections
->info_or_types
.s
.section
= sectp
;
11513 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11515 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11517 /* There can be only one. */
11518 if (sections
->line
.s
.section
!= NULL
)
11520 sections
->line
.s
.section
= sectp
;
11521 sections
->line
.size
= bfd_section_size (sectp
);
11523 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11525 /* There can be only one. */
11526 if (sections
->loc
.s
.section
!= NULL
)
11528 sections
->loc
.s
.section
= sectp
;
11529 sections
->loc
.size
= bfd_section_size (sectp
);
11531 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11533 /* There can be only one. */
11534 if (sections
->macinfo
.s
.section
!= NULL
)
11536 sections
->macinfo
.s
.section
= sectp
;
11537 sections
->macinfo
.size
= bfd_section_size (sectp
);
11539 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11541 /* There can be only one. */
11542 if (sections
->macro
.s
.section
!= NULL
)
11544 sections
->macro
.s
.section
= sectp
;
11545 sections
->macro
.size
= bfd_section_size (sectp
);
11547 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11549 /* There can be only one. */
11550 if (sections
->str_offsets
.s
.section
!= NULL
)
11552 sections
->str_offsets
.s
.section
= sectp
;
11553 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11557 /* No other kind of section is valid. */
11564 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11565 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11566 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11567 This is for DWP version 1 files. */
11569 static struct dwo_unit
*
11570 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11571 struct dwp_file
*dwp_file
,
11572 uint32_t unit_index
,
11573 const char *comp_dir
,
11574 ULONGEST signature
, int is_debug_types
)
11576 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11577 const struct dwp_hash_table
*dwp_htab
=
11578 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11579 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11580 const char *kind
= is_debug_types
? "TU" : "CU";
11581 struct dwo_file
*dwo_file
;
11582 struct dwo_unit
*dwo_unit
;
11583 struct virtual_v1_dwo_sections sections
;
11584 void **dwo_file_slot
;
11587 gdb_assert (dwp_file
->version
== 1);
11589 if (dwarf_read_debug
)
11591 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11593 pulongest (unit_index
), hex_string (signature
),
11597 /* Fetch the sections of this DWO unit.
11598 Put a limit on the number of sections we look for so that bad data
11599 doesn't cause us to loop forever. */
11601 #define MAX_NR_V1_DWO_SECTIONS \
11602 (1 /* .debug_info or .debug_types */ \
11603 + 1 /* .debug_abbrev */ \
11604 + 1 /* .debug_line */ \
11605 + 1 /* .debug_loc */ \
11606 + 1 /* .debug_str_offsets */ \
11607 + 1 /* .debug_macro or .debug_macinfo */ \
11608 + 1 /* trailing zero */)
11610 memset (§ions
, 0, sizeof (sections
));
11612 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11615 uint32_t section_nr
=
11616 read_4_bytes (dbfd
,
11617 dwp_htab
->section_pool
.v1
.indices
11618 + (unit_index
+ i
) * sizeof (uint32_t));
11620 if (section_nr
== 0)
11622 if (section_nr
>= dwp_file
->num_sections
)
11624 error (_("Dwarf Error: bad DWP hash table, section number too large"
11625 " [in module %s]"),
11629 sectp
= dwp_file
->elf_sections
[section_nr
];
11630 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11632 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11633 " [in module %s]"),
11639 || sections
.info_or_types
.empty ()
11640 || sections
.abbrev
.empty ())
11642 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11643 " [in module %s]"),
11646 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11648 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11649 " [in module %s]"),
11653 /* It's easier for the rest of the code if we fake a struct dwo_file and
11654 have dwo_unit "live" in that. At least for now.
11656 The DWP file can be made up of a random collection of CUs and TUs.
11657 However, for each CU + set of TUs that came from the same original DWO
11658 file, we can combine them back into a virtual DWO file to save space
11659 (fewer struct dwo_file objects to allocate). Remember that for really
11660 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11662 std::string virtual_dwo_name
=
11663 string_printf ("virtual-dwo/%d-%d-%d-%d",
11664 sections
.abbrev
.get_id (),
11665 sections
.line
.get_id (),
11666 sections
.loc
.get_id (),
11667 sections
.str_offsets
.get_id ());
11668 /* Can we use an existing virtual DWO file? */
11669 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11670 virtual_dwo_name
.c_str (),
11672 /* Create one if necessary. */
11673 if (*dwo_file_slot
== NULL
)
11675 if (dwarf_read_debug
)
11677 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11678 virtual_dwo_name
.c_str ());
11680 dwo_file
= new struct dwo_file
;
11681 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11682 dwo_file
->comp_dir
= comp_dir
;
11683 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11684 dwo_file
->sections
.line
= sections
.line
;
11685 dwo_file
->sections
.loc
= sections
.loc
;
11686 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11687 dwo_file
->sections
.macro
= sections
.macro
;
11688 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11689 /* The "str" section is global to the entire DWP file. */
11690 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11691 /* The info or types section is assigned below to dwo_unit,
11692 there's no need to record it in dwo_file.
11693 Also, we can't simply record type sections in dwo_file because
11694 we record a pointer into the vector in dwo_unit. As we collect more
11695 types we'll grow the vector and eventually have to reallocate space
11696 for it, invalidating all copies of pointers into the previous
11698 *dwo_file_slot
= dwo_file
;
11702 if (dwarf_read_debug
)
11704 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11705 virtual_dwo_name
.c_str ());
11707 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11710 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11711 dwo_unit
->dwo_file
= dwo_file
;
11712 dwo_unit
->signature
= signature
;
11713 dwo_unit
->section
=
11714 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11715 *dwo_unit
->section
= sections
.info_or_types
;
11716 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11721 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11722 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11723 piece within that section used by a TU/CU, return a virtual section
11724 of just that piece. */
11726 static struct dwarf2_section_info
11727 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11728 struct dwarf2_section_info
*section
,
11729 bfd_size_type offset
, bfd_size_type size
)
11731 struct dwarf2_section_info result
;
11734 gdb_assert (section
!= NULL
);
11735 gdb_assert (!section
->is_virtual
);
11737 memset (&result
, 0, sizeof (result
));
11738 result
.s
.containing_section
= section
;
11739 result
.is_virtual
= true;
11744 sectp
= section
->get_bfd_section ();
11746 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11747 bounds of the real section. This is a pretty-rare event, so just
11748 flag an error (easier) instead of a warning and trying to cope. */
11750 || offset
+ size
> bfd_section_size (sectp
))
11752 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11753 " in section %s [in module %s]"),
11754 sectp
? bfd_section_name (sectp
) : "<unknown>",
11755 objfile_name (dwarf2_per_objfile
->objfile
));
11758 result
.virtual_offset
= offset
;
11759 result
.size
= size
;
11763 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11764 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11765 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11766 This is for DWP version 2 files. */
11768 static struct dwo_unit
*
11769 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11770 struct dwp_file
*dwp_file
,
11771 uint32_t unit_index
,
11772 const char *comp_dir
,
11773 ULONGEST signature
, int is_debug_types
)
11775 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11776 const struct dwp_hash_table
*dwp_htab
=
11777 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11778 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11779 const char *kind
= is_debug_types
? "TU" : "CU";
11780 struct dwo_file
*dwo_file
;
11781 struct dwo_unit
*dwo_unit
;
11782 struct virtual_v2_dwo_sections sections
;
11783 void **dwo_file_slot
;
11786 gdb_assert (dwp_file
->version
== 2);
11788 if (dwarf_read_debug
)
11790 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11792 pulongest (unit_index
), hex_string (signature
),
11796 /* Fetch the section offsets of this DWO unit. */
11798 memset (§ions
, 0, sizeof (sections
));
11800 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11802 uint32_t offset
= read_4_bytes (dbfd
,
11803 dwp_htab
->section_pool
.v2
.offsets
11804 + (((unit_index
- 1) * dwp_htab
->nr_columns
11806 * sizeof (uint32_t)));
11807 uint32_t size
= read_4_bytes (dbfd
,
11808 dwp_htab
->section_pool
.v2
.sizes
11809 + (((unit_index
- 1) * dwp_htab
->nr_columns
11811 * sizeof (uint32_t)));
11813 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11816 case DW_SECT_TYPES
:
11817 sections
.info_or_types_offset
= offset
;
11818 sections
.info_or_types_size
= size
;
11820 case DW_SECT_ABBREV
:
11821 sections
.abbrev_offset
= offset
;
11822 sections
.abbrev_size
= size
;
11825 sections
.line_offset
= offset
;
11826 sections
.line_size
= size
;
11829 sections
.loc_offset
= offset
;
11830 sections
.loc_size
= size
;
11832 case DW_SECT_STR_OFFSETS
:
11833 sections
.str_offsets_offset
= offset
;
11834 sections
.str_offsets_size
= size
;
11836 case DW_SECT_MACINFO
:
11837 sections
.macinfo_offset
= offset
;
11838 sections
.macinfo_size
= size
;
11840 case DW_SECT_MACRO
:
11841 sections
.macro_offset
= offset
;
11842 sections
.macro_size
= size
;
11847 /* It's easier for the rest of the code if we fake a struct dwo_file and
11848 have dwo_unit "live" in that. At least for now.
11850 The DWP file can be made up of a random collection of CUs and TUs.
11851 However, for each CU + set of TUs that came from the same original DWO
11852 file, we can combine them back into a virtual DWO file to save space
11853 (fewer struct dwo_file objects to allocate). Remember that for really
11854 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11856 std::string virtual_dwo_name
=
11857 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11858 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11859 (long) (sections
.line_size
? sections
.line_offset
: 0),
11860 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11861 (long) (sections
.str_offsets_size
11862 ? sections
.str_offsets_offset
: 0));
11863 /* Can we use an existing virtual DWO file? */
11864 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11865 virtual_dwo_name
.c_str (),
11867 /* Create one if necessary. */
11868 if (*dwo_file_slot
== NULL
)
11870 if (dwarf_read_debug
)
11872 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11873 virtual_dwo_name
.c_str ());
11875 dwo_file
= new struct dwo_file
;
11876 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11877 dwo_file
->comp_dir
= comp_dir
;
11878 dwo_file
->sections
.abbrev
=
11879 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11880 sections
.abbrev_offset
, sections
.abbrev_size
);
11881 dwo_file
->sections
.line
=
11882 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11883 sections
.line_offset
, sections
.line_size
);
11884 dwo_file
->sections
.loc
=
11885 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11886 sections
.loc_offset
, sections
.loc_size
);
11887 dwo_file
->sections
.macinfo
=
11888 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11889 sections
.macinfo_offset
, sections
.macinfo_size
);
11890 dwo_file
->sections
.macro
=
11891 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11892 sections
.macro_offset
, sections
.macro_size
);
11893 dwo_file
->sections
.str_offsets
=
11894 create_dwp_v2_section (dwarf2_per_objfile
,
11895 &dwp_file
->sections
.str_offsets
,
11896 sections
.str_offsets_offset
,
11897 sections
.str_offsets_size
);
11898 /* The "str" section is global to the entire DWP file. */
11899 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11900 /* The info or types section is assigned below to dwo_unit,
11901 there's no need to record it in dwo_file.
11902 Also, we can't simply record type sections in dwo_file because
11903 we record a pointer into the vector in dwo_unit. As we collect more
11904 types we'll grow the vector and eventually have to reallocate space
11905 for it, invalidating all copies of pointers into the previous
11907 *dwo_file_slot
= dwo_file
;
11911 if (dwarf_read_debug
)
11913 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11914 virtual_dwo_name
.c_str ());
11916 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11919 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11920 dwo_unit
->dwo_file
= dwo_file
;
11921 dwo_unit
->signature
= signature
;
11922 dwo_unit
->section
=
11923 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11924 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11926 ? &dwp_file
->sections
.types
11927 : &dwp_file
->sections
.info
,
11928 sections
.info_or_types_offset
,
11929 sections
.info_or_types_size
);
11930 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11935 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11936 Returns NULL if the signature isn't found. */
11938 static struct dwo_unit
*
11939 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11940 struct dwp_file
*dwp_file
, const char *comp_dir
,
11941 ULONGEST signature
, int is_debug_types
)
11943 const struct dwp_hash_table
*dwp_htab
=
11944 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11945 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11946 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11947 uint32_t hash
= signature
& mask
;
11948 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11951 struct dwo_unit find_dwo_cu
;
11953 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11954 find_dwo_cu
.signature
= signature
;
11955 slot
= htab_find_slot (is_debug_types
11956 ? dwp_file
->loaded_tus
.get ()
11957 : dwp_file
->loaded_cus
.get (),
11958 &find_dwo_cu
, INSERT
);
11961 return (struct dwo_unit
*) *slot
;
11963 /* Use a for loop so that we don't loop forever on bad debug info. */
11964 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11966 ULONGEST signature_in_table
;
11968 signature_in_table
=
11969 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11970 if (signature_in_table
== signature
)
11972 uint32_t unit_index
=
11973 read_4_bytes (dbfd
,
11974 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11976 if (dwp_file
->version
== 1)
11978 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11979 dwp_file
, unit_index
,
11980 comp_dir
, signature
,
11985 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11986 dwp_file
, unit_index
,
11987 comp_dir
, signature
,
11990 return (struct dwo_unit
*) *slot
;
11992 if (signature_in_table
== 0)
11994 hash
= (hash
+ hash2
) & mask
;
11997 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11998 " [in module %s]"),
12002 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12003 Open the file specified by FILE_NAME and hand it off to BFD for
12004 preliminary analysis. Return a newly initialized bfd *, which
12005 includes a canonicalized copy of FILE_NAME.
12006 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12007 SEARCH_CWD is true if the current directory is to be searched.
12008 It will be searched before debug-file-directory.
12009 If successful, the file is added to the bfd include table of the
12010 objfile's bfd (see gdb_bfd_record_inclusion).
12011 If unable to find/open the file, return NULL.
12012 NOTE: This function is derived from symfile_bfd_open. */
12014 static gdb_bfd_ref_ptr
12015 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12016 const char *file_name
, int is_dwp
, int search_cwd
)
12019 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12020 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12021 to debug_file_directory. */
12022 const char *search_path
;
12023 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12025 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12028 if (*debug_file_directory
!= '\0')
12030 search_path_holder
.reset (concat (".", dirname_separator_string
,
12031 debug_file_directory
,
12033 search_path
= search_path_holder
.get ();
12039 search_path
= debug_file_directory
;
12041 openp_flags flags
= OPF_RETURN_REALPATH
;
12043 flags
|= OPF_SEARCH_IN_PATH
;
12045 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12046 desc
= openp (search_path
, flags
, file_name
,
12047 O_RDONLY
| O_BINARY
, &absolute_name
);
12051 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12053 if (sym_bfd
== NULL
)
12055 bfd_set_cacheable (sym_bfd
.get (), 1);
12057 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12060 /* Success. Record the bfd as having been included by the objfile's bfd.
12061 This is important because things like demangled_names_hash lives in the
12062 objfile's per_bfd space and may have references to things like symbol
12063 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12064 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12069 /* Try to open DWO file FILE_NAME.
12070 COMP_DIR is the DW_AT_comp_dir attribute.
12071 The result is the bfd handle of the file.
12072 If there is a problem finding or opening the file, return NULL.
12073 Upon success, the canonicalized path of the file is stored in the bfd,
12074 same as symfile_bfd_open. */
12076 static gdb_bfd_ref_ptr
12077 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12078 const char *file_name
, const char *comp_dir
)
12080 if (IS_ABSOLUTE_PATH (file_name
))
12081 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12082 0 /*is_dwp*/, 0 /*search_cwd*/);
12084 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12086 if (comp_dir
!= NULL
)
12088 gdb::unique_xmalloc_ptr
<char> path_to_try
12089 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12091 /* NOTE: If comp_dir is a relative path, this will also try the
12092 search path, which seems useful. */
12093 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12094 path_to_try
.get (),
12096 1 /*search_cwd*/));
12101 /* That didn't work, try debug-file-directory, which, despite its name,
12102 is a list of paths. */
12104 if (*debug_file_directory
== '\0')
12107 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12108 0 /*is_dwp*/, 1 /*search_cwd*/);
12111 /* This function is mapped across the sections and remembers the offset and
12112 size of each of the DWO debugging sections we are interested in. */
12115 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12117 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12118 const struct dwop_section_names
*names
= &dwop_section_names
;
12120 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12122 dwo_sections
->abbrev
.s
.section
= sectp
;
12123 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12125 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12127 dwo_sections
->info
.s
.section
= sectp
;
12128 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12130 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12132 dwo_sections
->line
.s
.section
= sectp
;
12133 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12135 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12137 dwo_sections
->loc
.s
.section
= sectp
;
12138 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12140 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12142 dwo_sections
->macinfo
.s
.section
= sectp
;
12143 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12145 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12147 dwo_sections
->macro
.s
.section
= sectp
;
12148 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12150 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12152 dwo_sections
->str
.s
.section
= sectp
;
12153 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12155 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12157 dwo_sections
->str_offsets
.s
.section
= sectp
;
12158 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12160 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12162 struct dwarf2_section_info type_section
;
12164 memset (&type_section
, 0, sizeof (type_section
));
12165 type_section
.s
.section
= sectp
;
12166 type_section
.size
= bfd_section_size (sectp
);
12167 dwo_sections
->types
.push_back (type_section
);
12171 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12172 by PER_CU. This is for the non-DWP case.
12173 The result is NULL if DWO_NAME can't be found. */
12175 static struct dwo_file
*
12176 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12177 const char *dwo_name
, const char *comp_dir
)
12179 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12181 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12184 if (dwarf_read_debug
)
12185 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12189 dwo_file_up
dwo_file (new struct dwo_file
);
12190 dwo_file
->dwo_name
= dwo_name
;
12191 dwo_file
->comp_dir
= comp_dir
;
12192 dwo_file
->dbfd
= std::move (dbfd
);
12194 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12195 &dwo_file
->sections
);
12197 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12198 dwo_file
->sections
.info
, dwo_file
->cus
);
12200 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12201 dwo_file
->sections
.types
, dwo_file
->tus
);
12203 if (dwarf_read_debug
)
12204 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12206 return dwo_file
.release ();
12209 /* This function is mapped across the sections and remembers the offset and
12210 size of each of the DWP debugging sections common to version 1 and 2 that
12211 we are interested in. */
12214 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12215 void *dwp_file_ptr
)
12217 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12218 const struct dwop_section_names
*names
= &dwop_section_names
;
12219 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12221 /* Record the ELF section number for later lookup: this is what the
12222 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12223 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12224 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12226 /* Look for specific sections that we need. */
12227 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12229 dwp_file
->sections
.str
.s
.section
= sectp
;
12230 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12232 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12234 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12235 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12237 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12239 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12240 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12244 /* This function is mapped across the sections and remembers the offset and
12245 size of each of the DWP version 2 debugging sections that we are interested
12246 in. This is split into a separate function because we don't know if we
12247 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12250 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12252 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12253 const struct dwop_section_names
*names
= &dwop_section_names
;
12254 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12256 /* Record the ELF section number for later lookup: this is what the
12257 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12258 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12259 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12261 /* Look for specific sections that we need. */
12262 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12264 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12265 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12267 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12269 dwp_file
->sections
.info
.s
.section
= sectp
;
12270 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12272 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12274 dwp_file
->sections
.line
.s
.section
= sectp
;
12275 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12277 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12279 dwp_file
->sections
.loc
.s
.section
= sectp
;
12280 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12282 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12284 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12285 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12287 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12289 dwp_file
->sections
.macro
.s
.section
= sectp
;
12290 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12292 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12294 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12295 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12297 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12299 dwp_file
->sections
.types
.s
.section
= sectp
;
12300 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12304 /* Hash function for dwp_file loaded CUs/TUs. */
12307 hash_dwp_loaded_cutus (const void *item
)
12309 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12311 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12312 return dwo_unit
->signature
;
12315 /* Equality function for dwp_file loaded CUs/TUs. */
12318 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12320 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12321 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12323 return dua
->signature
== dub
->signature
;
12326 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12329 allocate_dwp_loaded_cutus_table ()
12331 return htab_up (htab_create_alloc (3,
12332 hash_dwp_loaded_cutus
,
12333 eq_dwp_loaded_cutus
,
12334 NULL
, xcalloc
, xfree
));
12337 /* Try to open DWP file FILE_NAME.
12338 The result is the bfd handle of the file.
12339 If there is a problem finding or opening the file, return NULL.
12340 Upon success, the canonicalized path of the file is stored in the bfd,
12341 same as symfile_bfd_open. */
12343 static gdb_bfd_ref_ptr
12344 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12345 const char *file_name
)
12347 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12349 1 /*search_cwd*/));
12353 /* Work around upstream bug 15652.
12354 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12355 [Whether that's a "bug" is debatable, but it is getting in our way.]
12356 We have no real idea where the dwp file is, because gdb's realpath-ing
12357 of the executable's path may have discarded the needed info.
12358 [IWBN if the dwp file name was recorded in the executable, akin to
12359 .gnu_debuglink, but that doesn't exist yet.]
12360 Strip the directory from FILE_NAME and search again. */
12361 if (*debug_file_directory
!= '\0')
12363 /* Don't implicitly search the current directory here.
12364 If the user wants to search "." to handle this case,
12365 it must be added to debug-file-directory. */
12366 return try_open_dwop_file (dwarf2_per_objfile
,
12367 lbasename (file_name
), 1 /*is_dwp*/,
12374 /* Initialize the use of the DWP file for the current objfile.
12375 By convention the name of the DWP file is ${objfile}.dwp.
12376 The result is NULL if it can't be found. */
12378 static std::unique_ptr
<struct dwp_file
>
12379 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12381 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12383 /* Try to find first .dwp for the binary file before any symbolic links
12386 /* If the objfile is a debug file, find the name of the real binary
12387 file and get the name of dwp file from there. */
12388 std::string dwp_name
;
12389 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12391 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12392 const char *backlink_basename
= lbasename (backlink
->original_name
);
12394 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12397 dwp_name
= objfile
->original_name
;
12399 dwp_name
+= ".dwp";
12401 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12403 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12405 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12406 dwp_name
= objfile_name (objfile
);
12407 dwp_name
+= ".dwp";
12408 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12413 if (dwarf_read_debug
)
12414 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12415 return std::unique_ptr
<dwp_file
> ();
12418 const char *name
= bfd_get_filename (dbfd
.get ());
12419 std::unique_ptr
<struct dwp_file
> dwp_file
12420 (new struct dwp_file (name
, std::move (dbfd
)));
12422 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12423 dwp_file
->elf_sections
=
12424 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12425 dwp_file
->num_sections
, asection
*);
12427 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12428 dwarf2_locate_common_dwp_sections
,
12431 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12434 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12437 /* The DWP file version is stored in the hash table. Oh well. */
12438 if (dwp_file
->cus
&& dwp_file
->tus
12439 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12441 /* Technically speaking, we should try to limp along, but this is
12442 pretty bizarre. We use pulongest here because that's the established
12443 portability solution (e.g, we cannot use %u for uint32_t). */
12444 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12445 " TU version %s [in DWP file %s]"),
12446 pulongest (dwp_file
->cus
->version
),
12447 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12451 dwp_file
->version
= dwp_file
->cus
->version
;
12452 else if (dwp_file
->tus
)
12453 dwp_file
->version
= dwp_file
->tus
->version
;
12455 dwp_file
->version
= 2;
12457 if (dwp_file
->version
== 2)
12458 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12459 dwarf2_locate_v2_dwp_sections
,
12462 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12463 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12465 if (dwarf_read_debug
)
12467 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12468 fprintf_unfiltered (gdb_stdlog
,
12469 " %s CUs, %s TUs\n",
12470 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12471 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12477 /* Wrapper around open_and_init_dwp_file, only open it once. */
12479 static struct dwp_file
*
12480 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12482 if (! dwarf2_per_objfile
->dwp_checked
)
12484 dwarf2_per_objfile
->dwp_file
12485 = open_and_init_dwp_file (dwarf2_per_objfile
);
12486 dwarf2_per_objfile
->dwp_checked
= 1;
12488 return dwarf2_per_objfile
->dwp_file
.get ();
12491 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12492 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12493 or in the DWP file for the objfile, referenced by THIS_UNIT.
12494 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12495 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12497 This is called, for example, when wanting to read a variable with a
12498 complex location. Therefore we don't want to do file i/o for every call.
12499 Therefore we don't want to look for a DWO file on every call.
12500 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12501 then we check if we've already seen DWO_NAME, and only THEN do we check
12504 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12505 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12507 static struct dwo_unit
*
12508 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12509 const char *dwo_name
, const char *comp_dir
,
12510 ULONGEST signature
, int is_debug_types
)
12512 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12513 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12514 const char *kind
= is_debug_types
? "TU" : "CU";
12515 void **dwo_file_slot
;
12516 struct dwo_file
*dwo_file
;
12517 struct dwp_file
*dwp_file
;
12519 /* First see if there's a DWP file.
12520 If we have a DWP file but didn't find the DWO inside it, don't
12521 look for the original DWO file. It makes gdb behave differently
12522 depending on whether one is debugging in the build tree. */
12524 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12525 if (dwp_file
!= NULL
)
12527 const struct dwp_hash_table
*dwp_htab
=
12528 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12530 if (dwp_htab
!= NULL
)
12532 struct dwo_unit
*dwo_cutu
=
12533 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12534 signature
, is_debug_types
);
12536 if (dwo_cutu
!= NULL
)
12538 if (dwarf_read_debug
)
12540 fprintf_unfiltered (gdb_stdlog
,
12541 "Virtual DWO %s %s found: @%s\n",
12542 kind
, hex_string (signature
),
12543 host_address_to_string (dwo_cutu
));
12551 /* No DWP file, look for the DWO file. */
12553 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12554 dwo_name
, comp_dir
);
12555 if (*dwo_file_slot
== NULL
)
12557 /* Read in the file and build a table of the CUs/TUs it contains. */
12558 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12560 /* NOTE: This will be NULL if unable to open the file. */
12561 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12563 if (dwo_file
!= NULL
)
12565 struct dwo_unit
*dwo_cutu
= NULL
;
12567 if (is_debug_types
&& dwo_file
->tus
)
12569 struct dwo_unit find_dwo_cutu
;
12571 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12572 find_dwo_cutu
.signature
= signature
;
12574 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12577 else if (!is_debug_types
&& dwo_file
->cus
)
12579 struct dwo_unit find_dwo_cutu
;
12581 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12582 find_dwo_cutu
.signature
= signature
;
12583 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12587 if (dwo_cutu
!= NULL
)
12589 if (dwarf_read_debug
)
12591 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12592 kind
, dwo_name
, hex_string (signature
),
12593 host_address_to_string (dwo_cutu
));
12600 /* We didn't find it. This could mean a dwo_id mismatch, or
12601 someone deleted the DWO/DWP file, or the search path isn't set up
12602 correctly to find the file. */
12604 if (dwarf_read_debug
)
12606 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12607 kind
, dwo_name
, hex_string (signature
));
12610 /* This is a warning and not a complaint because it can be caused by
12611 pilot error (e.g., user accidentally deleting the DWO). */
12613 /* Print the name of the DWP file if we looked there, helps the user
12614 better diagnose the problem. */
12615 std::string dwp_text
;
12617 if (dwp_file
!= NULL
)
12618 dwp_text
= string_printf (" [in DWP file %s]",
12619 lbasename (dwp_file
->name
));
12621 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12622 " [in module %s]"),
12623 kind
, dwo_name
, hex_string (signature
),
12625 this_unit
->is_debug_types
? "TU" : "CU",
12626 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12631 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12632 See lookup_dwo_cutu_unit for details. */
12634 static struct dwo_unit
*
12635 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12636 const char *dwo_name
, const char *comp_dir
,
12637 ULONGEST signature
)
12639 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12642 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12643 See lookup_dwo_cutu_unit for details. */
12645 static struct dwo_unit
*
12646 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12647 const char *dwo_name
, const char *comp_dir
)
12649 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12652 /* Traversal function for queue_and_load_all_dwo_tus. */
12655 queue_and_load_dwo_tu (void **slot
, void *info
)
12657 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12658 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12659 ULONGEST signature
= dwo_unit
->signature
;
12660 struct signatured_type
*sig_type
=
12661 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12663 if (sig_type
!= NULL
)
12665 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12667 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12668 a real dependency of PER_CU on SIG_TYPE. That is detected later
12669 while processing PER_CU. */
12670 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12671 load_full_type_unit (sig_cu
);
12672 per_cu
->imported_symtabs_push (sig_cu
);
12678 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12679 The DWO may have the only definition of the type, though it may not be
12680 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12681 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12684 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12686 struct dwo_unit
*dwo_unit
;
12687 struct dwo_file
*dwo_file
;
12689 gdb_assert (!per_cu
->is_debug_types
);
12690 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12691 gdb_assert (per_cu
->cu
!= NULL
);
12693 dwo_unit
= per_cu
->cu
->dwo_unit
;
12694 gdb_assert (dwo_unit
!= NULL
);
12696 dwo_file
= dwo_unit
->dwo_file
;
12697 if (dwo_file
->tus
!= NULL
)
12698 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12702 /* Read in various DIEs. */
12704 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12705 Inherit only the children of the DW_AT_abstract_origin DIE not being
12706 already referenced by DW_AT_abstract_origin from the children of the
12710 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12712 struct die_info
*child_die
;
12713 sect_offset
*offsetp
;
12714 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12715 struct die_info
*origin_die
;
12716 /* Iterator of the ORIGIN_DIE children. */
12717 struct die_info
*origin_child_die
;
12718 struct attribute
*attr
;
12719 struct dwarf2_cu
*origin_cu
;
12720 struct pending
**origin_previous_list_in_scope
;
12722 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12726 /* Note that following die references may follow to a die in a
12730 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12732 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12734 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12735 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12737 if (die
->tag
!= origin_die
->tag
12738 && !(die
->tag
== DW_TAG_inlined_subroutine
12739 && origin_die
->tag
== DW_TAG_subprogram
))
12740 complaint (_("DIE %s and its abstract origin %s have different tags"),
12741 sect_offset_str (die
->sect_off
),
12742 sect_offset_str (origin_die
->sect_off
));
12744 std::vector
<sect_offset
> offsets
;
12746 for (child_die
= die
->child
;
12747 child_die
&& child_die
->tag
;
12748 child_die
= sibling_die (child_die
))
12750 struct die_info
*child_origin_die
;
12751 struct dwarf2_cu
*child_origin_cu
;
12753 /* We are trying to process concrete instance entries:
12754 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12755 it's not relevant to our analysis here. i.e. detecting DIEs that are
12756 present in the abstract instance but not referenced in the concrete
12758 if (child_die
->tag
== DW_TAG_call_site
12759 || child_die
->tag
== DW_TAG_GNU_call_site
)
12762 /* For each CHILD_DIE, find the corresponding child of
12763 ORIGIN_DIE. If there is more than one layer of
12764 DW_AT_abstract_origin, follow them all; there shouldn't be,
12765 but GCC versions at least through 4.4 generate this (GCC PR
12767 child_origin_die
= child_die
;
12768 child_origin_cu
= cu
;
12771 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12775 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12779 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12780 counterpart may exist. */
12781 if (child_origin_die
!= child_die
)
12783 if (child_die
->tag
!= child_origin_die
->tag
12784 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12785 && child_origin_die
->tag
== DW_TAG_subprogram
))
12786 complaint (_("Child DIE %s and its abstract origin %s have "
12788 sect_offset_str (child_die
->sect_off
),
12789 sect_offset_str (child_origin_die
->sect_off
));
12790 if (child_origin_die
->parent
!= origin_die
)
12791 complaint (_("Child DIE %s and its abstract origin %s have "
12792 "different parents"),
12793 sect_offset_str (child_die
->sect_off
),
12794 sect_offset_str (child_origin_die
->sect_off
));
12796 offsets
.push_back (child_origin_die
->sect_off
);
12799 std::sort (offsets
.begin (), offsets
.end ());
12800 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12801 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12802 if (offsetp
[-1] == *offsetp
)
12803 complaint (_("Multiple children of DIE %s refer "
12804 "to DIE %s as their abstract origin"),
12805 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12807 offsetp
= offsets
.data ();
12808 origin_child_die
= origin_die
->child
;
12809 while (origin_child_die
&& origin_child_die
->tag
)
12811 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12812 while (offsetp
< offsets_end
12813 && *offsetp
< origin_child_die
->sect_off
)
12815 if (offsetp
>= offsets_end
12816 || *offsetp
> origin_child_die
->sect_off
)
12818 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12819 Check whether we're already processing ORIGIN_CHILD_DIE.
12820 This can happen with mutually referenced abstract_origins.
12822 if (!origin_child_die
->in_process
)
12823 process_die (origin_child_die
, origin_cu
);
12825 origin_child_die
= sibling_die (origin_child_die
);
12827 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12829 if (cu
!= origin_cu
)
12830 compute_delayed_physnames (origin_cu
);
12834 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12836 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12837 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12838 struct context_stack
*newobj
;
12841 struct die_info
*child_die
;
12842 struct attribute
*attr
, *call_line
, *call_file
;
12844 CORE_ADDR baseaddr
;
12845 struct block
*block
;
12846 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12847 std::vector
<struct symbol
*> template_args
;
12848 struct template_symbol
*templ_func
= NULL
;
12852 /* If we do not have call site information, we can't show the
12853 caller of this inlined function. That's too confusing, so
12854 only use the scope for local variables. */
12855 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12856 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12857 if (call_line
== NULL
|| call_file
== NULL
)
12859 read_lexical_block_scope (die
, cu
);
12864 baseaddr
= objfile
->text_section_offset ();
12866 name
= dwarf2_name (die
, cu
);
12868 /* Ignore functions with missing or empty names. These are actually
12869 illegal according to the DWARF standard. */
12872 complaint (_("missing name for subprogram DIE at %s"),
12873 sect_offset_str (die
->sect_off
));
12877 /* Ignore functions with missing or invalid low and high pc attributes. */
12878 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12879 <= PC_BOUNDS_INVALID
)
12881 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12882 if (!attr
|| !DW_UNSND (attr
))
12883 complaint (_("cannot get low and high bounds "
12884 "for subprogram DIE at %s"),
12885 sect_offset_str (die
->sect_off
));
12889 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12890 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12892 /* If we have any template arguments, then we must allocate a
12893 different sort of symbol. */
12894 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12896 if (child_die
->tag
== DW_TAG_template_type_param
12897 || child_die
->tag
== DW_TAG_template_value_param
)
12899 templ_func
= allocate_template_symbol (objfile
);
12900 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12905 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12906 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12907 (struct symbol
*) templ_func
);
12909 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12910 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12913 /* If there is a location expression for DW_AT_frame_base, record
12915 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12916 if (attr
!= nullptr)
12917 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12919 /* If there is a location for the static link, record it. */
12920 newobj
->static_link
= NULL
;
12921 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12922 if (attr
!= nullptr)
12924 newobj
->static_link
12925 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12926 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12927 cu
->per_cu
->addr_type ());
12930 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12932 if (die
->child
!= NULL
)
12934 child_die
= die
->child
;
12935 while (child_die
&& child_die
->tag
)
12937 if (child_die
->tag
== DW_TAG_template_type_param
12938 || child_die
->tag
== DW_TAG_template_value_param
)
12940 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12943 template_args
.push_back (arg
);
12946 process_die (child_die
, cu
);
12947 child_die
= sibling_die (child_die
);
12951 inherit_abstract_dies (die
, cu
);
12953 /* If we have a DW_AT_specification, we might need to import using
12954 directives from the context of the specification DIE. See the
12955 comment in determine_prefix. */
12956 if (cu
->language
== language_cplus
12957 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12959 struct dwarf2_cu
*spec_cu
= cu
;
12960 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12964 child_die
= spec_die
->child
;
12965 while (child_die
&& child_die
->tag
)
12967 if (child_die
->tag
== DW_TAG_imported_module
)
12968 process_die (child_die
, spec_cu
);
12969 child_die
= sibling_die (child_die
);
12972 /* In some cases, GCC generates specification DIEs that
12973 themselves contain DW_AT_specification attributes. */
12974 spec_die
= die_specification (spec_die
, &spec_cu
);
12978 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12979 /* Make a block for the local symbols within. */
12980 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12981 cstk
.static_link
, lowpc
, highpc
);
12983 /* For C++, set the block's scope. */
12984 if ((cu
->language
== language_cplus
12985 || cu
->language
== language_fortran
12986 || cu
->language
== language_d
12987 || cu
->language
== language_rust
)
12988 && cu
->processing_has_namespace_info
)
12989 block_set_scope (block
, determine_prefix (die
, cu
),
12990 &objfile
->objfile_obstack
);
12992 /* If we have address ranges, record them. */
12993 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12995 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12997 /* Attach template arguments to function. */
12998 if (!template_args
.empty ())
13000 gdb_assert (templ_func
!= NULL
);
13002 templ_func
->n_template_arguments
= template_args
.size ();
13003 templ_func
->template_arguments
13004 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13005 templ_func
->n_template_arguments
);
13006 memcpy (templ_func
->template_arguments
,
13007 template_args
.data (),
13008 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13010 /* Make sure that the symtab is set on the new symbols. Even
13011 though they don't appear in this symtab directly, other parts
13012 of gdb assume that symbols do, and this is reasonably
13014 for (symbol
*sym
: template_args
)
13015 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13018 /* In C++, we can have functions nested inside functions (e.g., when
13019 a function declares a class that has methods). This means that
13020 when we finish processing a function scope, we may need to go
13021 back to building a containing block's symbol lists. */
13022 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13023 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13025 /* If we've finished processing a top-level function, subsequent
13026 symbols go in the file symbol list. */
13027 if (cu
->get_builder ()->outermost_context_p ())
13028 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13031 /* Process all the DIES contained within a lexical block scope. Start
13032 a new scope, process the dies, and then close the scope. */
13035 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13037 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13038 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13039 CORE_ADDR lowpc
, highpc
;
13040 struct die_info
*child_die
;
13041 CORE_ADDR baseaddr
;
13043 baseaddr
= objfile
->text_section_offset ();
13045 /* Ignore blocks with missing or invalid low and high pc attributes. */
13046 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13047 as multiple lexical blocks? Handling children in a sane way would
13048 be nasty. Might be easier to properly extend generic blocks to
13049 describe ranges. */
13050 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13052 case PC_BOUNDS_NOT_PRESENT
:
13053 /* DW_TAG_lexical_block has no attributes, process its children as if
13054 there was no wrapping by that DW_TAG_lexical_block.
13055 GCC does no longer produces such DWARF since GCC r224161. */
13056 for (child_die
= die
->child
;
13057 child_die
!= NULL
&& child_die
->tag
;
13058 child_die
= sibling_die (child_die
))
13059 process_die (child_die
, cu
);
13061 case PC_BOUNDS_INVALID
:
13064 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13065 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13067 cu
->get_builder ()->push_context (0, lowpc
);
13068 if (die
->child
!= NULL
)
13070 child_die
= die
->child
;
13071 while (child_die
&& child_die
->tag
)
13073 process_die (child_die
, cu
);
13074 child_die
= sibling_die (child_die
);
13077 inherit_abstract_dies (die
, cu
);
13078 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13080 if (*cu
->get_builder ()->get_local_symbols () != NULL
13081 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13083 struct block
*block
13084 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13085 cstk
.start_addr
, highpc
);
13087 /* Note that recording ranges after traversing children, as we
13088 do here, means that recording a parent's ranges entails
13089 walking across all its children's ranges as they appear in
13090 the address map, which is quadratic behavior.
13092 It would be nicer to record the parent's ranges before
13093 traversing its children, simply overriding whatever you find
13094 there. But since we don't even decide whether to create a
13095 block until after we've traversed its children, that's hard
13097 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13099 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13100 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13103 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13106 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13108 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13109 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13110 CORE_ADDR pc
, baseaddr
;
13111 struct attribute
*attr
;
13112 struct call_site
*call_site
, call_site_local
;
13115 struct die_info
*child_die
;
13117 baseaddr
= objfile
->text_section_offset ();
13119 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13122 /* This was a pre-DWARF-5 GNU extension alias
13123 for DW_AT_call_return_pc. */
13124 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13128 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13129 "DIE %s [in module %s]"),
13130 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13133 pc
= attr
->value_as_address () + baseaddr
;
13134 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13136 if (cu
->call_site_htab
== NULL
)
13137 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13138 NULL
, &objfile
->objfile_obstack
,
13139 hashtab_obstack_allocate
, NULL
);
13140 call_site_local
.pc
= pc
;
13141 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13144 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13145 "DIE %s [in module %s]"),
13146 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13147 objfile_name (objfile
));
13151 /* Count parameters at the caller. */
13154 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13155 child_die
= sibling_die (child_die
))
13157 if (child_die
->tag
!= DW_TAG_call_site_parameter
13158 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13160 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13161 "DW_TAG_call_site child DIE %s [in module %s]"),
13162 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13163 objfile_name (objfile
));
13171 = ((struct call_site
*)
13172 obstack_alloc (&objfile
->objfile_obstack
,
13173 sizeof (*call_site
)
13174 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13176 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13177 call_site
->pc
= pc
;
13179 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13180 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13182 struct die_info
*func_die
;
13184 /* Skip also over DW_TAG_inlined_subroutine. */
13185 for (func_die
= die
->parent
;
13186 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13187 && func_die
->tag
!= DW_TAG_subroutine_type
;
13188 func_die
= func_die
->parent
);
13190 /* DW_AT_call_all_calls is a superset
13191 of DW_AT_call_all_tail_calls. */
13193 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13194 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13195 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13196 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13198 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13199 not complete. But keep CALL_SITE for look ups via call_site_htab,
13200 both the initial caller containing the real return address PC and
13201 the final callee containing the current PC of a chain of tail
13202 calls do not need to have the tail call list complete. But any
13203 function candidate for a virtual tail call frame searched via
13204 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13205 determined unambiguously. */
13209 struct type
*func_type
= NULL
;
13212 func_type
= get_die_type (func_die
, cu
);
13213 if (func_type
!= NULL
)
13215 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13217 /* Enlist this call site to the function. */
13218 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13219 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13222 complaint (_("Cannot find function owning DW_TAG_call_site "
13223 "DIE %s [in module %s]"),
13224 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13228 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13230 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13232 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13235 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13236 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13238 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13239 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13240 /* Keep NULL DWARF_BLOCK. */;
13241 else if (attr
->form_is_block ())
13243 struct dwarf2_locexpr_baton
*dlbaton
;
13245 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13246 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13247 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13248 dlbaton
->per_cu
= cu
->per_cu
;
13250 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13252 else if (attr
->form_is_ref ())
13254 struct dwarf2_cu
*target_cu
= cu
;
13255 struct die_info
*target_die
;
13257 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13258 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13259 if (die_is_declaration (target_die
, target_cu
))
13261 const char *target_physname
;
13263 /* Prefer the mangled name; otherwise compute the demangled one. */
13264 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13265 if (target_physname
== NULL
)
13266 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13267 if (target_physname
== NULL
)
13268 complaint (_("DW_AT_call_target target DIE has invalid "
13269 "physname, for referencing DIE %s [in module %s]"),
13270 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13272 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13278 /* DW_AT_entry_pc should be preferred. */
13279 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13280 <= PC_BOUNDS_INVALID
)
13281 complaint (_("DW_AT_call_target target DIE has invalid "
13282 "low pc, for referencing DIE %s [in module %s]"),
13283 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13286 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13287 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13292 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13293 "block nor reference, for DIE %s [in module %s]"),
13294 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13296 call_site
->per_cu
= cu
->per_cu
;
13298 for (child_die
= die
->child
;
13299 child_die
&& child_die
->tag
;
13300 child_die
= sibling_die (child_die
))
13302 struct call_site_parameter
*parameter
;
13303 struct attribute
*loc
, *origin
;
13305 if (child_die
->tag
!= DW_TAG_call_site_parameter
13306 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13308 /* Already printed the complaint above. */
13312 gdb_assert (call_site
->parameter_count
< nparams
);
13313 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13315 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13316 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13317 register is contained in DW_AT_call_value. */
13319 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13320 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13321 if (origin
== NULL
)
13323 /* This was a pre-DWARF-5 GNU extension alias
13324 for DW_AT_call_parameter. */
13325 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13327 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13329 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13331 sect_offset sect_off
13332 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13333 if (!cu
->header
.offset_in_cu_p (sect_off
))
13335 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13336 binding can be done only inside one CU. Such referenced DIE
13337 therefore cannot be even moved to DW_TAG_partial_unit. */
13338 complaint (_("DW_AT_call_parameter offset is not in CU for "
13339 "DW_TAG_call_site child DIE %s [in module %s]"),
13340 sect_offset_str (child_die
->sect_off
),
13341 objfile_name (objfile
));
13344 parameter
->u
.param_cu_off
13345 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13347 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13349 complaint (_("No DW_FORM_block* DW_AT_location for "
13350 "DW_TAG_call_site child DIE %s [in module %s]"),
13351 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13356 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13357 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13358 if (parameter
->u
.dwarf_reg
!= -1)
13359 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13360 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13361 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13362 ¶meter
->u
.fb_offset
))
13363 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13366 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13367 "for DW_FORM_block* DW_AT_location is supported for "
13368 "DW_TAG_call_site child DIE %s "
13370 sect_offset_str (child_die
->sect_off
),
13371 objfile_name (objfile
));
13376 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13378 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13379 if (attr
== NULL
|| !attr
->form_is_block ())
13381 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13382 "DW_TAG_call_site child DIE %s [in module %s]"),
13383 sect_offset_str (child_die
->sect_off
),
13384 objfile_name (objfile
));
13387 parameter
->value
= DW_BLOCK (attr
)->data
;
13388 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13390 /* Parameters are not pre-cleared by memset above. */
13391 parameter
->data_value
= NULL
;
13392 parameter
->data_value_size
= 0;
13393 call_site
->parameter_count
++;
13395 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13397 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13398 if (attr
!= nullptr)
13400 if (!attr
->form_is_block ())
13401 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13402 "DW_TAG_call_site child DIE %s [in module %s]"),
13403 sect_offset_str (child_die
->sect_off
),
13404 objfile_name (objfile
));
13407 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13408 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13414 /* Helper function for read_variable. If DIE represents a virtual
13415 table, then return the type of the concrete object that is
13416 associated with the virtual table. Otherwise, return NULL. */
13418 static struct type
*
13419 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13421 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13425 /* Find the type DIE. */
13426 struct die_info
*type_die
= NULL
;
13427 struct dwarf2_cu
*type_cu
= cu
;
13429 if (attr
->form_is_ref ())
13430 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13431 if (type_die
== NULL
)
13434 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13436 return die_containing_type (type_die
, type_cu
);
13439 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13442 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13444 struct rust_vtable_symbol
*storage
= NULL
;
13446 if (cu
->language
== language_rust
)
13448 struct type
*containing_type
= rust_containing_type (die
, cu
);
13450 if (containing_type
!= NULL
)
13452 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13454 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13455 initialize_objfile_symbol (storage
);
13456 storage
->concrete_type
= containing_type
;
13457 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13461 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13462 struct attribute
*abstract_origin
13463 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13464 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13465 if (res
== NULL
&& loc
&& abstract_origin
)
13467 /* We have a variable without a name, but with a location and an abstract
13468 origin. This may be a concrete instance of an abstract variable
13469 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13471 struct dwarf2_cu
*origin_cu
= cu
;
13472 struct die_info
*origin_die
13473 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13474 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13475 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13479 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13480 reading .debug_rnglists.
13481 Callback's type should be:
13482 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13483 Return true if the attributes are present and valid, otherwise,
13486 template <typename Callback
>
13488 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13489 Callback
&&callback
)
13491 struct dwarf2_per_objfile
*dwarf2_per_objfile
13492 = cu
->per_cu
->dwarf2_per_objfile
;
13493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13494 bfd
*obfd
= objfile
->obfd
;
13495 /* Base address selection entry. */
13498 const gdb_byte
*buffer
;
13499 CORE_ADDR baseaddr
;
13500 bool overflow
= false;
13502 found_base
= cu
->base_known
;
13503 base
= cu
->base_address
;
13505 dwarf2_per_objfile
->rnglists
.read (objfile
);
13506 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13508 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13512 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13514 baseaddr
= objfile
->text_section_offset ();
13518 /* Initialize it due to a false compiler warning. */
13519 CORE_ADDR range_beginning
= 0, range_end
= 0;
13520 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13521 + dwarf2_per_objfile
->rnglists
.size
);
13522 unsigned int bytes_read
;
13524 if (buffer
== buf_end
)
13529 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13532 case DW_RLE_end_of_list
:
13534 case DW_RLE_base_address
:
13535 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13540 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13542 buffer
+= bytes_read
;
13544 case DW_RLE_start_length
:
13545 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13550 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13552 buffer
+= bytes_read
;
13553 range_end
= (range_beginning
13554 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13555 buffer
+= bytes_read
;
13556 if (buffer
> buf_end
)
13562 case DW_RLE_offset_pair
:
13563 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13564 buffer
+= bytes_read
;
13565 if (buffer
> buf_end
)
13570 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13571 buffer
+= bytes_read
;
13572 if (buffer
> buf_end
)
13578 case DW_RLE_start_end
:
13579 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13584 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13586 buffer
+= bytes_read
;
13587 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13588 buffer
+= bytes_read
;
13591 complaint (_("Invalid .debug_rnglists data (no base address)"));
13594 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13596 if (rlet
== DW_RLE_base_address
)
13601 /* We have no valid base address for the ranges
13603 complaint (_("Invalid .debug_rnglists data (no base address)"));
13607 if (range_beginning
> range_end
)
13609 /* Inverted range entries are invalid. */
13610 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13614 /* Empty range entries have no effect. */
13615 if (range_beginning
== range_end
)
13618 range_beginning
+= base
;
13621 /* A not-uncommon case of bad debug info.
13622 Don't pollute the addrmap with bad data. */
13623 if (range_beginning
+ baseaddr
== 0
13624 && !dwarf2_per_objfile
->has_section_at_zero
)
13626 complaint (_(".debug_rnglists entry has start address of zero"
13627 " [in module %s]"), objfile_name (objfile
));
13631 callback (range_beginning
, range_end
);
13636 complaint (_("Offset %d is not terminated "
13637 "for DW_AT_ranges attribute"),
13645 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13646 Callback's type should be:
13647 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13648 Return 1 if the attributes are present and valid, otherwise, return 0. */
13650 template <typename Callback
>
13652 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13653 Callback
&&callback
)
13655 struct dwarf2_per_objfile
*dwarf2_per_objfile
13656 = cu
->per_cu
->dwarf2_per_objfile
;
13657 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13658 struct comp_unit_head
*cu_header
= &cu
->header
;
13659 bfd
*obfd
= objfile
->obfd
;
13660 unsigned int addr_size
= cu_header
->addr_size
;
13661 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13662 /* Base address selection entry. */
13665 unsigned int dummy
;
13666 const gdb_byte
*buffer
;
13667 CORE_ADDR baseaddr
;
13669 if (cu_header
->version
>= 5)
13670 return dwarf2_rnglists_process (offset
, cu
, callback
);
13672 found_base
= cu
->base_known
;
13673 base
= cu
->base_address
;
13675 dwarf2_per_objfile
->ranges
.read (objfile
);
13676 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13678 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13682 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13684 baseaddr
= objfile
->text_section_offset ();
13688 CORE_ADDR range_beginning
, range_end
;
13690 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13691 buffer
+= addr_size
;
13692 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13693 buffer
+= addr_size
;
13694 offset
+= 2 * addr_size
;
13696 /* An end of list marker is a pair of zero addresses. */
13697 if (range_beginning
== 0 && range_end
== 0)
13698 /* Found the end of list entry. */
13701 /* Each base address selection entry is a pair of 2 values.
13702 The first is the largest possible address, the second is
13703 the base address. Check for a base address here. */
13704 if ((range_beginning
& mask
) == mask
)
13706 /* If we found the largest possible address, then we already
13707 have the base address in range_end. */
13715 /* We have no valid base address for the ranges
13717 complaint (_("Invalid .debug_ranges data (no base address)"));
13721 if (range_beginning
> range_end
)
13723 /* Inverted range entries are invalid. */
13724 complaint (_("Invalid .debug_ranges data (inverted range)"));
13728 /* Empty range entries have no effect. */
13729 if (range_beginning
== range_end
)
13732 range_beginning
+= base
;
13735 /* A not-uncommon case of bad debug info.
13736 Don't pollute the addrmap with bad data. */
13737 if (range_beginning
+ baseaddr
== 0
13738 && !dwarf2_per_objfile
->has_section_at_zero
)
13740 complaint (_(".debug_ranges entry has start address of zero"
13741 " [in module %s]"), objfile_name (objfile
));
13745 callback (range_beginning
, range_end
);
13751 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13752 Return 1 if the attributes are present and valid, otherwise, return 0.
13753 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13756 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13757 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13758 dwarf2_psymtab
*ranges_pst
)
13760 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13761 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13762 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13765 CORE_ADDR high
= 0;
13768 retval
= dwarf2_ranges_process (offset
, cu
,
13769 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13771 if (ranges_pst
!= NULL
)
13776 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13777 range_beginning
+ baseaddr
)
13779 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13780 range_end
+ baseaddr
)
13782 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13783 lowpc
, highpc
- 1, ranges_pst
);
13786 /* FIXME: This is recording everything as a low-high
13787 segment of consecutive addresses. We should have a
13788 data structure for discontiguous block ranges
13792 low
= range_beginning
;
13798 if (range_beginning
< low
)
13799 low
= range_beginning
;
13800 if (range_end
> high
)
13808 /* If the first entry is an end-of-list marker, the range
13809 describes an empty scope, i.e. no instructions. */
13815 *high_return
= high
;
13819 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13820 definition for the return value. *LOWPC and *HIGHPC are set iff
13821 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13823 static enum pc_bounds_kind
13824 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13825 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13826 dwarf2_psymtab
*pst
)
13828 struct dwarf2_per_objfile
*dwarf2_per_objfile
13829 = cu
->per_cu
->dwarf2_per_objfile
;
13830 struct attribute
*attr
;
13831 struct attribute
*attr_high
;
13833 CORE_ADDR high
= 0;
13834 enum pc_bounds_kind ret
;
13836 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13839 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13840 if (attr
!= nullptr)
13842 low
= attr
->value_as_address ();
13843 high
= attr_high
->value_as_address ();
13844 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13848 /* Found high w/o low attribute. */
13849 return PC_BOUNDS_INVALID
;
13851 /* Found consecutive range of addresses. */
13852 ret
= PC_BOUNDS_HIGH_LOW
;
13856 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13859 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13860 We take advantage of the fact that DW_AT_ranges does not appear
13861 in DW_TAG_compile_unit of DWO files. */
13862 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13863 unsigned int ranges_offset
= (DW_UNSND (attr
)
13864 + (need_ranges_base
13868 /* Value of the DW_AT_ranges attribute is the offset in the
13869 .debug_ranges section. */
13870 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13871 return PC_BOUNDS_INVALID
;
13872 /* Found discontinuous range of addresses. */
13873 ret
= PC_BOUNDS_RANGES
;
13876 return PC_BOUNDS_NOT_PRESENT
;
13879 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13881 return PC_BOUNDS_INVALID
;
13883 /* When using the GNU linker, .gnu.linkonce. sections are used to
13884 eliminate duplicate copies of functions and vtables and such.
13885 The linker will arbitrarily choose one and discard the others.
13886 The AT_*_pc values for such functions refer to local labels in
13887 these sections. If the section from that file was discarded, the
13888 labels are not in the output, so the relocs get a value of 0.
13889 If this is a discarded function, mark the pc bounds as invalid,
13890 so that GDB will ignore it. */
13891 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13892 return PC_BOUNDS_INVALID
;
13900 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13901 its low and high PC addresses. Do nothing if these addresses could not
13902 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13903 and HIGHPC to the high address if greater than HIGHPC. */
13906 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13907 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13908 struct dwarf2_cu
*cu
)
13910 CORE_ADDR low
, high
;
13911 struct die_info
*child
= die
->child
;
13913 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13915 *lowpc
= std::min (*lowpc
, low
);
13916 *highpc
= std::max (*highpc
, high
);
13919 /* If the language does not allow nested subprograms (either inside
13920 subprograms or lexical blocks), we're done. */
13921 if (cu
->language
!= language_ada
)
13924 /* Check all the children of the given DIE. If it contains nested
13925 subprograms, then check their pc bounds. Likewise, we need to
13926 check lexical blocks as well, as they may also contain subprogram
13928 while (child
&& child
->tag
)
13930 if (child
->tag
== DW_TAG_subprogram
13931 || child
->tag
== DW_TAG_lexical_block
)
13932 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13933 child
= sibling_die (child
);
13937 /* Get the low and high pc's represented by the scope DIE, and store
13938 them in *LOWPC and *HIGHPC. If the correct values can't be
13939 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13942 get_scope_pc_bounds (struct die_info
*die
,
13943 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13944 struct dwarf2_cu
*cu
)
13946 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13947 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13948 CORE_ADDR current_low
, current_high
;
13950 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13951 >= PC_BOUNDS_RANGES
)
13953 best_low
= current_low
;
13954 best_high
= current_high
;
13958 struct die_info
*child
= die
->child
;
13960 while (child
&& child
->tag
)
13962 switch (child
->tag
) {
13963 case DW_TAG_subprogram
:
13964 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13966 case DW_TAG_namespace
:
13967 case DW_TAG_module
:
13968 /* FIXME: carlton/2004-01-16: Should we do this for
13969 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13970 that current GCC's always emit the DIEs corresponding
13971 to definitions of methods of classes as children of a
13972 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13973 the DIEs giving the declarations, which could be
13974 anywhere). But I don't see any reason why the
13975 standards says that they have to be there. */
13976 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13978 if (current_low
!= ((CORE_ADDR
) -1))
13980 best_low
= std::min (best_low
, current_low
);
13981 best_high
= std::max (best_high
, current_high
);
13989 child
= sibling_die (child
);
13994 *highpc
= best_high
;
13997 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14001 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14002 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14004 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14005 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14006 struct attribute
*attr
;
14007 struct attribute
*attr_high
;
14009 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14012 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14013 if (attr
!= nullptr)
14015 CORE_ADDR low
= attr
->value_as_address ();
14016 CORE_ADDR high
= attr_high
->value_as_address ();
14018 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14021 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14022 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14023 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14027 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14028 if (attr
!= nullptr)
14030 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14031 We take advantage of the fact that DW_AT_ranges does not appear
14032 in DW_TAG_compile_unit of DWO files. */
14033 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14035 /* The value of the DW_AT_ranges attribute is the offset of the
14036 address range list in the .debug_ranges section. */
14037 unsigned long offset
= (DW_UNSND (attr
)
14038 + (need_ranges_base
? cu
->ranges_base
: 0));
14040 std::vector
<blockrange
> blockvec
;
14041 dwarf2_ranges_process (offset
, cu
,
14042 [&] (CORE_ADDR start
, CORE_ADDR end
)
14046 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14047 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14048 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14049 blockvec
.emplace_back (start
, end
);
14052 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14056 /* Check whether the producer field indicates either of GCC < 4.6, or the
14057 Intel C/C++ compiler, and cache the result in CU. */
14060 check_producer (struct dwarf2_cu
*cu
)
14064 if (cu
->producer
== NULL
)
14066 /* For unknown compilers expect their behavior is DWARF version
14069 GCC started to support .debug_types sections by -gdwarf-4 since
14070 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14071 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14072 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14073 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14075 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14077 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14078 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14080 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14082 cu
->producer_is_icc
= true;
14083 cu
->producer_is_icc_lt_14
= major
< 14;
14085 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14086 cu
->producer_is_codewarrior
= true;
14089 /* For other non-GCC compilers, expect their behavior is DWARF version
14093 cu
->checked_producer
= true;
14096 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14097 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14098 during 4.6.0 experimental. */
14101 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14103 if (!cu
->checked_producer
)
14104 check_producer (cu
);
14106 return cu
->producer_is_gxx_lt_4_6
;
14110 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14111 with incorrect is_stmt attributes. */
14114 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14116 if (!cu
->checked_producer
)
14117 check_producer (cu
);
14119 return cu
->producer_is_codewarrior
;
14122 /* Return the default accessibility type if it is not overridden by
14123 DW_AT_accessibility. */
14125 static enum dwarf_access_attribute
14126 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14128 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14130 /* The default DWARF 2 accessibility for members is public, the default
14131 accessibility for inheritance is private. */
14133 if (die
->tag
!= DW_TAG_inheritance
)
14134 return DW_ACCESS_public
;
14136 return DW_ACCESS_private
;
14140 /* DWARF 3+ defines the default accessibility a different way. The same
14141 rules apply now for DW_TAG_inheritance as for the members and it only
14142 depends on the container kind. */
14144 if (die
->parent
->tag
== DW_TAG_class_type
)
14145 return DW_ACCESS_private
;
14147 return DW_ACCESS_public
;
14151 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14152 offset. If the attribute was not found return 0, otherwise return
14153 1. If it was found but could not properly be handled, set *OFFSET
14157 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14160 struct attribute
*attr
;
14162 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14167 /* Note that we do not check for a section offset first here.
14168 This is because DW_AT_data_member_location is new in DWARF 4,
14169 so if we see it, we can assume that a constant form is really
14170 a constant and not a section offset. */
14171 if (attr
->form_is_constant ())
14172 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14173 else if (attr
->form_is_section_offset ())
14174 dwarf2_complex_location_expr_complaint ();
14175 else if (attr
->form_is_block ())
14176 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14178 dwarf2_complex_location_expr_complaint ();
14186 /* Add an aggregate field to the field list. */
14189 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14190 struct dwarf2_cu
*cu
)
14192 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14193 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14194 struct nextfield
*new_field
;
14195 struct attribute
*attr
;
14197 const char *fieldname
= "";
14199 if (die
->tag
== DW_TAG_inheritance
)
14201 fip
->baseclasses
.emplace_back ();
14202 new_field
= &fip
->baseclasses
.back ();
14206 fip
->fields
.emplace_back ();
14207 new_field
= &fip
->fields
.back ();
14210 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14211 if (attr
!= nullptr)
14212 new_field
->accessibility
= DW_UNSND (attr
);
14214 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14215 if (new_field
->accessibility
!= DW_ACCESS_public
)
14216 fip
->non_public_fields
= 1;
14218 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14219 if (attr
!= nullptr)
14220 new_field
->virtuality
= DW_UNSND (attr
);
14222 new_field
->virtuality
= DW_VIRTUALITY_none
;
14224 fp
= &new_field
->field
;
14226 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14230 /* Data member other than a C++ static data member. */
14232 /* Get type of field. */
14233 fp
->type
= die_type (die
, cu
);
14235 SET_FIELD_BITPOS (*fp
, 0);
14237 /* Get bit size of field (zero if none). */
14238 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14239 if (attr
!= nullptr)
14241 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14245 FIELD_BITSIZE (*fp
) = 0;
14248 /* Get bit offset of field. */
14249 if (handle_data_member_location (die
, cu
, &offset
))
14250 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14251 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14252 if (attr
!= nullptr)
14254 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14256 /* For big endian bits, the DW_AT_bit_offset gives the
14257 additional bit offset from the MSB of the containing
14258 anonymous object to the MSB of the field. We don't
14259 have to do anything special since we don't need to
14260 know the size of the anonymous object. */
14261 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14265 /* For little endian bits, compute the bit offset to the
14266 MSB of the anonymous object, subtract off the number of
14267 bits from the MSB of the field to the MSB of the
14268 object, and then subtract off the number of bits of
14269 the field itself. The result is the bit offset of
14270 the LSB of the field. */
14271 int anonymous_size
;
14272 int bit_offset
= DW_UNSND (attr
);
14274 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14275 if (attr
!= nullptr)
14277 /* The size of the anonymous object containing
14278 the bit field is explicit, so use the
14279 indicated size (in bytes). */
14280 anonymous_size
= DW_UNSND (attr
);
14284 /* The size of the anonymous object containing
14285 the bit field must be inferred from the type
14286 attribute of the data member containing the
14288 anonymous_size
= TYPE_LENGTH (fp
->type
);
14290 SET_FIELD_BITPOS (*fp
,
14291 (FIELD_BITPOS (*fp
)
14292 + anonymous_size
* bits_per_byte
14293 - bit_offset
- FIELD_BITSIZE (*fp
)));
14296 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14298 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14299 + dwarf2_get_attr_constant_value (attr
, 0)));
14301 /* Get name of field. */
14302 fieldname
= dwarf2_name (die
, cu
);
14303 if (fieldname
== NULL
)
14306 /* The name is already allocated along with this objfile, so we don't
14307 need to duplicate it for the type. */
14308 fp
->name
= fieldname
;
14310 /* Change accessibility for artificial fields (e.g. virtual table
14311 pointer or virtual base class pointer) to private. */
14312 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14314 FIELD_ARTIFICIAL (*fp
) = 1;
14315 new_field
->accessibility
= DW_ACCESS_private
;
14316 fip
->non_public_fields
= 1;
14319 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14321 /* C++ static member. */
14323 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14324 is a declaration, but all versions of G++ as of this writing
14325 (so through at least 3.2.1) incorrectly generate
14326 DW_TAG_variable tags. */
14328 const char *physname
;
14330 /* Get name of field. */
14331 fieldname
= dwarf2_name (die
, cu
);
14332 if (fieldname
== NULL
)
14335 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14337 /* Only create a symbol if this is an external value.
14338 new_symbol checks this and puts the value in the global symbol
14339 table, which we want. If it is not external, new_symbol
14340 will try to put the value in cu->list_in_scope which is wrong. */
14341 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14343 /* A static const member, not much different than an enum as far as
14344 we're concerned, except that we can support more types. */
14345 new_symbol (die
, NULL
, cu
);
14348 /* Get physical name. */
14349 physname
= dwarf2_physname (fieldname
, die
, cu
);
14351 /* The name is already allocated along with this objfile, so we don't
14352 need to duplicate it for the type. */
14353 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14354 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14355 FIELD_NAME (*fp
) = fieldname
;
14357 else if (die
->tag
== DW_TAG_inheritance
)
14361 /* C++ base class field. */
14362 if (handle_data_member_location (die
, cu
, &offset
))
14363 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14364 FIELD_BITSIZE (*fp
) = 0;
14365 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14366 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14368 else if (die
->tag
== DW_TAG_variant_part
)
14370 /* process_structure_scope will treat this DIE as a union. */
14371 process_structure_scope (die
, cu
);
14373 /* The variant part is relative to the start of the enclosing
14375 SET_FIELD_BITPOS (*fp
, 0);
14376 fp
->type
= get_die_type (die
, cu
);
14377 fp
->artificial
= 1;
14378 fp
->name
= "<<variant>>";
14380 /* Normally a DW_TAG_variant_part won't have a size, but our
14381 representation requires one, so set it to the maximum of the
14382 child sizes, being sure to account for the offset at which
14383 each child is seen. */
14384 if (TYPE_LENGTH (fp
->type
) == 0)
14387 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14389 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14390 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14394 TYPE_LENGTH (fp
->type
) = max
;
14398 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14401 /* Can the type given by DIE define another type? */
14404 type_can_define_types (const struct die_info
*die
)
14408 case DW_TAG_typedef
:
14409 case DW_TAG_class_type
:
14410 case DW_TAG_structure_type
:
14411 case DW_TAG_union_type
:
14412 case DW_TAG_enumeration_type
:
14420 /* Add a type definition defined in the scope of the FIP's class. */
14423 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14424 struct dwarf2_cu
*cu
)
14426 struct decl_field fp
;
14427 memset (&fp
, 0, sizeof (fp
));
14429 gdb_assert (type_can_define_types (die
));
14431 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14432 fp
.name
= dwarf2_name (die
, cu
);
14433 fp
.type
= read_type_die (die
, cu
);
14435 /* Save accessibility. */
14436 enum dwarf_access_attribute accessibility
;
14437 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14439 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14441 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14442 switch (accessibility
)
14444 case DW_ACCESS_public
:
14445 /* The assumed value if neither private nor protected. */
14447 case DW_ACCESS_private
:
14450 case DW_ACCESS_protected
:
14451 fp
.is_protected
= 1;
14454 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14457 if (die
->tag
== DW_TAG_typedef
)
14458 fip
->typedef_field_list
.push_back (fp
);
14460 fip
->nested_types_list
.push_back (fp
);
14463 /* Create the vector of fields, and attach it to the type. */
14466 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14467 struct dwarf2_cu
*cu
)
14469 int nfields
= fip
->nfields ();
14471 /* Record the field count, allocate space for the array of fields,
14472 and create blank accessibility bitfields if necessary. */
14473 TYPE_NFIELDS (type
) = nfields
;
14474 TYPE_FIELDS (type
) = (struct field
*)
14475 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14477 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14479 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14481 TYPE_FIELD_PRIVATE_BITS (type
) =
14482 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14483 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14485 TYPE_FIELD_PROTECTED_BITS (type
) =
14486 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14487 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14489 TYPE_FIELD_IGNORE_BITS (type
) =
14490 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14491 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14494 /* If the type has baseclasses, allocate and clear a bit vector for
14495 TYPE_FIELD_VIRTUAL_BITS. */
14496 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14498 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14499 unsigned char *pointer
;
14501 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14502 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14503 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14504 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14505 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14508 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14510 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14512 for (int index
= 0; index
< nfields
; ++index
)
14514 struct nextfield
&field
= fip
->fields
[index
];
14516 if (field
.variant
.is_discriminant
)
14517 di
->discriminant_index
= index
;
14518 else if (field
.variant
.default_branch
)
14519 di
->default_index
= index
;
14521 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14525 /* Copy the saved-up fields into the field vector. */
14526 for (int i
= 0; i
< nfields
; ++i
)
14528 struct nextfield
&field
14529 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14530 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14532 TYPE_FIELD (type
, i
) = field
.field
;
14533 switch (field
.accessibility
)
14535 case DW_ACCESS_private
:
14536 if (cu
->language
!= language_ada
)
14537 SET_TYPE_FIELD_PRIVATE (type
, i
);
14540 case DW_ACCESS_protected
:
14541 if (cu
->language
!= language_ada
)
14542 SET_TYPE_FIELD_PROTECTED (type
, i
);
14545 case DW_ACCESS_public
:
14549 /* Unknown accessibility. Complain and treat it as public. */
14551 complaint (_("unsupported accessibility %d"),
14552 field
.accessibility
);
14556 if (i
< fip
->baseclasses
.size ())
14558 switch (field
.virtuality
)
14560 case DW_VIRTUALITY_virtual
:
14561 case DW_VIRTUALITY_pure_virtual
:
14562 if (cu
->language
== language_ada
)
14563 error (_("unexpected virtuality in component of Ada type"));
14564 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14571 /* Return true if this member function is a constructor, false
14575 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14577 const char *fieldname
;
14578 const char *type_name
;
14581 if (die
->parent
== NULL
)
14584 if (die
->parent
->tag
!= DW_TAG_structure_type
14585 && die
->parent
->tag
!= DW_TAG_union_type
14586 && die
->parent
->tag
!= DW_TAG_class_type
)
14589 fieldname
= dwarf2_name (die
, cu
);
14590 type_name
= dwarf2_name (die
->parent
, cu
);
14591 if (fieldname
== NULL
|| type_name
== NULL
)
14594 len
= strlen (fieldname
);
14595 return (strncmp (fieldname
, type_name
, len
) == 0
14596 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14599 /* Check if the given VALUE is a recognized enum
14600 dwarf_defaulted_attribute constant according to DWARF5 spec,
14604 is_valid_DW_AT_defaulted (ULONGEST value
)
14608 case DW_DEFAULTED_no
:
14609 case DW_DEFAULTED_in_class
:
14610 case DW_DEFAULTED_out_of_class
:
14614 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14618 /* Add a member function to the proper fieldlist. */
14621 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14622 struct type
*type
, struct dwarf2_cu
*cu
)
14624 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14625 struct attribute
*attr
;
14627 struct fnfieldlist
*flp
= nullptr;
14628 struct fn_field
*fnp
;
14629 const char *fieldname
;
14630 struct type
*this_type
;
14631 enum dwarf_access_attribute accessibility
;
14633 if (cu
->language
== language_ada
)
14634 error (_("unexpected member function in Ada type"));
14636 /* Get name of member function. */
14637 fieldname
= dwarf2_name (die
, cu
);
14638 if (fieldname
== NULL
)
14641 /* Look up member function name in fieldlist. */
14642 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14644 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14646 flp
= &fip
->fnfieldlists
[i
];
14651 /* Create a new fnfieldlist if necessary. */
14652 if (flp
== nullptr)
14654 fip
->fnfieldlists
.emplace_back ();
14655 flp
= &fip
->fnfieldlists
.back ();
14656 flp
->name
= fieldname
;
14657 i
= fip
->fnfieldlists
.size () - 1;
14660 /* Create a new member function field and add it to the vector of
14662 flp
->fnfields
.emplace_back ();
14663 fnp
= &flp
->fnfields
.back ();
14665 /* Delay processing of the physname until later. */
14666 if (cu
->language
== language_cplus
)
14667 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14671 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14672 fnp
->physname
= physname
? physname
: "";
14675 fnp
->type
= alloc_type (objfile
);
14676 this_type
= read_type_die (die
, cu
);
14677 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14679 int nparams
= TYPE_NFIELDS (this_type
);
14681 /* TYPE is the domain of this method, and THIS_TYPE is the type
14682 of the method itself (TYPE_CODE_METHOD). */
14683 smash_to_method_type (fnp
->type
, type
,
14684 TYPE_TARGET_TYPE (this_type
),
14685 TYPE_FIELDS (this_type
),
14686 TYPE_NFIELDS (this_type
),
14687 TYPE_VARARGS (this_type
));
14689 /* Handle static member functions.
14690 Dwarf2 has no clean way to discern C++ static and non-static
14691 member functions. G++ helps GDB by marking the first
14692 parameter for non-static member functions (which is the this
14693 pointer) as artificial. We obtain this information from
14694 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14695 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14696 fnp
->voffset
= VOFFSET_STATIC
;
14699 complaint (_("member function type missing for '%s'"),
14700 dwarf2_full_name (fieldname
, die
, cu
));
14702 /* Get fcontext from DW_AT_containing_type if present. */
14703 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14704 fnp
->fcontext
= die_containing_type (die
, cu
);
14706 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14707 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14709 /* Get accessibility. */
14710 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14711 if (attr
!= nullptr)
14712 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14714 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14715 switch (accessibility
)
14717 case DW_ACCESS_private
:
14718 fnp
->is_private
= 1;
14720 case DW_ACCESS_protected
:
14721 fnp
->is_protected
= 1;
14725 /* Check for artificial methods. */
14726 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14727 if (attr
&& DW_UNSND (attr
) != 0)
14728 fnp
->is_artificial
= 1;
14730 /* Check for defaulted methods. */
14731 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14732 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14733 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14735 /* Check for deleted methods. */
14736 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14737 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14738 fnp
->is_deleted
= 1;
14740 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14742 /* Get index in virtual function table if it is a virtual member
14743 function. For older versions of GCC, this is an offset in the
14744 appropriate virtual table, as specified by DW_AT_containing_type.
14745 For everyone else, it is an expression to be evaluated relative
14746 to the object address. */
14748 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14749 if (attr
!= nullptr)
14751 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14753 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14755 /* Old-style GCC. */
14756 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14758 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14759 || (DW_BLOCK (attr
)->size
> 1
14760 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14761 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14763 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14764 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14765 dwarf2_complex_location_expr_complaint ();
14767 fnp
->voffset
/= cu
->header
.addr_size
;
14771 dwarf2_complex_location_expr_complaint ();
14773 if (!fnp
->fcontext
)
14775 /* If there is no `this' field and no DW_AT_containing_type,
14776 we cannot actually find a base class context for the
14778 if (TYPE_NFIELDS (this_type
) == 0
14779 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14781 complaint (_("cannot determine context for virtual member "
14782 "function \"%s\" (offset %s)"),
14783 fieldname
, sect_offset_str (die
->sect_off
));
14788 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14792 else if (attr
->form_is_section_offset ())
14794 dwarf2_complex_location_expr_complaint ();
14798 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14804 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14805 if (attr
&& DW_UNSND (attr
))
14807 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14808 complaint (_("Member function \"%s\" (offset %s) is virtual "
14809 "but the vtable offset is not specified"),
14810 fieldname
, sect_offset_str (die
->sect_off
));
14811 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14812 TYPE_CPLUS_DYNAMIC (type
) = 1;
14817 /* Create the vector of member function fields, and attach it to the type. */
14820 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14821 struct dwarf2_cu
*cu
)
14823 if (cu
->language
== language_ada
)
14824 error (_("unexpected member functions in Ada type"));
14826 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14827 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14829 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14831 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14833 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14834 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14836 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14837 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14838 fn_flp
->fn_fields
= (struct fn_field
*)
14839 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14841 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14842 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14845 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14848 /* Returns non-zero if NAME is the name of a vtable member in CU's
14849 language, zero otherwise. */
14851 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14853 static const char vptr
[] = "_vptr";
14855 /* Look for the C++ form of the vtable. */
14856 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14862 /* GCC outputs unnamed structures that are really pointers to member
14863 functions, with the ABI-specified layout. If TYPE describes
14864 such a structure, smash it into a member function type.
14866 GCC shouldn't do this; it should just output pointer to member DIEs.
14867 This is GCC PR debug/28767. */
14870 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14872 struct type
*pfn_type
, *self_type
, *new_type
;
14874 /* Check for a structure with no name and two children. */
14875 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14878 /* Check for __pfn and __delta members. */
14879 if (TYPE_FIELD_NAME (type
, 0) == NULL
14880 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14881 || TYPE_FIELD_NAME (type
, 1) == NULL
14882 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14885 /* Find the type of the method. */
14886 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14887 if (pfn_type
== NULL
14888 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14889 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14892 /* Look for the "this" argument. */
14893 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14894 if (TYPE_NFIELDS (pfn_type
) == 0
14895 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14896 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14899 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14900 new_type
= alloc_type (objfile
);
14901 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14902 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14903 TYPE_VARARGS (pfn_type
));
14904 smash_to_methodptr_type (type
, new_type
);
14907 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14908 appropriate error checking and issuing complaints if there is a
14912 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14914 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14916 if (attr
== nullptr)
14919 if (!attr
->form_is_constant ())
14921 complaint (_("DW_AT_alignment must have constant form"
14922 " - DIE at %s [in module %s]"),
14923 sect_offset_str (die
->sect_off
),
14924 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14929 if (attr
->form
== DW_FORM_sdata
)
14931 LONGEST val
= DW_SND (attr
);
14934 complaint (_("DW_AT_alignment value must not be negative"
14935 " - DIE at %s [in module %s]"),
14936 sect_offset_str (die
->sect_off
),
14937 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14943 align
= DW_UNSND (attr
);
14947 complaint (_("DW_AT_alignment value must not be zero"
14948 " - DIE at %s [in module %s]"),
14949 sect_offset_str (die
->sect_off
),
14950 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14953 if ((align
& (align
- 1)) != 0)
14955 complaint (_("DW_AT_alignment value must be a power of 2"
14956 " - DIE at %s [in module %s]"),
14957 sect_offset_str (die
->sect_off
),
14958 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14965 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14966 the alignment for TYPE. */
14969 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14972 if (!set_type_align (type
, get_alignment (cu
, die
)))
14973 complaint (_("DW_AT_alignment value too large"
14974 " - DIE at %s [in module %s]"),
14975 sect_offset_str (die
->sect_off
),
14976 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14979 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14980 constant for a type, according to DWARF5 spec, Table 5.5. */
14983 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14988 case DW_CC_pass_by_reference
:
14989 case DW_CC_pass_by_value
:
14993 complaint (_("unrecognized DW_AT_calling_convention value "
14994 "(%s) for a type"), pulongest (value
));
14999 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15000 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15001 also according to GNU-specific values (see include/dwarf2.h). */
15004 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15009 case DW_CC_program
:
15013 case DW_CC_GNU_renesas_sh
:
15014 case DW_CC_GNU_borland_fastcall_i386
:
15015 case DW_CC_GDB_IBM_OpenCL
:
15019 complaint (_("unrecognized DW_AT_calling_convention value "
15020 "(%s) for a subroutine"), pulongest (value
));
15025 /* Called when we find the DIE that starts a structure or union scope
15026 (definition) to create a type for the structure or union. Fill in
15027 the type's name and general properties; the members will not be
15028 processed until process_structure_scope. A symbol table entry for
15029 the type will also not be done until process_structure_scope (assuming
15030 the type has a name).
15032 NOTE: we need to call these functions regardless of whether or not the
15033 DIE has a DW_AT_name attribute, since it might be an anonymous
15034 structure or union. This gets the type entered into our set of
15035 user defined types. */
15037 static struct type
*
15038 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15040 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15042 struct attribute
*attr
;
15045 /* If the definition of this type lives in .debug_types, read that type.
15046 Don't follow DW_AT_specification though, that will take us back up
15047 the chain and we want to go down. */
15048 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15049 if (attr
!= nullptr)
15051 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15053 /* The type's CU may not be the same as CU.
15054 Ensure TYPE is recorded with CU in die_type_hash. */
15055 return set_die_type (die
, type
, cu
);
15058 type
= alloc_type (objfile
);
15059 INIT_CPLUS_SPECIFIC (type
);
15061 name
= dwarf2_name (die
, cu
);
15064 if (cu
->language
== language_cplus
15065 || cu
->language
== language_d
15066 || cu
->language
== language_rust
)
15068 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15070 /* dwarf2_full_name might have already finished building the DIE's
15071 type. If so, there is no need to continue. */
15072 if (get_die_type (die
, cu
) != NULL
)
15073 return get_die_type (die
, cu
);
15075 TYPE_NAME (type
) = full_name
;
15079 /* The name is already allocated along with this objfile, so
15080 we don't need to duplicate it for the type. */
15081 TYPE_NAME (type
) = name
;
15085 if (die
->tag
== DW_TAG_structure_type
)
15087 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15089 else if (die
->tag
== DW_TAG_union_type
)
15091 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15093 else if (die
->tag
== DW_TAG_variant_part
)
15095 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15096 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15100 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15103 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15104 TYPE_DECLARED_CLASS (type
) = 1;
15106 /* Store the calling convention in the type if it's available in
15107 the die. Otherwise the calling convention remains set to
15108 the default value DW_CC_normal. */
15109 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15110 if (attr
!= nullptr
15111 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15113 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15114 TYPE_CPLUS_CALLING_CONVENTION (type
)
15115 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15118 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15119 if (attr
!= nullptr)
15121 if (attr
->form_is_constant ())
15122 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15125 /* For the moment, dynamic type sizes are not supported
15126 by GDB's struct type. The actual size is determined
15127 on-demand when resolving the type of a given object,
15128 so set the type's length to zero for now. Otherwise,
15129 we record an expression as the length, and that expression
15130 could lead to a very large value, which could eventually
15131 lead to us trying to allocate that much memory when creating
15132 a value of that type. */
15133 TYPE_LENGTH (type
) = 0;
15138 TYPE_LENGTH (type
) = 0;
15141 maybe_set_alignment (cu
, die
, type
);
15143 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15145 /* ICC<14 does not output the required DW_AT_declaration on
15146 incomplete types, but gives them a size of zero. */
15147 TYPE_STUB (type
) = 1;
15150 TYPE_STUB_SUPPORTED (type
) = 1;
15152 if (die_is_declaration (die
, cu
))
15153 TYPE_STUB (type
) = 1;
15154 else if (attr
== NULL
&& die
->child
== NULL
15155 && producer_is_realview (cu
->producer
))
15156 /* RealView does not output the required DW_AT_declaration
15157 on incomplete types. */
15158 TYPE_STUB (type
) = 1;
15160 /* We need to add the type field to the die immediately so we don't
15161 infinitely recurse when dealing with pointers to the structure
15162 type within the structure itself. */
15163 set_die_type (die
, type
, cu
);
15165 /* set_die_type should be already done. */
15166 set_descriptive_type (type
, die
, cu
);
15171 /* A helper for process_structure_scope that handles a single member
15175 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15176 struct field_info
*fi
,
15177 std::vector
<struct symbol
*> *template_args
,
15178 struct dwarf2_cu
*cu
)
15180 if (child_die
->tag
== DW_TAG_member
15181 || child_die
->tag
== DW_TAG_variable
15182 || child_die
->tag
== DW_TAG_variant_part
)
15184 /* NOTE: carlton/2002-11-05: A C++ static data member
15185 should be a DW_TAG_member that is a declaration, but
15186 all versions of G++ as of this writing (so through at
15187 least 3.2.1) incorrectly generate DW_TAG_variable
15188 tags for them instead. */
15189 dwarf2_add_field (fi
, child_die
, cu
);
15191 else if (child_die
->tag
== DW_TAG_subprogram
)
15193 /* Rust doesn't have member functions in the C++ sense.
15194 However, it does emit ordinary functions as children
15195 of a struct DIE. */
15196 if (cu
->language
== language_rust
)
15197 read_func_scope (child_die
, cu
);
15200 /* C++ member function. */
15201 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15204 else if (child_die
->tag
== DW_TAG_inheritance
)
15206 /* C++ base class field. */
15207 dwarf2_add_field (fi
, child_die
, cu
);
15209 else if (type_can_define_types (child_die
))
15210 dwarf2_add_type_defn (fi
, child_die
, cu
);
15211 else if (child_die
->tag
== DW_TAG_template_type_param
15212 || child_die
->tag
== DW_TAG_template_value_param
)
15214 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15217 template_args
->push_back (arg
);
15219 else if (child_die
->tag
== DW_TAG_variant
)
15221 /* In a variant we want to get the discriminant and also add a
15222 field for our sole member child. */
15223 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15225 for (die_info
*variant_child
= child_die
->child
;
15226 variant_child
!= NULL
;
15227 variant_child
= sibling_die (variant_child
))
15229 if (variant_child
->tag
== DW_TAG_member
)
15231 handle_struct_member_die (variant_child
, type
, fi
,
15232 template_args
, cu
);
15233 /* Only handle the one. */
15238 /* We don't handle this but we might as well report it if we see
15240 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15241 complaint (_("DW_AT_discr_list is not supported yet"
15242 " - DIE at %s [in module %s]"),
15243 sect_offset_str (child_die
->sect_off
),
15244 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15246 /* The first field was just added, so we can stash the
15247 discriminant there. */
15248 gdb_assert (!fi
->fields
.empty ());
15250 fi
->fields
.back ().variant
.default_branch
= true;
15252 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15256 /* Finish creating a structure or union type, including filling in
15257 its members and creating a symbol for it. */
15260 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15262 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15263 struct die_info
*child_die
;
15266 type
= get_die_type (die
, cu
);
15268 type
= read_structure_type (die
, cu
);
15270 /* When reading a DW_TAG_variant_part, we need to notice when we
15271 read the discriminant member, so we can record it later in the
15272 discriminant_info. */
15273 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15274 sect_offset discr_offset
{};
15275 bool has_template_parameters
= false;
15277 if (is_variant_part
)
15279 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15282 /* Maybe it's a univariant form, an extension we support.
15283 In this case arrange not to check the offset. */
15284 is_variant_part
= false;
15286 else if (discr
->form_is_ref ())
15288 struct dwarf2_cu
*target_cu
= cu
;
15289 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15291 discr_offset
= target_die
->sect_off
;
15295 complaint (_("DW_AT_discr does not have DIE reference form"
15296 " - DIE at %s [in module %s]"),
15297 sect_offset_str (die
->sect_off
),
15298 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15299 is_variant_part
= false;
15303 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15305 struct field_info fi
;
15306 std::vector
<struct symbol
*> template_args
;
15308 child_die
= die
->child
;
15310 while (child_die
&& child_die
->tag
)
15312 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15314 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15315 fi
.fields
.back ().variant
.is_discriminant
= true;
15317 child_die
= sibling_die (child_die
);
15320 /* Attach template arguments to type. */
15321 if (!template_args
.empty ())
15323 has_template_parameters
= true;
15324 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15325 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15326 TYPE_TEMPLATE_ARGUMENTS (type
)
15327 = XOBNEWVEC (&objfile
->objfile_obstack
,
15329 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15330 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15331 template_args
.data (),
15332 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15333 * sizeof (struct symbol
*)));
15336 /* Attach fields and member functions to the type. */
15337 if (fi
.nfields () > 0)
15338 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15339 if (!fi
.fnfieldlists
.empty ())
15341 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15343 /* Get the type which refers to the base class (possibly this
15344 class itself) which contains the vtable pointer for the current
15345 class from the DW_AT_containing_type attribute. This use of
15346 DW_AT_containing_type is a GNU extension. */
15348 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15350 struct type
*t
= die_containing_type (die
, cu
);
15352 set_type_vptr_basetype (type
, t
);
15357 /* Our own class provides vtbl ptr. */
15358 for (i
= TYPE_NFIELDS (t
) - 1;
15359 i
>= TYPE_N_BASECLASSES (t
);
15362 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15364 if (is_vtable_name (fieldname
, cu
))
15366 set_type_vptr_fieldno (type
, i
);
15371 /* Complain if virtual function table field not found. */
15372 if (i
< TYPE_N_BASECLASSES (t
))
15373 complaint (_("virtual function table pointer "
15374 "not found when defining class '%s'"),
15375 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15379 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15382 else if (cu
->producer
15383 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15385 /* The IBM XLC compiler does not provide direct indication
15386 of the containing type, but the vtable pointer is
15387 always named __vfp. */
15391 for (i
= TYPE_NFIELDS (type
) - 1;
15392 i
>= TYPE_N_BASECLASSES (type
);
15395 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15397 set_type_vptr_fieldno (type
, i
);
15398 set_type_vptr_basetype (type
, type
);
15405 /* Copy fi.typedef_field_list linked list elements content into the
15406 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15407 if (!fi
.typedef_field_list
.empty ())
15409 int count
= fi
.typedef_field_list
.size ();
15411 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15412 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15413 = ((struct decl_field
*)
15415 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15416 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15418 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15419 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15422 /* Copy fi.nested_types_list linked list elements content into the
15423 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15424 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15426 int count
= fi
.nested_types_list
.size ();
15428 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15429 TYPE_NESTED_TYPES_ARRAY (type
)
15430 = ((struct decl_field
*)
15431 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15432 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15434 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15435 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15439 quirk_gcc_member_function_pointer (type
, objfile
);
15440 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15441 cu
->rust_unions
.push_back (type
);
15443 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15444 snapshots) has been known to create a die giving a declaration
15445 for a class that has, as a child, a die giving a definition for a
15446 nested class. So we have to process our children even if the
15447 current die is a declaration. Normally, of course, a declaration
15448 won't have any children at all. */
15450 child_die
= die
->child
;
15452 while (child_die
!= NULL
&& child_die
->tag
)
15454 if (child_die
->tag
== DW_TAG_member
15455 || child_die
->tag
== DW_TAG_variable
15456 || child_die
->tag
== DW_TAG_inheritance
15457 || child_die
->tag
== DW_TAG_template_value_param
15458 || child_die
->tag
== DW_TAG_template_type_param
)
15463 process_die (child_die
, cu
);
15465 child_die
= sibling_die (child_die
);
15468 /* Do not consider external references. According to the DWARF standard,
15469 these DIEs are identified by the fact that they have no byte_size
15470 attribute, and a declaration attribute. */
15471 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15472 || !die_is_declaration (die
, cu
))
15474 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15476 if (has_template_parameters
)
15478 struct symtab
*symtab
;
15479 if (sym
!= nullptr)
15480 symtab
= symbol_symtab (sym
);
15481 else if (cu
->line_header
!= nullptr)
15483 /* Any related symtab will do. */
15485 = cu
->line_header
->file_names ()[0].symtab
;
15490 complaint (_("could not find suitable "
15491 "symtab for template parameter"
15492 " - DIE at %s [in module %s]"),
15493 sect_offset_str (die
->sect_off
),
15494 objfile_name (objfile
));
15497 if (symtab
!= nullptr)
15499 /* Make sure that the symtab is set on the new symbols.
15500 Even though they don't appear in this symtab directly,
15501 other parts of gdb assume that symbols do, and this is
15502 reasonably true. */
15503 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15504 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15510 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15511 update TYPE using some information only available in DIE's children. */
15514 update_enumeration_type_from_children (struct die_info
*die
,
15516 struct dwarf2_cu
*cu
)
15518 struct die_info
*child_die
;
15519 int unsigned_enum
= 1;
15522 auto_obstack obstack
;
15524 for (child_die
= die
->child
;
15525 child_die
!= NULL
&& child_die
->tag
;
15526 child_die
= sibling_die (child_die
))
15528 struct attribute
*attr
;
15530 const gdb_byte
*bytes
;
15531 struct dwarf2_locexpr_baton
*baton
;
15534 if (child_die
->tag
!= DW_TAG_enumerator
)
15537 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15541 name
= dwarf2_name (child_die
, cu
);
15543 name
= "<anonymous enumerator>";
15545 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15546 &value
, &bytes
, &baton
);
15554 if (count_one_bits_ll (value
) >= 2)
15558 /* If we already know that the enum type is neither unsigned, nor
15559 a flag type, no need to look at the rest of the enumerates. */
15560 if (!unsigned_enum
&& !flag_enum
)
15565 TYPE_UNSIGNED (type
) = 1;
15567 TYPE_FLAG_ENUM (type
) = 1;
15570 /* Given a DW_AT_enumeration_type die, set its type. We do not
15571 complete the type's fields yet, or create any symbols. */
15573 static struct type
*
15574 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15576 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15578 struct attribute
*attr
;
15581 /* If the definition of this type lives in .debug_types, read that type.
15582 Don't follow DW_AT_specification though, that will take us back up
15583 the chain and we want to go down. */
15584 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15585 if (attr
!= nullptr)
15587 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15589 /* The type's CU may not be the same as CU.
15590 Ensure TYPE is recorded with CU in die_type_hash. */
15591 return set_die_type (die
, type
, cu
);
15594 type
= alloc_type (objfile
);
15596 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15597 name
= dwarf2_full_name (NULL
, die
, cu
);
15599 TYPE_NAME (type
) = name
;
15601 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15604 struct type
*underlying_type
= die_type (die
, cu
);
15606 TYPE_TARGET_TYPE (type
) = underlying_type
;
15609 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15610 if (attr
!= nullptr)
15612 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15616 TYPE_LENGTH (type
) = 0;
15619 maybe_set_alignment (cu
, die
, type
);
15621 /* The enumeration DIE can be incomplete. In Ada, any type can be
15622 declared as private in the package spec, and then defined only
15623 inside the package body. Such types are known as Taft Amendment
15624 Types. When another package uses such a type, an incomplete DIE
15625 may be generated by the compiler. */
15626 if (die_is_declaration (die
, cu
))
15627 TYPE_STUB (type
) = 1;
15629 /* Finish the creation of this type by using the enum's children.
15630 We must call this even when the underlying type has been provided
15631 so that we can determine if we're looking at a "flag" enum. */
15632 update_enumeration_type_from_children (die
, type
, cu
);
15634 /* If this type has an underlying type that is not a stub, then we
15635 may use its attributes. We always use the "unsigned" attribute
15636 in this situation, because ordinarily we guess whether the type
15637 is unsigned -- but the guess can be wrong and the underlying type
15638 can tell us the reality. However, we defer to a local size
15639 attribute if one exists, because this lets the compiler override
15640 the underlying type if needed. */
15641 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15643 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15644 if (TYPE_LENGTH (type
) == 0)
15645 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15646 if (TYPE_RAW_ALIGN (type
) == 0
15647 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15648 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15651 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15653 return set_die_type (die
, type
, cu
);
15656 /* Given a pointer to a die which begins an enumeration, process all
15657 the dies that define the members of the enumeration, and create the
15658 symbol for the enumeration type.
15660 NOTE: We reverse the order of the element list. */
15663 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15665 struct type
*this_type
;
15667 this_type
= get_die_type (die
, cu
);
15668 if (this_type
== NULL
)
15669 this_type
= read_enumeration_type (die
, cu
);
15671 if (die
->child
!= NULL
)
15673 struct die_info
*child_die
;
15674 struct symbol
*sym
;
15675 std::vector
<struct field
> fields
;
15678 child_die
= die
->child
;
15679 while (child_die
&& child_die
->tag
)
15681 if (child_die
->tag
!= DW_TAG_enumerator
)
15683 process_die (child_die
, cu
);
15687 name
= dwarf2_name (child_die
, cu
);
15690 sym
= new_symbol (child_die
, this_type
, cu
);
15692 fields
.emplace_back ();
15693 struct field
&field
= fields
.back ();
15695 FIELD_NAME (field
) = sym
->linkage_name ();
15696 FIELD_TYPE (field
) = NULL
;
15697 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15698 FIELD_BITSIZE (field
) = 0;
15702 child_die
= sibling_die (child_die
);
15705 if (!fields
.empty ())
15707 TYPE_NFIELDS (this_type
) = fields
.size ();
15708 TYPE_FIELDS (this_type
) = (struct field
*)
15709 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15710 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15711 sizeof (struct field
) * fields
.size ());
15715 /* If we are reading an enum from a .debug_types unit, and the enum
15716 is a declaration, and the enum is not the signatured type in the
15717 unit, then we do not want to add a symbol for it. Adding a
15718 symbol would in some cases obscure the true definition of the
15719 enum, giving users an incomplete type when the definition is
15720 actually available. Note that we do not want to do this for all
15721 enums which are just declarations, because C++0x allows forward
15722 enum declarations. */
15723 if (cu
->per_cu
->is_debug_types
15724 && die_is_declaration (die
, cu
))
15726 struct signatured_type
*sig_type
;
15728 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15729 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15730 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15734 new_symbol (die
, this_type
, cu
);
15737 /* Extract all information from a DW_TAG_array_type DIE and put it in
15738 the DIE's type field. For now, this only handles one dimensional
15741 static struct type
*
15742 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15744 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15745 struct die_info
*child_die
;
15747 struct type
*element_type
, *range_type
, *index_type
;
15748 struct attribute
*attr
;
15750 struct dynamic_prop
*byte_stride_prop
= NULL
;
15751 unsigned int bit_stride
= 0;
15753 element_type
= die_type (die
, cu
);
15755 /* The die_type call above may have already set the type for this DIE. */
15756 type
= get_die_type (die
, cu
);
15760 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15764 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15767 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15768 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15772 complaint (_("unable to read array DW_AT_byte_stride "
15773 " - DIE at %s [in module %s]"),
15774 sect_offset_str (die
->sect_off
),
15775 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15776 /* Ignore this attribute. We will likely not be able to print
15777 arrays of this type correctly, but there is little we can do
15778 to help if we cannot read the attribute's value. */
15779 byte_stride_prop
= NULL
;
15783 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15785 bit_stride
= DW_UNSND (attr
);
15787 /* Irix 6.2 native cc creates array types without children for
15788 arrays with unspecified length. */
15789 if (die
->child
== NULL
)
15791 index_type
= objfile_type (objfile
)->builtin_int
;
15792 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15793 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15794 byte_stride_prop
, bit_stride
);
15795 return set_die_type (die
, type
, cu
);
15798 std::vector
<struct type
*> range_types
;
15799 child_die
= die
->child
;
15800 while (child_die
&& child_die
->tag
)
15802 if (child_die
->tag
== DW_TAG_subrange_type
)
15804 struct type
*child_type
= read_type_die (child_die
, cu
);
15806 if (child_type
!= NULL
)
15808 /* The range type was succesfully read. Save it for the
15809 array type creation. */
15810 range_types
.push_back (child_type
);
15813 child_die
= sibling_die (child_die
);
15816 /* Dwarf2 dimensions are output from left to right, create the
15817 necessary array types in backwards order. */
15819 type
= element_type
;
15821 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15825 while (i
< range_types
.size ())
15826 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15827 byte_stride_prop
, bit_stride
);
15831 size_t ndim
= range_types
.size ();
15833 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15834 byte_stride_prop
, bit_stride
);
15837 /* Understand Dwarf2 support for vector types (like they occur on
15838 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15839 array type. This is not part of the Dwarf2/3 standard yet, but a
15840 custom vendor extension. The main difference between a regular
15841 array and the vector variant is that vectors are passed by value
15843 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15844 if (attr
!= nullptr)
15845 make_vector_type (type
);
15847 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15848 implementation may choose to implement triple vectors using this
15850 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15851 if (attr
!= nullptr)
15853 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15854 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15856 complaint (_("DW_AT_byte_size for array type smaller "
15857 "than the total size of elements"));
15860 name
= dwarf2_name (die
, cu
);
15862 TYPE_NAME (type
) = name
;
15864 maybe_set_alignment (cu
, die
, type
);
15866 /* Install the type in the die. */
15867 set_die_type (die
, type
, cu
);
15869 /* set_die_type should be already done. */
15870 set_descriptive_type (type
, die
, cu
);
15875 static enum dwarf_array_dim_ordering
15876 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15878 struct attribute
*attr
;
15880 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15882 if (attr
!= nullptr)
15883 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15885 /* GNU F77 is a special case, as at 08/2004 array type info is the
15886 opposite order to the dwarf2 specification, but data is still
15887 laid out as per normal fortran.
15889 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15890 version checking. */
15892 if (cu
->language
== language_fortran
15893 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15895 return DW_ORD_row_major
;
15898 switch (cu
->language_defn
->la_array_ordering
)
15900 case array_column_major
:
15901 return DW_ORD_col_major
;
15902 case array_row_major
:
15904 return DW_ORD_row_major
;
15908 /* Extract all information from a DW_TAG_set_type DIE and put it in
15909 the DIE's type field. */
15911 static struct type
*
15912 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15914 struct type
*domain_type
, *set_type
;
15915 struct attribute
*attr
;
15917 domain_type
= die_type (die
, cu
);
15919 /* The die_type call above may have already set the type for this DIE. */
15920 set_type
= get_die_type (die
, cu
);
15924 set_type
= create_set_type (NULL
, domain_type
);
15926 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15927 if (attr
!= nullptr)
15928 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15930 maybe_set_alignment (cu
, die
, set_type
);
15932 return set_die_type (die
, set_type
, cu
);
15935 /* A helper for read_common_block that creates a locexpr baton.
15936 SYM is the symbol which we are marking as computed.
15937 COMMON_DIE is the DIE for the common block.
15938 COMMON_LOC is the location expression attribute for the common
15940 MEMBER_LOC is the location expression attribute for the particular
15941 member of the common block that we are processing.
15942 CU is the CU from which the above come. */
15945 mark_common_block_symbol_computed (struct symbol
*sym
,
15946 struct die_info
*common_die
,
15947 struct attribute
*common_loc
,
15948 struct attribute
*member_loc
,
15949 struct dwarf2_cu
*cu
)
15951 struct dwarf2_per_objfile
*dwarf2_per_objfile
15952 = cu
->per_cu
->dwarf2_per_objfile
;
15953 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15954 struct dwarf2_locexpr_baton
*baton
;
15956 unsigned int cu_off
;
15957 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15958 LONGEST offset
= 0;
15960 gdb_assert (common_loc
&& member_loc
);
15961 gdb_assert (common_loc
->form_is_block ());
15962 gdb_assert (member_loc
->form_is_block ()
15963 || member_loc
->form_is_constant ());
15965 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15966 baton
->per_cu
= cu
->per_cu
;
15967 gdb_assert (baton
->per_cu
);
15969 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15971 if (member_loc
->form_is_constant ())
15973 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15974 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15977 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15979 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15982 *ptr
++ = DW_OP_call4
;
15983 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15984 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15987 if (member_loc
->form_is_constant ())
15989 *ptr
++ = DW_OP_addr
;
15990 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15991 ptr
+= cu
->header
.addr_size
;
15995 /* We have to copy the data here, because DW_OP_call4 will only
15996 use a DW_AT_location attribute. */
15997 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15998 ptr
+= DW_BLOCK (member_loc
)->size
;
16001 *ptr
++ = DW_OP_plus
;
16002 gdb_assert (ptr
- baton
->data
== baton
->size
);
16004 SYMBOL_LOCATION_BATON (sym
) = baton
;
16005 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16008 /* Create appropriate locally-scoped variables for all the
16009 DW_TAG_common_block entries. Also create a struct common_block
16010 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16011 is used to separate the common blocks name namespace from regular
16015 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16017 struct attribute
*attr
;
16019 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16020 if (attr
!= nullptr)
16022 /* Support the .debug_loc offsets. */
16023 if (attr
->form_is_block ())
16027 else if (attr
->form_is_section_offset ())
16029 dwarf2_complex_location_expr_complaint ();
16034 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16035 "common block member");
16040 if (die
->child
!= NULL
)
16042 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16043 struct die_info
*child_die
;
16044 size_t n_entries
= 0, size
;
16045 struct common_block
*common_block
;
16046 struct symbol
*sym
;
16048 for (child_die
= die
->child
;
16049 child_die
&& child_die
->tag
;
16050 child_die
= sibling_die (child_die
))
16053 size
= (sizeof (struct common_block
)
16054 + (n_entries
- 1) * sizeof (struct symbol
*));
16056 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16058 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16059 common_block
->n_entries
= 0;
16061 for (child_die
= die
->child
;
16062 child_die
&& child_die
->tag
;
16063 child_die
= sibling_die (child_die
))
16065 /* Create the symbol in the DW_TAG_common_block block in the current
16067 sym
= new_symbol (child_die
, NULL
, cu
);
16070 struct attribute
*member_loc
;
16072 common_block
->contents
[common_block
->n_entries
++] = sym
;
16074 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16078 /* GDB has handled this for a long time, but it is
16079 not specified by DWARF. It seems to have been
16080 emitted by gfortran at least as recently as:
16081 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16082 complaint (_("Variable in common block has "
16083 "DW_AT_data_member_location "
16084 "- DIE at %s [in module %s]"),
16085 sect_offset_str (child_die
->sect_off
),
16086 objfile_name (objfile
));
16088 if (member_loc
->form_is_section_offset ())
16089 dwarf2_complex_location_expr_complaint ();
16090 else if (member_loc
->form_is_constant ()
16091 || member_loc
->form_is_block ())
16093 if (attr
!= nullptr)
16094 mark_common_block_symbol_computed (sym
, die
, attr
,
16098 dwarf2_complex_location_expr_complaint ();
16103 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16104 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16108 /* Create a type for a C++ namespace. */
16110 static struct type
*
16111 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16113 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16114 const char *previous_prefix
, *name
;
16118 /* For extensions, reuse the type of the original namespace. */
16119 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16121 struct die_info
*ext_die
;
16122 struct dwarf2_cu
*ext_cu
= cu
;
16124 ext_die
= dwarf2_extension (die
, &ext_cu
);
16125 type
= read_type_die (ext_die
, ext_cu
);
16127 /* EXT_CU may not be the same as CU.
16128 Ensure TYPE is recorded with CU in die_type_hash. */
16129 return set_die_type (die
, type
, cu
);
16132 name
= namespace_name (die
, &is_anonymous
, cu
);
16134 /* Now build the name of the current namespace. */
16136 previous_prefix
= determine_prefix (die
, cu
);
16137 if (previous_prefix
[0] != '\0')
16138 name
= typename_concat (&objfile
->objfile_obstack
,
16139 previous_prefix
, name
, 0, cu
);
16141 /* Create the type. */
16142 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16144 return set_die_type (die
, type
, cu
);
16147 /* Read a namespace scope. */
16150 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16152 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16155 /* Add a symbol associated to this if we haven't seen the namespace
16156 before. Also, add a using directive if it's an anonymous
16159 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16163 type
= read_type_die (die
, cu
);
16164 new_symbol (die
, type
, cu
);
16166 namespace_name (die
, &is_anonymous
, cu
);
16169 const char *previous_prefix
= determine_prefix (die
, cu
);
16171 std::vector
<const char *> excludes
;
16172 add_using_directive (using_directives (cu
),
16173 previous_prefix
, TYPE_NAME (type
), NULL
,
16174 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16178 if (die
->child
!= NULL
)
16180 struct die_info
*child_die
= die
->child
;
16182 while (child_die
&& child_die
->tag
)
16184 process_die (child_die
, cu
);
16185 child_die
= sibling_die (child_die
);
16190 /* Read a Fortran module as type. This DIE can be only a declaration used for
16191 imported module. Still we need that type as local Fortran "use ... only"
16192 declaration imports depend on the created type in determine_prefix. */
16194 static struct type
*
16195 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16197 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16198 const char *module_name
;
16201 module_name
= dwarf2_name (die
, cu
);
16202 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16204 return set_die_type (die
, type
, cu
);
16207 /* Read a Fortran module. */
16210 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16212 struct die_info
*child_die
= die
->child
;
16215 type
= read_type_die (die
, cu
);
16216 new_symbol (die
, type
, cu
);
16218 while (child_die
&& child_die
->tag
)
16220 process_die (child_die
, cu
);
16221 child_die
= sibling_die (child_die
);
16225 /* Return the name of the namespace represented by DIE. Set
16226 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16229 static const char *
16230 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16232 struct die_info
*current_die
;
16233 const char *name
= NULL
;
16235 /* Loop through the extensions until we find a name. */
16237 for (current_die
= die
;
16238 current_die
!= NULL
;
16239 current_die
= dwarf2_extension (die
, &cu
))
16241 /* We don't use dwarf2_name here so that we can detect the absence
16242 of a name -> anonymous namespace. */
16243 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16249 /* Is it an anonymous namespace? */
16251 *is_anonymous
= (name
== NULL
);
16253 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16258 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16259 the user defined type vector. */
16261 static struct type
*
16262 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16264 struct gdbarch
*gdbarch
16265 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16266 struct comp_unit_head
*cu_header
= &cu
->header
;
16268 struct attribute
*attr_byte_size
;
16269 struct attribute
*attr_address_class
;
16270 int byte_size
, addr_class
;
16271 struct type
*target_type
;
16273 target_type
= die_type (die
, cu
);
16275 /* The die_type call above may have already set the type for this DIE. */
16276 type
= get_die_type (die
, cu
);
16280 type
= lookup_pointer_type (target_type
);
16282 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16283 if (attr_byte_size
)
16284 byte_size
= DW_UNSND (attr_byte_size
);
16286 byte_size
= cu_header
->addr_size
;
16288 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16289 if (attr_address_class
)
16290 addr_class
= DW_UNSND (attr_address_class
);
16292 addr_class
= DW_ADDR_none
;
16294 ULONGEST alignment
= get_alignment (cu
, die
);
16296 /* If the pointer size, alignment, or address class is different
16297 than the default, create a type variant marked as such and set
16298 the length accordingly. */
16299 if (TYPE_LENGTH (type
) != byte_size
16300 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16301 && alignment
!= TYPE_RAW_ALIGN (type
))
16302 || addr_class
!= DW_ADDR_none
)
16304 if (gdbarch_address_class_type_flags_p (gdbarch
))
16308 type_flags
= gdbarch_address_class_type_flags
16309 (gdbarch
, byte_size
, addr_class
);
16310 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16312 type
= make_type_with_address_space (type
, type_flags
);
16314 else if (TYPE_LENGTH (type
) != byte_size
)
16316 complaint (_("invalid pointer size %d"), byte_size
);
16318 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16320 complaint (_("Invalid DW_AT_alignment"
16321 " - DIE at %s [in module %s]"),
16322 sect_offset_str (die
->sect_off
),
16323 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16327 /* Should we also complain about unhandled address classes? */
16331 TYPE_LENGTH (type
) = byte_size
;
16332 set_type_align (type
, alignment
);
16333 return set_die_type (die
, type
, cu
);
16336 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16337 the user defined type vector. */
16339 static struct type
*
16340 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16343 struct type
*to_type
;
16344 struct type
*domain
;
16346 to_type
= die_type (die
, cu
);
16347 domain
= die_containing_type (die
, cu
);
16349 /* The calls above may have already set the type for this DIE. */
16350 type
= get_die_type (die
, cu
);
16354 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16355 type
= lookup_methodptr_type (to_type
);
16356 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16358 struct type
*new_type
16359 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16361 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16362 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16363 TYPE_VARARGS (to_type
));
16364 type
= lookup_methodptr_type (new_type
);
16367 type
= lookup_memberptr_type (to_type
, domain
);
16369 return set_die_type (die
, type
, cu
);
16372 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16373 the user defined type vector. */
16375 static struct type
*
16376 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16377 enum type_code refcode
)
16379 struct comp_unit_head
*cu_header
= &cu
->header
;
16380 struct type
*type
, *target_type
;
16381 struct attribute
*attr
;
16383 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16385 target_type
= die_type (die
, cu
);
16387 /* The die_type call above may have already set the type for this DIE. */
16388 type
= get_die_type (die
, cu
);
16392 type
= lookup_reference_type (target_type
, refcode
);
16393 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16394 if (attr
!= nullptr)
16396 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16400 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16402 maybe_set_alignment (cu
, die
, type
);
16403 return set_die_type (die
, type
, cu
);
16406 /* Add the given cv-qualifiers to the element type of the array. GCC
16407 outputs DWARF type qualifiers that apply to an array, not the
16408 element type. But GDB relies on the array element type to carry
16409 the cv-qualifiers. This mimics section 6.7.3 of the C99
16412 static struct type
*
16413 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16414 struct type
*base_type
, int cnst
, int voltl
)
16416 struct type
*el_type
, *inner_array
;
16418 base_type
= copy_type (base_type
);
16419 inner_array
= base_type
;
16421 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16423 TYPE_TARGET_TYPE (inner_array
) =
16424 copy_type (TYPE_TARGET_TYPE (inner_array
));
16425 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16428 el_type
= TYPE_TARGET_TYPE (inner_array
);
16429 cnst
|= TYPE_CONST (el_type
);
16430 voltl
|= TYPE_VOLATILE (el_type
);
16431 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16433 return set_die_type (die
, base_type
, cu
);
16436 static struct type
*
16437 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16439 struct type
*base_type
, *cv_type
;
16441 base_type
= die_type (die
, cu
);
16443 /* The die_type call above may have already set the type for this DIE. */
16444 cv_type
= get_die_type (die
, cu
);
16448 /* In case the const qualifier is applied to an array type, the element type
16449 is so qualified, not the array type (section 6.7.3 of C99). */
16450 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16451 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16453 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16454 return set_die_type (die
, cv_type
, cu
);
16457 static struct type
*
16458 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16460 struct type
*base_type
, *cv_type
;
16462 base_type
= die_type (die
, cu
);
16464 /* The die_type call above may have already set the type for this DIE. */
16465 cv_type
= get_die_type (die
, cu
);
16469 /* In case the volatile qualifier is applied to an array type, the
16470 element type is so qualified, not the array type (section 6.7.3
16472 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16473 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16475 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16476 return set_die_type (die
, cv_type
, cu
);
16479 /* Handle DW_TAG_restrict_type. */
16481 static struct type
*
16482 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16484 struct type
*base_type
, *cv_type
;
16486 base_type
= die_type (die
, cu
);
16488 /* The die_type call above may have already set the type for this DIE. */
16489 cv_type
= get_die_type (die
, cu
);
16493 cv_type
= make_restrict_type (base_type
);
16494 return set_die_type (die
, cv_type
, cu
);
16497 /* Handle DW_TAG_atomic_type. */
16499 static struct type
*
16500 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16502 struct type
*base_type
, *cv_type
;
16504 base_type
= die_type (die
, cu
);
16506 /* The die_type call above may have already set the type for this DIE. */
16507 cv_type
= get_die_type (die
, cu
);
16511 cv_type
= make_atomic_type (base_type
);
16512 return set_die_type (die
, cv_type
, cu
);
16515 /* Extract all information from a DW_TAG_string_type DIE and add to
16516 the user defined type vector. It isn't really a user defined type,
16517 but it behaves like one, with other DIE's using an AT_user_def_type
16518 attribute to reference it. */
16520 static struct type
*
16521 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16523 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16524 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16525 struct type
*type
, *range_type
, *index_type
, *char_type
;
16526 struct attribute
*attr
;
16527 struct dynamic_prop prop
;
16528 bool length_is_constant
= true;
16531 /* There are a couple of places where bit sizes might be made use of
16532 when parsing a DW_TAG_string_type, however, no producer that we know
16533 of make use of these. Handling bit sizes that are a multiple of the
16534 byte size is easy enough, but what about other bit sizes? Lets deal
16535 with that problem when we have to. Warn about these attributes being
16536 unsupported, then parse the type and ignore them like we always
16538 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16539 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16541 static bool warning_printed
= false;
16542 if (!warning_printed
)
16544 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16545 "currently supported on DW_TAG_string_type."));
16546 warning_printed
= true;
16550 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16551 if (attr
!= nullptr && !attr
->form_is_constant ())
16553 /* The string length describes the location at which the length of
16554 the string can be found. The size of the length field can be
16555 specified with one of the attributes below. */
16556 struct type
*prop_type
;
16557 struct attribute
*len
16558 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16559 if (len
== nullptr)
16560 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16561 if (len
!= nullptr && len
->form_is_constant ())
16563 /* Pass 0 as the default as we know this attribute is constant
16564 and the default value will not be returned. */
16565 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16566 prop_type
= cu
->per_cu
->int_type (sz
, true);
16570 /* If the size is not specified then we assume it is the size of
16571 an address on this target. */
16572 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16575 /* Convert the attribute into a dynamic property. */
16576 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16579 length_is_constant
= false;
16581 else if (attr
!= nullptr)
16583 /* This DW_AT_string_length just contains the length with no
16584 indirection. There's no need to create a dynamic property in this
16585 case. Pass 0 for the default value as we know it will not be
16586 returned in this case. */
16587 length
= dwarf2_get_attr_constant_value (attr
, 0);
16589 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16591 /* We don't currently support non-constant byte sizes for strings. */
16592 length
= dwarf2_get_attr_constant_value (attr
, 1);
16596 /* Use 1 as a fallback length if we have nothing else. */
16600 index_type
= objfile_type (objfile
)->builtin_int
;
16601 if (length_is_constant
)
16602 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16605 struct dynamic_prop low_bound
;
16607 low_bound
.kind
= PROP_CONST
;
16608 low_bound
.data
.const_val
= 1;
16609 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16611 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16612 type
= create_string_type (NULL
, char_type
, range_type
);
16614 return set_die_type (die
, type
, cu
);
16617 /* Assuming that DIE corresponds to a function, returns nonzero
16618 if the function is prototyped. */
16621 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16623 struct attribute
*attr
;
16625 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16626 if (attr
&& (DW_UNSND (attr
) != 0))
16629 /* The DWARF standard implies that the DW_AT_prototyped attribute
16630 is only meaningful for C, but the concept also extends to other
16631 languages that allow unprototyped functions (Eg: Objective C).
16632 For all other languages, assume that functions are always
16634 if (cu
->language
!= language_c
16635 && cu
->language
!= language_objc
16636 && cu
->language
!= language_opencl
)
16639 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16640 prototyped and unprototyped functions; default to prototyped,
16641 since that is more common in modern code (and RealView warns
16642 about unprototyped functions). */
16643 if (producer_is_realview (cu
->producer
))
16649 /* Handle DIES due to C code like:
16653 int (*funcp)(int a, long l);
16657 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16659 static struct type
*
16660 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16662 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16663 struct type
*type
; /* Type that this function returns. */
16664 struct type
*ftype
; /* Function that returns above type. */
16665 struct attribute
*attr
;
16667 type
= die_type (die
, cu
);
16669 /* The die_type call above may have already set the type for this DIE. */
16670 ftype
= get_die_type (die
, cu
);
16674 ftype
= lookup_function_type (type
);
16676 if (prototyped_function_p (die
, cu
))
16677 TYPE_PROTOTYPED (ftype
) = 1;
16679 /* Store the calling convention in the type if it's available in
16680 the subroutine die. Otherwise set the calling convention to
16681 the default value DW_CC_normal. */
16682 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16683 if (attr
!= nullptr
16684 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16685 TYPE_CALLING_CONVENTION (ftype
)
16686 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16687 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16688 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16690 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16692 /* Record whether the function returns normally to its caller or not
16693 if the DWARF producer set that information. */
16694 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16695 if (attr
&& (DW_UNSND (attr
) != 0))
16696 TYPE_NO_RETURN (ftype
) = 1;
16698 /* We need to add the subroutine type to the die immediately so
16699 we don't infinitely recurse when dealing with parameters
16700 declared as the same subroutine type. */
16701 set_die_type (die
, ftype
, cu
);
16703 if (die
->child
!= NULL
)
16705 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16706 struct die_info
*child_die
;
16707 int nparams
, iparams
;
16709 /* Count the number of parameters.
16710 FIXME: GDB currently ignores vararg functions, but knows about
16711 vararg member functions. */
16713 child_die
= die
->child
;
16714 while (child_die
&& child_die
->tag
)
16716 if (child_die
->tag
== DW_TAG_formal_parameter
)
16718 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16719 TYPE_VARARGS (ftype
) = 1;
16720 child_die
= sibling_die (child_die
);
16723 /* Allocate storage for parameters and fill them in. */
16724 TYPE_NFIELDS (ftype
) = nparams
;
16725 TYPE_FIELDS (ftype
) = (struct field
*)
16726 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16728 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16729 even if we error out during the parameters reading below. */
16730 for (iparams
= 0; iparams
< nparams
; iparams
++)
16731 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16734 child_die
= die
->child
;
16735 while (child_die
&& child_die
->tag
)
16737 if (child_die
->tag
== DW_TAG_formal_parameter
)
16739 struct type
*arg_type
;
16741 /* DWARF version 2 has no clean way to discern C++
16742 static and non-static member functions. G++ helps
16743 GDB by marking the first parameter for non-static
16744 member functions (which is the this pointer) as
16745 artificial. We pass this information to
16746 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16748 DWARF version 3 added DW_AT_object_pointer, which GCC
16749 4.5 does not yet generate. */
16750 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16751 if (attr
!= nullptr)
16752 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16754 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16755 arg_type
= die_type (child_die
, cu
);
16757 /* RealView does not mark THIS as const, which the testsuite
16758 expects. GCC marks THIS as const in method definitions,
16759 but not in the class specifications (GCC PR 43053). */
16760 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16761 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16764 struct dwarf2_cu
*arg_cu
= cu
;
16765 const char *name
= dwarf2_name (child_die
, cu
);
16767 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16768 if (attr
!= nullptr)
16770 /* If the compiler emits this, use it. */
16771 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16774 else if (name
&& strcmp (name
, "this") == 0)
16775 /* Function definitions will have the argument names. */
16777 else if (name
== NULL
&& iparams
== 0)
16778 /* Declarations may not have the names, so like
16779 elsewhere in GDB, assume an artificial first
16780 argument is "this". */
16784 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16788 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16791 child_die
= sibling_die (child_die
);
16798 static struct type
*
16799 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16801 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16802 const char *name
= NULL
;
16803 struct type
*this_type
, *target_type
;
16805 name
= dwarf2_full_name (NULL
, die
, cu
);
16806 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16807 TYPE_TARGET_STUB (this_type
) = 1;
16808 set_die_type (die
, this_type
, cu
);
16809 target_type
= die_type (die
, cu
);
16810 if (target_type
!= this_type
)
16811 TYPE_TARGET_TYPE (this_type
) = target_type
;
16814 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16815 spec and cause infinite loops in GDB. */
16816 complaint (_("Self-referential DW_TAG_typedef "
16817 "- DIE at %s [in module %s]"),
16818 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16819 TYPE_TARGET_TYPE (this_type
) = NULL
;
16823 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16824 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16825 Handle these by just returning the target type, rather than
16826 constructing an anonymous typedef type and trying to handle this
16828 set_die_type (die
, target_type
, cu
);
16829 return target_type
;
16834 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16835 (which may be different from NAME) to the architecture back-end to allow
16836 it to guess the correct format if necessary. */
16838 static struct type
*
16839 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16840 const char *name_hint
, enum bfd_endian byte_order
)
16842 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16843 const struct floatformat
**format
;
16846 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16848 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16850 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16855 /* Allocate an integer type of size BITS and name NAME. */
16857 static struct type
*
16858 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16859 int bits
, int unsigned_p
, const char *name
)
16863 /* Versions of Intel's C Compiler generate an integer type called "void"
16864 instead of using DW_TAG_unspecified_type. This has been seen on
16865 at least versions 14, 17, and 18. */
16866 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16867 && strcmp (name
, "void") == 0)
16868 type
= objfile_type (objfile
)->builtin_void
;
16870 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16875 /* Initialise and return a floating point type of size BITS suitable for
16876 use as a component of a complex number. The NAME_HINT is passed through
16877 when initialising the floating point type and is the name of the complex
16880 As DWARF doesn't currently provide an explicit name for the components
16881 of a complex number, but it can be helpful to have these components
16882 named, we try to select a suitable name based on the size of the
16884 static struct type
*
16885 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16886 struct objfile
*objfile
,
16887 int bits
, const char *name_hint
,
16888 enum bfd_endian byte_order
)
16890 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16891 struct type
*tt
= nullptr;
16893 /* Try to find a suitable floating point builtin type of size BITS.
16894 We're going to use the name of this type as the name for the complex
16895 target type that we are about to create. */
16896 switch (cu
->language
)
16898 case language_fortran
:
16902 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16905 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16907 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16909 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16917 tt
= builtin_type (gdbarch
)->builtin_float
;
16920 tt
= builtin_type (gdbarch
)->builtin_double
;
16922 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16924 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16930 /* If the type we found doesn't match the size we were looking for, then
16931 pretend we didn't find a type at all, the complex target type we
16932 create will then be nameless. */
16933 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16936 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16937 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16940 /* Find a representation of a given base type and install
16941 it in the TYPE field of the die. */
16943 static struct type
*
16944 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16946 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16948 struct attribute
*attr
;
16949 int encoding
= 0, bits
= 0;
16953 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16954 if (attr
!= nullptr)
16955 encoding
= DW_UNSND (attr
);
16956 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16957 if (attr
!= nullptr)
16958 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16959 name
= dwarf2_name (die
, cu
);
16961 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16963 arch
= get_objfile_arch (objfile
);
16964 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16966 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16969 int endianity
= DW_UNSND (attr
);
16974 byte_order
= BFD_ENDIAN_BIG
;
16976 case DW_END_little
:
16977 byte_order
= BFD_ENDIAN_LITTLE
;
16980 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16987 case DW_ATE_address
:
16988 /* Turn DW_ATE_address into a void * pointer. */
16989 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16990 type
= init_pointer_type (objfile
, bits
, name
, type
);
16992 case DW_ATE_boolean
:
16993 type
= init_boolean_type (objfile
, bits
, 1, name
);
16995 case DW_ATE_complex_float
:
16996 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16998 type
= init_complex_type (objfile
, name
, type
);
17000 case DW_ATE_decimal_float
:
17001 type
= init_decfloat_type (objfile
, bits
, name
);
17004 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17006 case DW_ATE_signed
:
17007 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17009 case DW_ATE_unsigned
:
17010 if (cu
->language
== language_fortran
17012 && startswith (name
, "character("))
17013 type
= init_character_type (objfile
, bits
, 1, name
);
17015 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17017 case DW_ATE_signed_char
:
17018 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17019 || cu
->language
== language_pascal
17020 || cu
->language
== language_fortran
)
17021 type
= init_character_type (objfile
, bits
, 0, name
);
17023 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17025 case DW_ATE_unsigned_char
:
17026 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17027 || cu
->language
== language_pascal
17028 || cu
->language
== language_fortran
17029 || cu
->language
== language_rust
)
17030 type
= init_character_type (objfile
, bits
, 1, name
);
17032 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17037 type
= builtin_type (arch
)->builtin_char16
;
17038 else if (bits
== 32)
17039 type
= builtin_type (arch
)->builtin_char32
;
17042 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17044 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17046 return set_die_type (die
, type
, cu
);
17051 complaint (_("unsupported DW_AT_encoding: '%s'"),
17052 dwarf_type_encoding_name (encoding
));
17053 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17057 if (name
&& strcmp (name
, "char") == 0)
17058 TYPE_NOSIGN (type
) = 1;
17060 maybe_set_alignment (cu
, die
, type
);
17062 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17064 return set_die_type (die
, type
, cu
);
17067 /* Parse dwarf attribute if it's a block, reference or constant and put the
17068 resulting value of the attribute into struct bound_prop.
17069 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17072 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17073 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17074 struct type
*default_type
)
17076 struct dwarf2_property_baton
*baton
;
17077 struct obstack
*obstack
17078 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17080 gdb_assert (default_type
!= NULL
);
17082 if (attr
== NULL
|| prop
== NULL
)
17085 if (attr
->form_is_block ())
17087 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17088 baton
->property_type
= default_type
;
17089 baton
->locexpr
.per_cu
= cu
->per_cu
;
17090 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17091 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17092 switch (attr
->name
)
17094 case DW_AT_string_length
:
17095 baton
->locexpr
.is_reference
= true;
17098 baton
->locexpr
.is_reference
= false;
17101 prop
->data
.baton
= baton
;
17102 prop
->kind
= PROP_LOCEXPR
;
17103 gdb_assert (prop
->data
.baton
!= NULL
);
17105 else if (attr
->form_is_ref ())
17107 struct dwarf2_cu
*target_cu
= cu
;
17108 struct die_info
*target_die
;
17109 struct attribute
*target_attr
;
17111 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17112 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17113 if (target_attr
== NULL
)
17114 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17116 if (target_attr
== NULL
)
17119 switch (target_attr
->name
)
17121 case DW_AT_location
:
17122 if (target_attr
->form_is_section_offset ())
17124 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17125 baton
->property_type
= die_type (target_die
, target_cu
);
17126 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17127 prop
->data
.baton
= baton
;
17128 prop
->kind
= PROP_LOCLIST
;
17129 gdb_assert (prop
->data
.baton
!= NULL
);
17131 else if (target_attr
->form_is_block ())
17133 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17134 baton
->property_type
= die_type (target_die
, target_cu
);
17135 baton
->locexpr
.per_cu
= cu
->per_cu
;
17136 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17137 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17138 baton
->locexpr
.is_reference
= true;
17139 prop
->data
.baton
= baton
;
17140 prop
->kind
= PROP_LOCEXPR
;
17141 gdb_assert (prop
->data
.baton
!= NULL
);
17145 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17146 "dynamic property");
17150 case DW_AT_data_member_location
:
17154 if (!handle_data_member_location (target_die
, target_cu
,
17158 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17159 baton
->property_type
= read_type_die (target_die
->parent
,
17161 baton
->offset_info
.offset
= offset
;
17162 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17163 prop
->data
.baton
= baton
;
17164 prop
->kind
= PROP_ADDR_OFFSET
;
17169 else if (attr
->form_is_constant ())
17171 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17172 prop
->kind
= PROP_CONST
;
17176 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17177 dwarf2_name (die
, cu
));
17187 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17189 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17190 struct type
*int_type
;
17192 /* Helper macro to examine the various builtin types. */
17193 #define TRY_TYPE(F) \
17194 int_type = (unsigned_p \
17195 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17196 : objfile_type (objfile)->builtin_ ## F); \
17197 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17204 TRY_TYPE (long_long
);
17208 gdb_assert_not_reached ("unable to find suitable integer type");
17214 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17216 int addr_size
= this->addr_size ();
17217 return int_type (addr_size
, unsigned_p
);
17220 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17221 present (which is valid) then compute the default type based on the
17222 compilation units address size. */
17224 static struct type
*
17225 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17227 struct type
*index_type
= die_type (die
, cu
);
17229 /* Dwarf-2 specifications explicitly allows to create subrange types
17230 without specifying a base type.
17231 In that case, the base type must be set to the type of
17232 the lower bound, upper bound or count, in that order, if any of these
17233 three attributes references an object that has a type.
17234 If no base type is found, the Dwarf-2 specifications say that
17235 a signed integer type of size equal to the size of an address should
17237 For the following C code: `extern char gdb_int [];'
17238 GCC produces an empty range DIE.
17239 FIXME: muller/2010-05-28: Possible references to object for low bound,
17240 high bound or count are not yet handled by this code. */
17241 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17242 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17247 /* Read the given DW_AT_subrange DIE. */
17249 static struct type
*
17250 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17252 struct type
*base_type
, *orig_base_type
;
17253 struct type
*range_type
;
17254 struct attribute
*attr
;
17255 struct dynamic_prop low
, high
;
17256 int low_default_is_valid
;
17257 int high_bound_is_count
= 0;
17259 ULONGEST negative_mask
;
17261 orig_base_type
= read_subrange_index_type (die
, cu
);
17263 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17264 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17265 creating the range type, but we use the result of check_typedef
17266 when examining properties of the type. */
17267 base_type
= check_typedef (orig_base_type
);
17269 /* The die_type call above may have already set the type for this DIE. */
17270 range_type
= get_die_type (die
, cu
);
17274 low
.kind
= PROP_CONST
;
17275 high
.kind
= PROP_CONST
;
17276 high
.data
.const_val
= 0;
17278 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17279 omitting DW_AT_lower_bound. */
17280 switch (cu
->language
)
17283 case language_cplus
:
17284 low
.data
.const_val
= 0;
17285 low_default_is_valid
= 1;
17287 case language_fortran
:
17288 low
.data
.const_val
= 1;
17289 low_default_is_valid
= 1;
17292 case language_objc
:
17293 case language_rust
:
17294 low
.data
.const_val
= 0;
17295 low_default_is_valid
= (cu
->header
.version
>= 4);
17299 case language_pascal
:
17300 low
.data
.const_val
= 1;
17301 low_default_is_valid
= (cu
->header
.version
>= 4);
17304 low
.data
.const_val
= 0;
17305 low_default_is_valid
= 0;
17309 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17310 if (attr
!= nullptr)
17311 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17312 else if (!low_default_is_valid
)
17313 complaint (_("Missing DW_AT_lower_bound "
17314 "- DIE at %s [in module %s]"),
17315 sect_offset_str (die
->sect_off
),
17316 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17318 struct attribute
*attr_ub
, *attr_count
;
17319 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17320 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17322 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17323 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17325 /* If bounds are constant do the final calculation here. */
17326 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17327 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17329 high_bound_is_count
= 1;
17333 if (attr_ub
!= NULL
)
17334 complaint (_("Unresolved DW_AT_upper_bound "
17335 "- DIE at %s [in module %s]"),
17336 sect_offset_str (die
->sect_off
),
17337 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17338 if (attr_count
!= NULL
)
17339 complaint (_("Unresolved DW_AT_count "
17340 "- DIE at %s [in module %s]"),
17341 sect_offset_str (die
->sect_off
),
17342 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17347 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17348 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17349 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17351 /* Normally, the DWARF producers are expected to use a signed
17352 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17353 But this is unfortunately not always the case, as witnessed
17354 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17355 is used instead. To work around that ambiguity, we treat
17356 the bounds as signed, and thus sign-extend their values, when
17357 the base type is signed. */
17359 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17360 if (low
.kind
== PROP_CONST
17361 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17362 low
.data
.const_val
|= negative_mask
;
17363 if (high
.kind
== PROP_CONST
17364 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17365 high
.data
.const_val
|= negative_mask
;
17367 /* Check for bit and byte strides. */
17368 struct dynamic_prop byte_stride_prop
;
17369 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17370 if (attr_byte_stride
!= nullptr)
17372 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17373 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17377 struct dynamic_prop bit_stride_prop
;
17378 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17379 if (attr_bit_stride
!= nullptr)
17381 /* It only makes sense to have either a bit or byte stride. */
17382 if (attr_byte_stride
!= nullptr)
17384 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17385 "- DIE at %s [in module %s]"),
17386 sect_offset_str (die
->sect_off
),
17387 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17388 attr_bit_stride
= nullptr;
17392 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17393 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17398 if (attr_byte_stride
!= nullptr
17399 || attr_bit_stride
!= nullptr)
17401 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17402 struct dynamic_prop
*stride
17403 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17406 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17407 &high
, bias
, stride
, byte_stride_p
);
17410 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17412 if (high_bound_is_count
)
17413 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17415 /* Ada expects an empty array on no boundary attributes. */
17416 if (attr
== NULL
&& cu
->language
!= language_ada
)
17417 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17419 name
= dwarf2_name (die
, cu
);
17421 TYPE_NAME (range_type
) = name
;
17423 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17424 if (attr
!= nullptr)
17425 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17427 maybe_set_alignment (cu
, die
, range_type
);
17429 set_die_type (die
, range_type
, cu
);
17431 /* set_die_type should be already done. */
17432 set_descriptive_type (range_type
, die
, cu
);
17437 static struct type
*
17438 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17442 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17444 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17446 /* In Ada, an unspecified type is typically used when the description
17447 of the type is deferred to a different unit. When encountering
17448 such a type, we treat it as a stub, and try to resolve it later on,
17450 if (cu
->language
== language_ada
)
17451 TYPE_STUB (type
) = 1;
17453 return set_die_type (die
, type
, cu
);
17456 /* Read a single die and all its descendents. Set the die's sibling
17457 field to NULL; set other fields in the die correctly, and set all
17458 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17459 location of the info_ptr after reading all of those dies. PARENT
17460 is the parent of the die in question. */
17462 static struct die_info
*
17463 read_die_and_children (const struct die_reader_specs
*reader
,
17464 const gdb_byte
*info_ptr
,
17465 const gdb_byte
**new_info_ptr
,
17466 struct die_info
*parent
)
17468 struct die_info
*die
;
17469 const gdb_byte
*cur_ptr
;
17471 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17474 *new_info_ptr
= cur_ptr
;
17477 store_in_ref_table (die
, reader
->cu
);
17479 if (die
->has_children
)
17480 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17484 *new_info_ptr
= cur_ptr
;
17487 die
->sibling
= NULL
;
17488 die
->parent
= parent
;
17492 /* Read a die, all of its descendents, and all of its siblings; set
17493 all of the fields of all of the dies correctly. Arguments are as
17494 in read_die_and_children. */
17496 static struct die_info
*
17497 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17498 const gdb_byte
*info_ptr
,
17499 const gdb_byte
**new_info_ptr
,
17500 struct die_info
*parent
)
17502 struct die_info
*first_die
, *last_sibling
;
17503 const gdb_byte
*cur_ptr
;
17505 cur_ptr
= info_ptr
;
17506 first_die
= last_sibling
= NULL
;
17510 struct die_info
*die
17511 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17515 *new_info_ptr
= cur_ptr
;
17522 last_sibling
->sibling
= die
;
17524 last_sibling
= die
;
17528 /* Read a die, all of its descendents, and all of its siblings; set
17529 all of the fields of all of the dies correctly. Arguments are as
17530 in read_die_and_children.
17531 This the main entry point for reading a DIE and all its children. */
17533 static struct die_info
*
17534 read_die_and_siblings (const struct die_reader_specs
*reader
,
17535 const gdb_byte
*info_ptr
,
17536 const gdb_byte
**new_info_ptr
,
17537 struct die_info
*parent
)
17539 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17540 new_info_ptr
, parent
);
17542 if (dwarf_die_debug
)
17544 fprintf_unfiltered (gdb_stdlog
,
17545 "Read die from %s@0x%x of %s:\n",
17546 reader
->die_section
->get_name (),
17547 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17548 bfd_get_filename (reader
->abfd
));
17549 dump_die (die
, dwarf_die_debug
);
17555 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17557 The caller is responsible for filling in the extra attributes
17558 and updating (*DIEP)->num_attrs.
17559 Set DIEP to point to a newly allocated die with its information,
17560 except for its child, sibling, and parent fields. */
17562 static const gdb_byte
*
17563 read_full_die_1 (const struct die_reader_specs
*reader
,
17564 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17565 int num_extra_attrs
)
17567 unsigned int abbrev_number
, bytes_read
, i
;
17568 struct abbrev_info
*abbrev
;
17569 struct die_info
*die
;
17570 struct dwarf2_cu
*cu
= reader
->cu
;
17571 bfd
*abfd
= reader
->abfd
;
17573 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17574 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17575 info_ptr
+= bytes_read
;
17576 if (!abbrev_number
)
17582 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17584 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17586 bfd_get_filename (abfd
));
17588 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17589 die
->sect_off
= sect_off
;
17590 die
->tag
= abbrev
->tag
;
17591 die
->abbrev
= abbrev_number
;
17592 die
->has_children
= abbrev
->has_children
;
17594 /* Make the result usable.
17595 The caller needs to update num_attrs after adding the extra
17597 die
->num_attrs
= abbrev
->num_attrs
;
17599 std::vector
<int> indexes_that_need_reprocess
;
17600 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17602 bool need_reprocess
;
17604 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17605 info_ptr
, &need_reprocess
);
17606 if (need_reprocess
)
17607 indexes_that_need_reprocess
.push_back (i
);
17610 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17611 if (attr
!= nullptr)
17612 cu
->str_offsets_base
= DW_UNSND (attr
);
17614 auto maybe_addr_base
= lookup_addr_base(die
);
17615 if (maybe_addr_base
.has_value ())
17616 cu
->addr_base
= *maybe_addr_base
;
17617 for (int index
: indexes_that_need_reprocess
)
17618 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17623 /* Read a die and all its attributes.
17624 Set DIEP to point to a newly allocated die with its information,
17625 except for its child, sibling, and parent fields. */
17627 static const gdb_byte
*
17628 read_full_die (const struct die_reader_specs
*reader
,
17629 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17631 const gdb_byte
*result
;
17633 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17635 if (dwarf_die_debug
)
17637 fprintf_unfiltered (gdb_stdlog
,
17638 "Read die from %s@0x%x of %s:\n",
17639 reader
->die_section
->get_name (),
17640 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17641 bfd_get_filename (reader
->abfd
));
17642 dump_die (*diep
, dwarf_die_debug
);
17649 /* Returns nonzero if TAG represents a type that we might generate a partial
17653 is_type_tag_for_partial (int tag
)
17658 /* Some types that would be reasonable to generate partial symbols for,
17659 that we don't at present. */
17660 case DW_TAG_array_type
:
17661 case DW_TAG_file_type
:
17662 case DW_TAG_ptr_to_member_type
:
17663 case DW_TAG_set_type
:
17664 case DW_TAG_string_type
:
17665 case DW_TAG_subroutine_type
:
17667 case DW_TAG_base_type
:
17668 case DW_TAG_class_type
:
17669 case DW_TAG_interface_type
:
17670 case DW_TAG_enumeration_type
:
17671 case DW_TAG_structure_type
:
17672 case DW_TAG_subrange_type
:
17673 case DW_TAG_typedef
:
17674 case DW_TAG_union_type
:
17681 /* Load all DIEs that are interesting for partial symbols into memory. */
17683 static struct partial_die_info
*
17684 load_partial_dies (const struct die_reader_specs
*reader
,
17685 const gdb_byte
*info_ptr
, int building_psymtab
)
17687 struct dwarf2_cu
*cu
= reader
->cu
;
17688 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17689 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17690 unsigned int bytes_read
;
17691 unsigned int load_all
= 0;
17692 int nesting_level
= 1;
17697 gdb_assert (cu
->per_cu
!= NULL
);
17698 if (cu
->per_cu
->load_all_dies
)
17702 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17706 &cu
->comp_unit_obstack
,
17707 hashtab_obstack_allocate
,
17708 dummy_obstack_deallocate
);
17712 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17714 /* A NULL abbrev means the end of a series of children. */
17715 if (abbrev
== NULL
)
17717 if (--nesting_level
== 0)
17720 info_ptr
+= bytes_read
;
17721 last_die
= parent_die
;
17722 parent_die
= parent_die
->die_parent
;
17726 /* Check for template arguments. We never save these; if
17727 they're seen, we just mark the parent, and go on our way. */
17728 if (parent_die
!= NULL
17729 && cu
->language
== language_cplus
17730 && (abbrev
->tag
== DW_TAG_template_type_param
17731 || abbrev
->tag
== DW_TAG_template_value_param
))
17733 parent_die
->has_template_arguments
= 1;
17737 /* We don't need a partial DIE for the template argument. */
17738 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17743 /* We only recurse into c++ subprograms looking for template arguments.
17744 Skip their other children. */
17746 && cu
->language
== language_cplus
17747 && parent_die
!= NULL
17748 && parent_die
->tag
== DW_TAG_subprogram
)
17750 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17754 /* Check whether this DIE is interesting enough to save. Normally
17755 we would not be interested in members here, but there may be
17756 later variables referencing them via DW_AT_specification (for
17757 static members). */
17759 && !is_type_tag_for_partial (abbrev
->tag
)
17760 && abbrev
->tag
!= DW_TAG_constant
17761 && abbrev
->tag
!= DW_TAG_enumerator
17762 && abbrev
->tag
!= DW_TAG_subprogram
17763 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17764 && abbrev
->tag
!= DW_TAG_lexical_block
17765 && abbrev
->tag
!= DW_TAG_variable
17766 && abbrev
->tag
!= DW_TAG_namespace
17767 && abbrev
->tag
!= DW_TAG_module
17768 && abbrev
->tag
!= DW_TAG_member
17769 && abbrev
->tag
!= DW_TAG_imported_unit
17770 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17772 /* Otherwise we skip to the next sibling, if any. */
17773 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17777 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17780 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17782 /* This two-pass algorithm for processing partial symbols has a
17783 high cost in cache pressure. Thus, handle some simple cases
17784 here which cover the majority of C partial symbols. DIEs
17785 which neither have specification tags in them, nor could have
17786 specification tags elsewhere pointing at them, can simply be
17787 processed and discarded.
17789 This segment is also optional; scan_partial_symbols and
17790 add_partial_symbol will handle these DIEs if we chain
17791 them in normally. When compilers which do not emit large
17792 quantities of duplicate debug information are more common,
17793 this code can probably be removed. */
17795 /* Any complete simple types at the top level (pretty much all
17796 of them, for a language without namespaces), can be processed
17798 if (parent_die
== NULL
17799 && pdi
.has_specification
== 0
17800 && pdi
.is_declaration
== 0
17801 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17802 || pdi
.tag
== DW_TAG_base_type
17803 || pdi
.tag
== DW_TAG_subrange_type
))
17805 if (building_psymtab
&& pdi
.name
!= NULL
)
17806 add_psymbol_to_list (pdi
.name
, false,
17807 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17808 psymbol_placement::STATIC
,
17809 0, cu
->language
, objfile
);
17810 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17814 /* The exception for DW_TAG_typedef with has_children above is
17815 a workaround of GCC PR debug/47510. In the case of this complaint
17816 type_name_or_error will error on such types later.
17818 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17819 it could not find the child DIEs referenced later, this is checked
17820 above. In correct DWARF DW_TAG_typedef should have no children. */
17822 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17823 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17824 "- DIE at %s [in module %s]"),
17825 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17827 /* If we're at the second level, and we're an enumerator, and
17828 our parent has no specification (meaning possibly lives in a
17829 namespace elsewhere), then we can add the partial symbol now
17830 instead of queueing it. */
17831 if (pdi
.tag
== DW_TAG_enumerator
17832 && parent_die
!= NULL
17833 && parent_die
->die_parent
== NULL
17834 && parent_die
->tag
== DW_TAG_enumeration_type
17835 && parent_die
->has_specification
== 0)
17837 if (pdi
.name
== NULL
)
17838 complaint (_("malformed enumerator DIE ignored"));
17839 else if (building_psymtab
)
17840 add_psymbol_to_list (pdi
.name
, false,
17841 VAR_DOMAIN
, LOC_CONST
, -1,
17842 cu
->language
== language_cplus
17843 ? psymbol_placement::GLOBAL
17844 : psymbol_placement::STATIC
,
17845 0, cu
->language
, objfile
);
17847 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17851 struct partial_die_info
*part_die
17852 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17854 /* We'll save this DIE so link it in. */
17855 part_die
->die_parent
= parent_die
;
17856 part_die
->die_sibling
= NULL
;
17857 part_die
->die_child
= NULL
;
17859 if (last_die
&& last_die
== parent_die
)
17860 last_die
->die_child
= part_die
;
17862 last_die
->die_sibling
= part_die
;
17864 last_die
= part_die
;
17866 if (first_die
== NULL
)
17867 first_die
= part_die
;
17869 /* Maybe add the DIE to the hash table. Not all DIEs that we
17870 find interesting need to be in the hash table, because we
17871 also have the parent/sibling/child chains; only those that we
17872 might refer to by offset later during partial symbol reading.
17874 For now this means things that might have be the target of a
17875 DW_AT_specification, DW_AT_abstract_origin, or
17876 DW_AT_extension. DW_AT_extension will refer only to
17877 namespaces; DW_AT_abstract_origin refers to functions (and
17878 many things under the function DIE, but we do not recurse
17879 into function DIEs during partial symbol reading) and
17880 possibly variables as well; DW_AT_specification refers to
17881 declarations. Declarations ought to have the DW_AT_declaration
17882 flag. It happens that GCC forgets to put it in sometimes, but
17883 only for functions, not for types.
17885 Adding more things than necessary to the hash table is harmless
17886 except for the performance cost. Adding too few will result in
17887 wasted time in find_partial_die, when we reread the compilation
17888 unit with load_all_dies set. */
17891 || abbrev
->tag
== DW_TAG_constant
17892 || abbrev
->tag
== DW_TAG_subprogram
17893 || abbrev
->tag
== DW_TAG_variable
17894 || abbrev
->tag
== DW_TAG_namespace
17895 || part_die
->is_declaration
)
17899 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17900 to_underlying (part_die
->sect_off
),
17905 /* For some DIEs we want to follow their children (if any). For C
17906 we have no reason to follow the children of structures; for other
17907 languages we have to, so that we can get at method physnames
17908 to infer fully qualified class names, for DW_AT_specification,
17909 and for C++ template arguments. For C++, we also look one level
17910 inside functions to find template arguments (if the name of the
17911 function does not already contain the template arguments).
17913 For Ada and Fortran, we need to scan the children of subprograms
17914 and lexical blocks as well because these languages allow the
17915 definition of nested entities that could be interesting for the
17916 debugger, such as nested subprograms for instance. */
17917 if (last_die
->has_children
17919 || last_die
->tag
== DW_TAG_namespace
17920 || last_die
->tag
== DW_TAG_module
17921 || last_die
->tag
== DW_TAG_enumeration_type
17922 || (cu
->language
== language_cplus
17923 && last_die
->tag
== DW_TAG_subprogram
17924 && (last_die
->name
== NULL
17925 || strchr (last_die
->name
, '<') == NULL
))
17926 || (cu
->language
!= language_c
17927 && (last_die
->tag
== DW_TAG_class_type
17928 || last_die
->tag
== DW_TAG_interface_type
17929 || last_die
->tag
== DW_TAG_structure_type
17930 || last_die
->tag
== DW_TAG_union_type
))
17931 || ((cu
->language
== language_ada
17932 || cu
->language
== language_fortran
)
17933 && (last_die
->tag
== DW_TAG_subprogram
17934 || last_die
->tag
== DW_TAG_lexical_block
))))
17937 parent_die
= last_die
;
17941 /* Otherwise we skip to the next sibling, if any. */
17942 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17944 /* Back to the top, do it again. */
17948 partial_die_info::partial_die_info (sect_offset sect_off_
,
17949 struct abbrev_info
*abbrev
)
17950 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17954 /* Read a minimal amount of information into the minimal die structure.
17955 INFO_PTR should point just after the initial uleb128 of a DIE. */
17958 partial_die_info::read (const struct die_reader_specs
*reader
,
17959 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17961 struct dwarf2_cu
*cu
= reader
->cu
;
17962 struct dwarf2_per_objfile
*dwarf2_per_objfile
17963 = cu
->per_cu
->dwarf2_per_objfile
;
17965 int has_low_pc_attr
= 0;
17966 int has_high_pc_attr
= 0;
17967 int high_pc_relative
= 0;
17969 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17970 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17972 bool need_reprocess
;
17973 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17974 info_ptr
, &need_reprocess
);
17975 /* String and address offsets that need to do the reprocessing have
17976 already been read at this point, so there is no need to wait until
17977 the loop terminates to do the reprocessing. */
17978 if (need_reprocess
)
17979 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17980 attribute
&attr
= attr_vec
[i
];
17981 /* Store the data if it is of an attribute we want to keep in a
17982 partial symbol table. */
17988 case DW_TAG_compile_unit
:
17989 case DW_TAG_partial_unit
:
17990 case DW_TAG_type_unit
:
17991 /* Compilation units have a DW_AT_name that is a filename, not
17992 a source language identifier. */
17993 case DW_TAG_enumeration_type
:
17994 case DW_TAG_enumerator
:
17995 /* These tags always have simple identifiers already; no need
17996 to canonicalize them. */
17997 name
= DW_STRING (&attr
);
18001 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18004 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18009 case DW_AT_linkage_name
:
18010 case DW_AT_MIPS_linkage_name
:
18011 /* Note that both forms of linkage name might appear. We
18012 assume they will be the same, and we only store the last
18014 linkage_name
= DW_STRING (&attr
);
18017 has_low_pc_attr
= 1;
18018 lowpc
= attr
.value_as_address ();
18020 case DW_AT_high_pc
:
18021 has_high_pc_attr
= 1;
18022 highpc
= attr
.value_as_address ();
18023 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18024 high_pc_relative
= 1;
18026 case DW_AT_location
:
18027 /* Support the .debug_loc offsets. */
18028 if (attr
.form_is_block ())
18030 d
.locdesc
= DW_BLOCK (&attr
);
18032 else if (attr
.form_is_section_offset ())
18034 dwarf2_complex_location_expr_complaint ();
18038 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18039 "partial symbol information");
18042 case DW_AT_external
:
18043 is_external
= DW_UNSND (&attr
);
18045 case DW_AT_declaration
:
18046 is_declaration
= DW_UNSND (&attr
);
18051 case DW_AT_abstract_origin
:
18052 case DW_AT_specification
:
18053 case DW_AT_extension
:
18054 has_specification
= 1;
18055 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18056 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18057 || cu
->per_cu
->is_dwz
);
18059 case DW_AT_sibling
:
18060 /* Ignore absolute siblings, they might point outside of
18061 the current compile unit. */
18062 if (attr
.form
== DW_FORM_ref_addr
)
18063 complaint (_("ignoring absolute DW_AT_sibling"));
18066 const gdb_byte
*buffer
= reader
->buffer
;
18067 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18068 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18070 if (sibling_ptr
< info_ptr
)
18071 complaint (_("DW_AT_sibling points backwards"));
18072 else if (sibling_ptr
> reader
->buffer_end
)
18073 reader
->die_section
->overflow_complaint ();
18075 sibling
= sibling_ptr
;
18078 case DW_AT_byte_size
:
18081 case DW_AT_const_value
:
18082 has_const_value
= 1;
18084 case DW_AT_calling_convention
:
18085 /* DWARF doesn't provide a way to identify a program's source-level
18086 entry point. DW_AT_calling_convention attributes are only meant
18087 to describe functions' calling conventions.
18089 However, because it's a necessary piece of information in
18090 Fortran, and before DWARF 4 DW_CC_program was the only
18091 piece of debugging information whose definition refers to
18092 a 'main program' at all, several compilers marked Fortran
18093 main programs with DW_CC_program --- even when those
18094 functions use the standard calling conventions.
18096 Although DWARF now specifies a way to provide this
18097 information, we support this practice for backward
18099 if (DW_UNSND (&attr
) == DW_CC_program
18100 && cu
->language
== language_fortran
)
18101 main_subprogram
= 1;
18104 if (DW_UNSND (&attr
) == DW_INL_inlined
18105 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18106 may_be_inlined
= 1;
18110 if (tag
== DW_TAG_imported_unit
)
18112 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18113 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18114 || cu
->per_cu
->is_dwz
);
18118 case DW_AT_main_subprogram
:
18119 main_subprogram
= DW_UNSND (&attr
);
18124 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18125 but that requires a full DIE, so instead we just
18127 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18128 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18129 + (need_ranges_base
18133 /* Value of the DW_AT_ranges attribute is the offset in the
18134 .debug_ranges section. */
18135 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18146 /* For Ada, if both the name and the linkage name appear, we prefer
18147 the latter. This lets "catch exception" work better, regardless
18148 of the order in which the name and linkage name were emitted.
18149 Really, though, this is just a workaround for the fact that gdb
18150 doesn't store both the name and the linkage name. */
18151 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18152 name
= linkage_name
;
18154 if (high_pc_relative
)
18157 if (has_low_pc_attr
&& has_high_pc_attr
)
18159 /* When using the GNU linker, .gnu.linkonce. sections are used to
18160 eliminate duplicate copies of functions and vtables and such.
18161 The linker will arbitrarily choose one and discard the others.
18162 The AT_*_pc values for such functions refer to local labels in
18163 these sections. If the section from that file was discarded, the
18164 labels are not in the output, so the relocs get a value of 0.
18165 If this is a discarded function, mark the pc bounds as invalid,
18166 so that GDB will ignore it. */
18167 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18169 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18170 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18172 complaint (_("DW_AT_low_pc %s is zero "
18173 "for DIE at %s [in module %s]"),
18174 paddress (gdbarch
, lowpc
),
18175 sect_offset_str (sect_off
),
18176 objfile_name (objfile
));
18178 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18179 else if (lowpc
>= highpc
)
18181 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18182 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18184 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18185 "for DIE at %s [in module %s]"),
18186 paddress (gdbarch
, lowpc
),
18187 paddress (gdbarch
, highpc
),
18188 sect_offset_str (sect_off
),
18189 objfile_name (objfile
));
18198 /* Find a cached partial DIE at OFFSET in CU. */
18200 struct partial_die_info
*
18201 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18203 struct partial_die_info
*lookup_die
= NULL
;
18204 struct partial_die_info
part_die (sect_off
);
18206 lookup_die
= ((struct partial_die_info
*)
18207 htab_find_with_hash (partial_dies
, &part_die
,
18208 to_underlying (sect_off
)));
18213 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18214 except in the case of .debug_types DIEs which do not reference
18215 outside their CU (they do however referencing other types via
18216 DW_FORM_ref_sig8). */
18218 static const struct cu_partial_die_info
18219 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18221 struct dwarf2_per_objfile
*dwarf2_per_objfile
18222 = cu
->per_cu
->dwarf2_per_objfile
;
18223 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18224 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18225 struct partial_die_info
*pd
= NULL
;
18227 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18228 && cu
->header
.offset_in_cu_p (sect_off
))
18230 pd
= cu
->find_partial_die (sect_off
);
18233 /* We missed recording what we needed.
18234 Load all dies and try again. */
18235 per_cu
= cu
->per_cu
;
18239 /* TUs don't reference other CUs/TUs (except via type signatures). */
18240 if (cu
->per_cu
->is_debug_types
)
18242 error (_("Dwarf Error: Type Unit at offset %s contains"
18243 " external reference to offset %s [in module %s].\n"),
18244 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18245 bfd_get_filename (objfile
->obfd
));
18247 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18248 dwarf2_per_objfile
);
18250 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18251 load_partial_comp_unit (per_cu
);
18253 per_cu
->cu
->last_used
= 0;
18254 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18257 /* If we didn't find it, and not all dies have been loaded,
18258 load them all and try again. */
18260 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18262 per_cu
->load_all_dies
= 1;
18264 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18265 THIS_CU->cu may already be in use. So we can't just free it and
18266 replace its DIEs with the ones we read in. Instead, we leave those
18267 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18268 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18270 load_partial_comp_unit (per_cu
);
18272 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18276 internal_error (__FILE__
, __LINE__
,
18277 _("could not find partial DIE %s "
18278 "in cache [from module %s]\n"),
18279 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18280 return { per_cu
->cu
, pd
};
18283 /* See if we can figure out if the class lives in a namespace. We do
18284 this by looking for a member function; its demangled name will
18285 contain namespace info, if there is any. */
18288 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18289 struct dwarf2_cu
*cu
)
18291 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18292 what template types look like, because the demangler
18293 frequently doesn't give the same name as the debug info. We
18294 could fix this by only using the demangled name to get the
18295 prefix (but see comment in read_structure_type). */
18297 struct partial_die_info
*real_pdi
;
18298 struct partial_die_info
*child_pdi
;
18300 /* If this DIE (this DIE's specification, if any) has a parent, then
18301 we should not do this. We'll prepend the parent's fully qualified
18302 name when we create the partial symbol. */
18304 real_pdi
= struct_pdi
;
18305 while (real_pdi
->has_specification
)
18307 auto res
= find_partial_die (real_pdi
->spec_offset
,
18308 real_pdi
->spec_is_dwz
, cu
);
18309 real_pdi
= res
.pdi
;
18313 if (real_pdi
->die_parent
!= NULL
)
18316 for (child_pdi
= struct_pdi
->die_child
;
18318 child_pdi
= child_pdi
->die_sibling
)
18320 if (child_pdi
->tag
== DW_TAG_subprogram
18321 && child_pdi
->linkage_name
!= NULL
)
18323 gdb::unique_xmalloc_ptr
<char> actual_class_name
18324 (language_class_name_from_physname (cu
->language_defn
,
18325 child_pdi
->linkage_name
));
18326 if (actual_class_name
!= NULL
)
18328 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18329 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18337 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18339 /* Once we've fixed up a die, there's no point in doing so again.
18340 This also avoids a memory leak if we were to call
18341 guess_partial_die_structure_name multiple times. */
18345 /* If we found a reference attribute and the DIE has no name, try
18346 to find a name in the referred to DIE. */
18348 if (name
== NULL
&& has_specification
)
18350 struct partial_die_info
*spec_die
;
18352 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18353 spec_die
= res
.pdi
;
18356 spec_die
->fixup (cu
);
18358 if (spec_die
->name
)
18360 name
= spec_die
->name
;
18362 /* Copy DW_AT_external attribute if it is set. */
18363 if (spec_die
->is_external
)
18364 is_external
= spec_die
->is_external
;
18368 /* Set default names for some unnamed DIEs. */
18370 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18371 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18373 /* If there is no parent die to provide a namespace, and there are
18374 children, see if we can determine the namespace from their linkage
18376 if (cu
->language
== language_cplus
18377 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18378 && die_parent
== NULL
18380 && (tag
== DW_TAG_class_type
18381 || tag
== DW_TAG_structure_type
18382 || tag
== DW_TAG_union_type
))
18383 guess_partial_die_structure_name (this, cu
);
18385 /* GCC might emit a nameless struct or union that has a linkage
18386 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18388 && (tag
== DW_TAG_class_type
18389 || tag
== DW_TAG_interface_type
18390 || tag
== DW_TAG_structure_type
18391 || tag
== DW_TAG_union_type
)
18392 && linkage_name
!= NULL
)
18394 gdb::unique_xmalloc_ptr
<char> demangled
18395 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18396 if (demangled
!= nullptr)
18400 /* Strip any leading namespaces/classes, keep only the base name.
18401 DW_AT_name for named DIEs does not contain the prefixes. */
18402 base
= strrchr (demangled
.get (), ':');
18403 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18406 base
= demangled
.get ();
18408 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18409 name
= objfile
->intern (base
);
18416 /* Process the attributes that had to be skipped in the first round. These
18417 attributes are the ones that need str_offsets_base or addr_base attributes.
18418 They could not have been processed in the first round, because at the time
18419 the values of str_offsets_base or addr_base may not have been known. */
18420 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18421 struct attribute
*attr
)
18423 struct dwarf2_cu
*cu
= reader
->cu
;
18424 switch (attr
->form
)
18426 case DW_FORM_addrx
:
18427 case DW_FORM_GNU_addr_index
:
18428 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18431 case DW_FORM_strx1
:
18432 case DW_FORM_strx2
:
18433 case DW_FORM_strx3
:
18434 case DW_FORM_strx4
:
18435 case DW_FORM_GNU_str_index
:
18437 unsigned int str_index
= DW_UNSND (attr
);
18438 if (reader
->dwo_file
!= NULL
)
18440 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18441 DW_STRING_IS_CANONICAL (attr
) = 0;
18445 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18446 DW_STRING_IS_CANONICAL (attr
) = 0;
18451 gdb_assert_not_reached (_("Unexpected DWARF form."));
18455 /* Read an attribute value described by an attribute form. */
18457 static const gdb_byte
*
18458 read_attribute_value (const struct die_reader_specs
*reader
,
18459 struct attribute
*attr
, unsigned form
,
18460 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18461 bool *need_reprocess
)
18463 struct dwarf2_cu
*cu
= reader
->cu
;
18464 struct dwarf2_per_objfile
*dwarf2_per_objfile
18465 = cu
->per_cu
->dwarf2_per_objfile
;
18466 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18467 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18468 bfd
*abfd
= reader
->abfd
;
18469 struct comp_unit_head
*cu_header
= &cu
->header
;
18470 unsigned int bytes_read
;
18471 struct dwarf_block
*blk
;
18472 *need_reprocess
= false;
18474 attr
->form
= (enum dwarf_form
) form
;
18477 case DW_FORM_ref_addr
:
18478 if (cu
->header
.version
== 2)
18479 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18482 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18484 info_ptr
+= bytes_read
;
18486 case DW_FORM_GNU_ref_alt
:
18487 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18488 info_ptr
+= bytes_read
;
18491 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18492 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18493 info_ptr
+= bytes_read
;
18495 case DW_FORM_block2
:
18496 blk
= dwarf_alloc_block (cu
);
18497 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18499 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18500 info_ptr
+= blk
->size
;
18501 DW_BLOCK (attr
) = blk
;
18503 case DW_FORM_block4
:
18504 blk
= dwarf_alloc_block (cu
);
18505 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18507 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18508 info_ptr
+= blk
->size
;
18509 DW_BLOCK (attr
) = blk
;
18511 case DW_FORM_data2
:
18512 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18515 case DW_FORM_data4
:
18516 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18519 case DW_FORM_data8
:
18520 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18523 case DW_FORM_data16
:
18524 blk
= dwarf_alloc_block (cu
);
18526 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18528 DW_BLOCK (attr
) = blk
;
18530 case DW_FORM_sec_offset
:
18531 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18532 info_ptr
+= bytes_read
;
18534 case DW_FORM_string
:
18535 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18536 DW_STRING_IS_CANONICAL (attr
) = 0;
18537 info_ptr
+= bytes_read
;
18540 if (!cu
->per_cu
->is_dwz
)
18542 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18543 abfd
, info_ptr
, cu_header
,
18545 DW_STRING_IS_CANONICAL (attr
) = 0;
18546 info_ptr
+= bytes_read
;
18550 case DW_FORM_line_strp
:
18551 if (!cu
->per_cu
->is_dwz
)
18553 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18555 cu_header
, &bytes_read
);
18556 DW_STRING_IS_CANONICAL (attr
) = 0;
18557 info_ptr
+= bytes_read
;
18561 case DW_FORM_GNU_strp_alt
:
18563 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18564 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18567 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18568 DW_STRING_IS_CANONICAL (attr
) = 0;
18569 info_ptr
+= bytes_read
;
18572 case DW_FORM_exprloc
:
18573 case DW_FORM_block
:
18574 blk
= dwarf_alloc_block (cu
);
18575 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18576 info_ptr
+= bytes_read
;
18577 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18578 info_ptr
+= blk
->size
;
18579 DW_BLOCK (attr
) = blk
;
18581 case DW_FORM_block1
:
18582 blk
= dwarf_alloc_block (cu
);
18583 blk
->size
= read_1_byte (abfd
, info_ptr
);
18585 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18586 info_ptr
+= blk
->size
;
18587 DW_BLOCK (attr
) = blk
;
18589 case DW_FORM_data1
:
18590 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18594 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18597 case DW_FORM_flag_present
:
18598 DW_UNSND (attr
) = 1;
18600 case DW_FORM_sdata
:
18601 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18602 info_ptr
+= bytes_read
;
18604 case DW_FORM_udata
:
18605 case DW_FORM_rnglistx
:
18606 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18607 info_ptr
+= bytes_read
;
18610 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18611 + read_1_byte (abfd
, info_ptr
));
18615 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18616 + read_2_bytes (abfd
, info_ptr
));
18620 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18621 + read_4_bytes (abfd
, info_ptr
));
18625 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18626 + read_8_bytes (abfd
, info_ptr
));
18629 case DW_FORM_ref_sig8
:
18630 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18633 case DW_FORM_ref_udata
:
18634 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18635 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18636 info_ptr
+= bytes_read
;
18638 case DW_FORM_indirect
:
18639 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18640 info_ptr
+= bytes_read
;
18641 if (form
== DW_FORM_implicit_const
)
18643 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18644 info_ptr
+= bytes_read
;
18646 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18647 info_ptr
, need_reprocess
);
18649 case DW_FORM_implicit_const
:
18650 DW_SND (attr
) = implicit_const
;
18652 case DW_FORM_addrx
:
18653 case DW_FORM_GNU_addr_index
:
18654 *need_reprocess
= true;
18655 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18656 info_ptr
+= bytes_read
;
18659 case DW_FORM_strx1
:
18660 case DW_FORM_strx2
:
18661 case DW_FORM_strx3
:
18662 case DW_FORM_strx4
:
18663 case DW_FORM_GNU_str_index
:
18665 ULONGEST str_index
;
18666 if (form
== DW_FORM_strx1
)
18668 str_index
= read_1_byte (abfd
, info_ptr
);
18671 else if (form
== DW_FORM_strx2
)
18673 str_index
= read_2_bytes (abfd
, info_ptr
);
18676 else if (form
== DW_FORM_strx3
)
18678 str_index
= read_3_bytes (abfd
, info_ptr
);
18681 else if (form
== DW_FORM_strx4
)
18683 str_index
= read_4_bytes (abfd
, info_ptr
);
18688 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18689 info_ptr
+= bytes_read
;
18691 *need_reprocess
= true;
18692 DW_UNSND (attr
) = str_index
;
18696 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18697 dwarf_form_name (form
),
18698 bfd_get_filename (abfd
));
18702 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18703 attr
->form
= DW_FORM_GNU_ref_alt
;
18705 /* We have seen instances where the compiler tried to emit a byte
18706 size attribute of -1 which ended up being encoded as an unsigned
18707 0xffffffff. Although 0xffffffff is technically a valid size value,
18708 an object of this size seems pretty unlikely so we can relatively
18709 safely treat these cases as if the size attribute was invalid and
18710 treat them as zero by default. */
18711 if (attr
->name
== DW_AT_byte_size
18712 && form
== DW_FORM_data4
18713 && DW_UNSND (attr
) >= 0xffffffff)
18716 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18717 hex_string (DW_UNSND (attr
)));
18718 DW_UNSND (attr
) = 0;
18724 /* Read an attribute described by an abbreviated attribute. */
18726 static const gdb_byte
*
18727 read_attribute (const struct die_reader_specs
*reader
,
18728 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18729 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18731 attr
->name
= abbrev
->name
;
18732 return read_attribute_value (reader
, attr
, abbrev
->form
,
18733 abbrev
->implicit_const
, info_ptr
,
18737 /* Cover function for read_initial_length.
18738 Returns the length of the object at BUF, and stores the size of the
18739 initial length in *BYTES_READ and stores the size that offsets will be in
18741 If the initial length size is not equivalent to that specified in
18742 CU_HEADER then issue a complaint.
18743 This is useful when reading non-comp-unit headers. */
18746 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18747 const struct comp_unit_head
*cu_header
,
18748 unsigned int *bytes_read
,
18749 unsigned int *offset_size
)
18751 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18753 gdb_assert (cu_header
->initial_length_size
== 4
18754 || cu_header
->initial_length_size
== 8
18755 || cu_header
->initial_length_size
== 12);
18757 if (cu_header
->initial_length_size
!= *bytes_read
)
18758 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18760 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18764 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18766 static const char *
18767 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18768 LONGEST str_offset
)
18770 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18771 str_offset
, "DW_FORM_strp");
18774 /* Return pointer to string at .debug_str offset as read from BUF.
18775 BUF is assumed to be in a compilation unit described by CU_HEADER.
18776 Return *BYTES_READ_PTR count of bytes read from BUF. */
18778 static const char *
18779 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18780 const gdb_byte
*buf
,
18781 const struct comp_unit_head
*cu_header
,
18782 unsigned int *bytes_read_ptr
)
18784 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18786 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18789 /* Return pointer to string at .debug_line_str offset as read from BUF.
18790 BUF is assumed to be in a compilation unit described by CU_HEADER.
18791 Return *BYTES_READ_PTR count of bytes read from BUF. */
18793 static const char *
18794 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18795 bfd
*abfd
, const gdb_byte
*buf
,
18796 const struct comp_unit_head
*cu_header
,
18797 unsigned int *bytes_read_ptr
)
18799 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18801 return dwarf2_per_objfile
->line_str
.read_string (dwarf2_per_objfile
->objfile
,
18803 "DW_FORM_line_strp");
18806 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18807 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18808 ADDR_SIZE is the size of addresses from the CU header. */
18811 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18812 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18815 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18816 bfd
*abfd
= objfile
->obfd
;
18817 const gdb_byte
*info_ptr
;
18818 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18820 dwarf2_per_objfile
->addr
.read (objfile
);
18821 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18822 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18823 objfile_name (objfile
));
18824 if (addr_base_or_zero
+ addr_index
* addr_size
18825 >= dwarf2_per_objfile
->addr
.size
)
18826 error (_("DW_FORM_addr_index pointing outside of "
18827 ".debug_addr section [in module %s]"),
18828 objfile_name (objfile
));
18829 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18830 + addr_base_or_zero
+ addr_index
* addr_size
);
18831 if (addr_size
== 4)
18832 return bfd_get_32 (abfd
, info_ptr
);
18834 return bfd_get_64 (abfd
, info_ptr
);
18837 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18840 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18842 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18843 cu
->addr_base
, cu
->header
.addr_size
);
18846 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18849 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18850 unsigned int *bytes_read
)
18852 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18853 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18855 return read_addr_index (cu
, addr_index
);
18861 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18863 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18864 struct dwarf2_cu
*cu
= per_cu
->cu
;
18865 gdb::optional
<ULONGEST
> addr_base
;
18868 /* We need addr_base and addr_size.
18869 If we don't have PER_CU->cu, we have to get it.
18870 Nasty, but the alternative is storing the needed info in PER_CU,
18871 which at this point doesn't seem justified: it's not clear how frequently
18872 it would get used and it would increase the size of every PER_CU.
18873 Entry points like dwarf2_per_cu_addr_size do a similar thing
18874 so we're not in uncharted territory here.
18875 Alas we need to be a bit more complicated as addr_base is contained
18878 We don't need to read the entire CU(/TU).
18879 We just need the header and top level die.
18881 IWBN to use the aging mechanism to let us lazily later discard the CU.
18882 For now we skip this optimization. */
18886 addr_base
= cu
->addr_base
;
18887 addr_size
= cu
->header
.addr_size
;
18891 cutu_reader
reader (per_cu
, NULL
, 0, false);
18892 addr_base
= reader
.cu
->addr_base
;
18893 addr_size
= reader
.cu
->header
.addr_size
;
18896 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18900 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18901 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18904 static const char *
18905 read_str_index (struct dwarf2_cu
*cu
,
18906 struct dwarf2_section_info
*str_section
,
18907 struct dwarf2_section_info
*str_offsets_section
,
18908 ULONGEST str_offsets_base
, ULONGEST str_index
)
18910 struct dwarf2_per_objfile
*dwarf2_per_objfile
18911 = cu
->per_cu
->dwarf2_per_objfile
;
18912 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18913 const char *objf_name
= objfile_name (objfile
);
18914 bfd
*abfd
= objfile
->obfd
;
18915 const gdb_byte
*info_ptr
;
18916 ULONGEST str_offset
;
18917 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18919 str_section
->read (objfile
);
18920 str_offsets_section
->read (objfile
);
18921 if (str_section
->buffer
== NULL
)
18922 error (_("%s used without %s section"
18923 " in CU at offset %s [in module %s]"),
18924 form_name
, str_section
->get_name (),
18925 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18926 if (str_offsets_section
->buffer
== NULL
)
18927 error (_("%s used without %s section"
18928 " in CU at offset %s [in module %s]"),
18929 form_name
, str_section
->get_name (),
18930 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18931 info_ptr
= (str_offsets_section
->buffer
18933 + str_index
* cu
->header
.offset_size
);
18934 if (cu
->header
.offset_size
== 4)
18935 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18937 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18938 if (str_offset
>= str_section
->size
)
18939 error (_("Offset from %s pointing outside of"
18940 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18941 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18942 return (const char *) (str_section
->buffer
+ str_offset
);
18945 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18947 static const char *
18948 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18950 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18951 ? reader
->cu
->header
.addr_size
: 0;
18952 return read_str_index (reader
->cu
,
18953 &reader
->dwo_file
->sections
.str
,
18954 &reader
->dwo_file
->sections
.str_offsets
,
18955 str_offsets_base
, str_index
);
18958 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18960 static const char *
18961 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18963 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18964 const char *objf_name
= objfile_name (objfile
);
18965 static const char form_name
[] = "DW_FORM_GNU_str_index";
18966 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18968 if (!cu
->str_offsets_base
.has_value ())
18969 error (_("%s used in Fission stub without %s"
18970 " in CU at offset 0x%lx [in module %s]"),
18971 form_name
, str_offsets_attr_name
,
18972 (long) cu
->header
.offset_size
, objf_name
);
18974 return read_str_index (cu
,
18975 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18976 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18977 *cu
->str_offsets_base
, str_index
);
18980 /* Return the length of an LEB128 number in BUF. */
18983 leb128_size (const gdb_byte
*buf
)
18985 const gdb_byte
*begin
= buf
;
18991 if ((byte
& 128) == 0)
18992 return buf
- begin
;
18997 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19006 cu
->language
= language_c
;
19009 case DW_LANG_C_plus_plus
:
19010 case DW_LANG_C_plus_plus_11
:
19011 case DW_LANG_C_plus_plus_14
:
19012 cu
->language
= language_cplus
;
19015 cu
->language
= language_d
;
19017 case DW_LANG_Fortran77
:
19018 case DW_LANG_Fortran90
:
19019 case DW_LANG_Fortran95
:
19020 case DW_LANG_Fortran03
:
19021 case DW_LANG_Fortran08
:
19022 cu
->language
= language_fortran
;
19025 cu
->language
= language_go
;
19027 case DW_LANG_Mips_Assembler
:
19028 cu
->language
= language_asm
;
19030 case DW_LANG_Ada83
:
19031 case DW_LANG_Ada95
:
19032 cu
->language
= language_ada
;
19034 case DW_LANG_Modula2
:
19035 cu
->language
= language_m2
;
19037 case DW_LANG_Pascal83
:
19038 cu
->language
= language_pascal
;
19041 cu
->language
= language_objc
;
19044 case DW_LANG_Rust_old
:
19045 cu
->language
= language_rust
;
19047 case DW_LANG_Cobol74
:
19048 case DW_LANG_Cobol85
:
19050 cu
->language
= language_minimal
;
19053 cu
->language_defn
= language_def (cu
->language
);
19056 /* Return the named attribute or NULL if not there. */
19058 static struct attribute
*
19059 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19064 struct attribute
*spec
= NULL
;
19066 for (i
= 0; i
< die
->num_attrs
; ++i
)
19068 if (die
->attrs
[i
].name
== name
)
19069 return &die
->attrs
[i
];
19070 if (die
->attrs
[i
].name
== DW_AT_specification
19071 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19072 spec
= &die
->attrs
[i
];
19078 die
= follow_die_ref (die
, spec
, &cu
);
19084 /* Return the named attribute or NULL if not there,
19085 but do not follow DW_AT_specification, etc.
19086 This is for use in contexts where we're reading .debug_types dies.
19087 Following DW_AT_specification, DW_AT_abstract_origin will take us
19088 back up the chain, and we want to go down. */
19090 static struct attribute
*
19091 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19095 for (i
= 0; i
< die
->num_attrs
; ++i
)
19096 if (die
->attrs
[i
].name
== name
)
19097 return &die
->attrs
[i
];
19102 /* Return the string associated with a string-typed attribute, or NULL if it
19103 is either not found or is of an incorrect type. */
19105 static const char *
19106 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19108 struct attribute
*attr
;
19109 const char *str
= NULL
;
19111 attr
= dwarf2_attr (die
, name
, cu
);
19115 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19116 || attr
->form
== DW_FORM_string
19117 || attr
->form
== DW_FORM_strx
19118 || attr
->form
== DW_FORM_strx1
19119 || attr
->form
== DW_FORM_strx2
19120 || attr
->form
== DW_FORM_strx3
19121 || attr
->form
== DW_FORM_strx4
19122 || attr
->form
== DW_FORM_GNU_str_index
19123 || attr
->form
== DW_FORM_GNU_strp_alt
)
19124 str
= DW_STRING (attr
);
19126 complaint (_("string type expected for attribute %s for "
19127 "DIE at %s in module %s"),
19128 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19129 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19135 /* Return the dwo name or NULL if not present. If present, it is in either
19136 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19137 static const char *
19138 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19140 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19141 if (dwo_name
== nullptr)
19142 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19146 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19147 and holds a non-zero value. This function should only be used for
19148 DW_FORM_flag or DW_FORM_flag_present attributes. */
19151 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19153 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19155 return (attr
&& DW_UNSND (attr
));
19159 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19161 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19162 which value is non-zero. However, we have to be careful with
19163 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19164 (via dwarf2_flag_true_p) follows this attribute. So we may
19165 end up accidently finding a declaration attribute that belongs
19166 to a different DIE referenced by the specification attribute,
19167 even though the given DIE does not have a declaration attribute. */
19168 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19169 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19172 /* Return the die giving the specification for DIE, if there is
19173 one. *SPEC_CU is the CU containing DIE on input, and the CU
19174 containing the return value on output. If there is no
19175 specification, but there is an abstract origin, that is
19178 static struct die_info
*
19179 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19181 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19184 if (spec_attr
== NULL
)
19185 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19187 if (spec_attr
== NULL
)
19190 return follow_die_ref (die
, spec_attr
, spec_cu
);
19193 /* Stub for free_line_header to match void * callback types. */
19196 free_line_header_voidp (void *arg
)
19198 struct line_header
*lh
= (struct line_header
*) arg
;
19203 /* A convenience function to find the proper .debug_line section for a CU. */
19205 static struct dwarf2_section_info
*
19206 get_debug_line_section (struct dwarf2_cu
*cu
)
19208 struct dwarf2_section_info
*section
;
19209 struct dwarf2_per_objfile
*dwarf2_per_objfile
19210 = cu
->per_cu
->dwarf2_per_objfile
;
19212 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19214 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19215 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19216 else if (cu
->per_cu
->is_dwz
)
19218 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19220 section
= &dwz
->line
;
19223 section
= &dwarf2_per_objfile
->line
;
19228 /* Read directory or file name entry format, starting with byte of
19229 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19230 entries count and the entries themselves in the described entry
19234 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19235 bfd
*abfd
, const gdb_byte
**bufp
,
19236 struct line_header
*lh
,
19237 const struct comp_unit_head
*cu_header
,
19238 void (*callback
) (struct line_header
*lh
,
19241 unsigned int mod_time
,
19242 unsigned int length
))
19244 gdb_byte format_count
, formati
;
19245 ULONGEST data_count
, datai
;
19246 const gdb_byte
*buf
= *bufp
;
19247 const gdb_byte
*format_header_data
;
19248 unsigned int bytes_read
;
19250 format_count
= read_1_byte (abfd
, buf
);
19252 format_header_data
= buf
;
19253 for (formati
= 0; formati
< format_count
; formati
++)
19255 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19257 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19261 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19263 for (datai
= 0; datai
< data_count
; datai
++)
19265 const gdb_byte
*format
= format_header_data
;
19266 struct file_entry fe
;
19268 for (formati
= 0; formati
< format_count
; formati
++)
19270 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19271 format
+= bytes_read
;
19273 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19274 format
+= bytes_read
;
19276 gdb::optional
<const char *> string
;
19277 gdb::optional
<unsigned int> uint
;
19281 case DW_FORM_string
:
19282 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19286 case DW_FORM_line_strp
:
19287 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19294 case DW_FORM_data1
:
19295 uint
.emplace (read_1_byte (abfd
, buf
));
19299 case DW_FORM_data2
:
19300 uint
.emplace (read_2_bytes (abfd
, buf
));
19304 case DW_FORM_data4
:
19305 uint
.emplace (read_4_bytes (abfd
, buf
));
19309 case DW_FORM_data8
:
19310 uint
.emplace (read_8_bytes (abfd
, buf
));
19314 case DW_FORM_data16
:
19315 /* This is used for MD5, but file_entry does not record MD5s. */
19319 case DW_FORM_udata
:
19320 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19324 case DW_FORM_block
:
19325 /* It is valid only for DW_LNCT_timestamp which is ignored by
19330 switch (content_type
)
19333 if (string
.has_value ())
19336 case DW_LNCT_directory_index
:
19337 if (uint
.has_value ())
19338 fe
.d_index
= (dir_index
) *uint
;
19340 case DW_LNCT_timestamp
:
19341 if (uint
.has_value ())
19342 fe
.mod_time
= *uint
;
19345 if (uint
.has_value ())
19351 complaint (_("Unknown format content type %s"),
19352 pulongest (content_type
));
19356 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19362 /* Read the statement program header starting at OFFSET in
19363 .debug_line, or .debug_line.dwo. Return a pointer
19364 to a struct line_header, allocated using xmalloc.
19365 Returns NULL if there is a problem reading the header, e.g., if it
19366 has a version we don't understand.
19368 NOTE: the strings in the include directory and file name tables of
19369 the returned object point into the dwarf line section buffer,
19370 and must not be freed. */
19372 static line_header_up
19373 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19375 const gdb_byte
*line_ptr
;
19376 unsigned int bytes_read
, offset_size
;
19378 const char *cur_dir
, *cur_file
;
19379 struct dwarf2_section_info
*section
;
19381 struct dwarf2_per_objfile
*dwarf2_per_objfile
19382 = cu
->per_cu
->dwarf2_per_objfile
;
19384 section
= get_debug_line_section (cu
);
19385 section
->read (dwarf2_per_objfile
->objfile
);
19386 if (section
->buffer
== NULL
)
19388 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19389 complaint (_("missing .debug_line.dwo section"));
19391 complaint (_("missing .debug_line section"));
19395 /* We can't do this until we know the section is non-empty.
19396 Only then do we know we have such a section. */
19397 abfd
= section
->get_bfd_owner ();
19399 /* Make sure that at least there's room for the total_length field.
19400 That could be 12 bytes long, but we're just going to fudge that. */
19401 if (to_underlying (sect_off
) + 4 >= section
->size
)
19403 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19407 line_header_up
lh (new line_header ());
19409 lh
->sect_off
= sect_off
;
19410 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19412 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19414 /* Read in the header. */
19416 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19417 &bytes_read
, &offset_size
);
19418 line_ptr
+= bytes_read
;
19420 const gdb_byte
*start_here
= line_ptr
;
19422 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19424 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19427 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19428 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19430 if (lh
->version
> 5)
19432 /* This is a version we don't understand. The format could have
19433 changed in ways we don't handle properly so just punt. */
19434 complaint (_("unsupported version in .debug_line section"));
19437 if (lh
->version
>= 5)
19439 gdb_byte segment_selector_size
;
19441 /* Skip address size. */
19442 read_1_byte (abfd
, line_ptr
);
19445 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19447 if (segment_selector_size
!= 0)
19449 complaint (_("unsupported segment selector size %u "
19450 "in .debug_line section"),
19451 segment_selector_size
);
19455 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19456 line_ptr
+= offset_size
;
19457 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19458 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19460 if (lh
->version
>= 4)
19462 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19466 lh
->maximum_ops_per_instruction
= 1;
19468 if (lh
->maximum_ops_per_instruction
== 0)
19470 lh
->maximum_ops_per_instruction
= 1;
19471 complaint (_("invalid maximum_ops_per_instruction "
19472 "in `.debug_line' section"));
19475 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19477 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19479 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19481 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19483 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19485 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19486 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19488 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19492 if (lh
->version
>= 5)
19494 /* Read directory table. */
19495 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19497 [] (struct line_header
*header
, const char *name
,
19498 dir_index d_index
, unsigned int mod_time
,
19499 unsigned int length
)
19501 header
->add_include_dir (name
);
19504 /* Read file name table. */
19505 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19507 [] (struct line_header
*header
, const char *name
,
19508 dir_index d_index
, unsigned int mod_time
,
19509 unsigned int length
)
19511 header
->add_file_name (name
, d_index
, mod_time
, length
);
19516 /* Read directory table. */
19517 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19519 line_ptr
+= bytes_read
;
19520 lh
->add_include_dir (cur_dir
);
19522 line_ptr
+= bytes_read
;
19524 /* Read file name table. */
19525 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19527 unsigned int mod_time
, length
;
19530 line_ptr
+= bytes_read
;
19531 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19532 line_ptr
+= bytes_read
;
19533 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19534 line_ptr
+= bytes_read
;
19535 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19536 line_ptr
+= bytes_read
;
19538 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19540 line_ptr
+= bytes_read
;
19543 if (line_ptr
> (section
->buffer
+ section
->size
))
19544 complaint (_("line number info header doesn't "
19545 "fit in `.debug_line' section"));
19550 /* Subroutine of dwarf_decode_lines to simplify it.
19551 Return the file name of the psymtab for the given file_entry.
19552 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19553 If space for the result is malloc'd, *NAME_HOLDER will be set.
19554 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19556 static const char *
19557 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19558 const dwarf2_psymtab
*pst
,
19559 const char *comp_dir
,
19560 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19562 const char *include_name
= fe
.name
;
19563 const char *include_name_to_compare
= include_name
;
19564 const char *pst_filename
;
19567 const char *dir_name
= fe
.include_dir (lh
);
19569 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19570 if (!IS_ABSOLUTE_PATH (include_name
)
19571 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19573 /* Avoid creating a duplicate psymtab for PST.
19574 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19575 Before we do the comparison, however, we need to account
19576 for DIR_NAME and COMP_DIR.
19577 First prepend dir_name (if non-NULL). If we still don't
19578 have an absolute path prepend comp_dir (if non-NULL).
19579 However, the directory we record in the include-file's
19580 psymtab does not contain COMP_DIR (to match the
19581 corresponding symtab(s)).
19586 bash$ gcc -g ./hello.c
19587 include_name = "hello.c"
19589 DW_AT_comp_dir = comp_dir = "/tmp"
19590 DW_AT_name = "./hello.c"
19594 if (dir_name
!= NULL
)
19596 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19597 include_name
, (char *) NULL
));
19598 include_name
= name_holder
->get ();
19599 include_name_to_compare
= include_name
;
19601 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19603 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19604 include_name
, (char *) NULL
));
19605 include_name_to_compare
= hold_compare
.get ();
19609 pst_filename
= pst
->filename
;
19610 gdb::unique_xmalloc_ptr
<char> copied_name
;
19611 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19613 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19614 pst_filename
, (char *) NULL
));
19615 pst_filename
= copied_name
.get ();
19618 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19622 return include_name
;
19625 /* State machine to track the state of the line number program. */
19627 class lnp_state_machine
19630 /* Initialize a machine state for the start of a line number
19632 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19633 bool record_lines_p
);
19635 file_entry
*current_file ()
19637 /* lh->file_names is 0-based, but the file name numbers in the
19638 statement program are 1-based. */
19639 return m_line_header
->file_name_at (m_file
);
19642 /* Record the line in the state machine. END_SEQUENCE is true if
19643 we're processing the end of a sequence. */
19644 void record_line (bool end_sequence
);
19646 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19647 nop-out rest of the lines in this sequence. */
19648 void check_line_address (struct dwarf2_cu
*cu
,
19649 const gdb_byte
*line_ptr
,
19650 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19652 void handle_set_discriminator (unsigned int discriminator
)
19654 m_discriminator
= discriminator
;
19655 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19658 /* Handle DW_LNE_set_address. */
19659 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19662 address
+= baseaddr
;
19663 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19666 /* Handle DW_LNS_advance_pc. */
19667 void handle_advance_pc (CORE_ADDR adjust
);
19669 /* Handle a special opcode. */
19670 void handle_special_opcode (unsigned char op_code
);
19672 /* Handle DW_LNS_advance_line. */
19673 void handle_advance_line (int line_delta
)
19675 advance_line (line_delta
);
19678 /* Handle DW_LNS_set_file. */
19679 void handle_set_file (file_name_index file
);
19681 /* Handle DW_LNS_negate_stmt. */
19682 void handle_negate_stmt ()
19684 m_is_stmt
= !m_is_stmt
;
19687 /* Handle DW_LNS_const_add_pc. */
19688 void handle_const_add_pc ();
19690 /* Handle DW_LNS_fixed_advance_pc. */
19691 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19693 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19697 /* Handle DW_LNS_copy. */
19698 void handle_copy ()
19700 record_line (false);
19701 m_discriminator
= 0;
19704 /* Handle DW_LNE_end_sequence. */
19705 void handle_end_sequence ()
19707 m_currently_recording_lines
= true;
19711 /* Advance the line by LINE_DELTA. */
19712 void advance_line (int line_delta
)
19714 m_line
+= line_delta
;
19716 if (line_delta
!= 0)
19717 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19720 struct dwarf2_cu
*m_cu
;
19722 gdbarch
*m_gdbarch
;
19724 /* True if we're recording lines.
19725 Otherwise we're building partial symtabs and are just interested in
19726 finding include files mentioned by the line number program. */
19727 bool m_record_lines_p
;
19729 /* The line number header. */
19730 line_header
*m_line_header
;
19732 /* These are part of the standard DWARF line number state machine,
19733 and initialized according to the DWARF spec. */
19735 unsigned char m_op_index
= 0;
19736 /* The line table index of the current file. */
19737 file_name_index m_file
= 1;
19738 unsigned int m_line
= 1;
19740 /* These are initialized in the constructor. */
19742 CORE_ADDR m_address
;
19744 unsigned int m_discriminator
;
19746 /* Additional bits of state we need to track. */
19748 /* The last file that we called dwarf2_start_subfile for.
19749 This is only used for TLLs. */
19750 unsigned int m_last_file
= 0;
19751 /* The last file a line number was recorded for. */
19752 struct subfile
*m_last_subfile
= NULL
;
19754 /* When true, record the lines we decode. */
19755 bool m_currently_recording_lines
= false;
19757 /* The last line number that was recorded, used to coalesce
19758 consecutive entries for the same line. This can happen, for
19759 example, when discriminators are present. PR 17276. */
19760 unsigned int m_last_line
= 0;
19761 bool m_line_has_non_zero_discriminator
= false;
19765 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19767 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19768 / m_line_header
->maximum_ops_per_instruction
)
19769 * m_line_header
->minimum_instruction_length
);
19770 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19771 m_op_index
= ((m_op_index
+ adjust
)
19772 % m_line_header
->maximum_ops_per_instruction
);
19776 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19778 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19779 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19780 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19781 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19782 / m_line_header
->maximum_ops_per_instruction
)
19783 * m_line_header
->minimum_instruction_length
);
19784 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19785 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19786 % m_line_header
->maximum_ops_per_instruction
);
19788 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19789 advance_line (line_delta
);
19790 record_line (false);
19791 m_discriminator
= 0;
19795 lnp_state_machine::handle_set_file (file_name_index file
)
19799 const file_entry
*fe
= current_file ();
19801 dwarf2_debug_line_missing_file_complaint ();
19802 else if (m_record_lines_p
)
19804 const char *dir
= fe
->include_dir (m_line_header
);
19806 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19807 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19808 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19813 lnp_state_machine::handle_const_add_pc ()
19816 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19819 = (((m_op_index
+ adjust
)
19820 / m_line_header
->maximum_ops_per_instruction
)
19821 * m_line_header
->minimum_instruction_length
);
19823 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19824 m_op_index
= ((m_op_index
+ adjust
)
19825 % m_line_header
->maximum_ops_per_instruction
);
19828 /* Return non-zero if we should add LINE to the line number table.
19829 LINE is the line to add, LAST_LINE is the last line that was added,
19830 LAST_SUBFILE is the subfile for LAST_LINE.
19831 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19832 had a non-zero discriminator.
19834 We have to be careful in the presence of discriminators.
19835 E.g., for this line:
19837 for (i = 0; i < 100000; i++);
19839 clang can emit four line number entries for that one line,
19840 each with a different discriminator.
19841 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19843 However, we want gdb to coalesce all four entries into one.
19844 Otherwise the user could stepi into the middle of the line and
19845 gdb would get confused about whether the pc really was in the
19846 middle of the line.
19848 Things are further complicated by the fact that two consecutive
19849 line number entries for the same line is a heuristic used by gcc
19850 to denote the end of the prologue. So we can't just discard duplicate
19851 entries, we have to be selective about it. The heuristic we use is
19852 that we only collapse consecutive entries for the same line if at least
19853 one of those entries has a non-zero discriminator. PR 17276.
19855 Note: Addresses in the line number state machine can never go backwards
19856 within one sequence, thus this coalescing is ok. */
19859 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19860 unsigned int line
, unsigned int last_line
,
19861 int line_has_non_zero_discriminator
,
19862 struct subfile
*last_subfile
)
19864 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19866 if (line
!= last_line
)
19868 /* Same line for the same file that we've seen already.
19869 As a last check, for pr 17276, only record the line if the line
19870 has never had a non-zero discriminator. */
19871 if (!line_has_non_zero_discriminator
)
19876 /* Use the CU's builder to record line number LINE beginning at
19877 address ADDRESS in the line table of subfile SUBFILE. */
19880 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19881 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19882 struct dwarf2_cu
*cu
)
19884 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19886 if (dwarf_line_debug
)
19888 fprintf_unfiltered (gdb_stdlog
,
19889 "Recording line %u, file %s, address %s\n",
19890 line
, lbasename (subfile
->name
),
19891 paddress (gdbarch
, address
));
19895 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19898 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19899 Mark the end of a set of line number records.
19900 The arguments are the same as for dwarf_record_line_1.
19901 If SUBFILE is NULL the request is ignored. */
19904 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19905 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19907 if (subfile
== NULL
)
19910 if (dwarf_line_debug
)
19912 fprintf_unfiltered (gdb_stdlog
,
19913 "Finishing current line, file %s, address %s\n",
19914 lbasename (subfile
->name
),
19915 paddress (gdbarch
, address
));
19918 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19922 lnp_state_machine::record_line (bool end_sequence
)
19924 if (dwarf_line_debug
)
19926 fprintf_unfiltered (gdb_stdlog
,
19927 "Processing actual line %u: file %u,"
19928 " address %s, is_stmt %u, discrim %u%s\n",
19930 paddress (m_gdbarch
, m_address
),
19931 m_is_stmt
, m_discriminator
,
19932 (end_sequence
? "\t(end sequence)" : ""));
19935 file_entry
*fe
= current_file ();
19938 dwarf2_debug_line_missing_file_complaint ();
19939 /* For now we ignore lines not starting on an instruction boundary.
19940 But not when processing end_sequence for compatibility with the
19941 previous version of the code. */
19942 else if (m_op_index
== 0 || end_sequence
)
19944 fe
->included_p
= 1;
19945 if (m_record_lines_p
)
19947 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19950 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19951 m_currently_recording_lines
? m_cu
: nullptr);
19956 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19958 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19959 m_line_has_non_zero_discriminator
,
19962 buildsym_compunit
*builder
= m_cu
->get_builder ();
19963 dwarf_record_line_1 (m_gdbarch
,
19964 builder
->get_current_subfile (),
19965 m_line
, m_address
, is_stmt
,
19966 m_currently_recording_lines
? m_cu
: nullptr);
19968 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19969 m_last_line
= m_line
;
19975 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19976 line_header
*lh
, bool record_lines_p
)
19980 m_record_lines_p
= record_lines_p
;
19981 m_line_header
= lh
;
19983 m_currently_recording_lines
= true;
19985 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19986 was a line entry for it so that the backend has a chance to adjust it
19987 and also record it in case it needs it. This is currently used by MIPS
19988 code, cf. `mips_adjust_dwarf2_line'. */
19989 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19990 m_is_stmt
= lh
->default_is_stmt
;
19991 m_discriminator
= 0;
19995 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19996 const gdb_byte
*line_ptr
,
19997 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19999 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20000 the pc range of the CU. However, we restrict the test to only ADDRESS
20001 values of zero to preserve GDB's previous behaviour which is to handle
20002 the specific case of a function being GC'd by the linker. */
20004 if (address
== 0 && address
< unrelocated_lowpc
)
20006 /* This line table is for a function which has been
20007 GCd by the linker. Ignore it. PR gdb/12528 */
20009 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20010 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20012 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20013 line_offset
, objfile_name (objfile
));
20014 m_currently_recording_lines
= false;
20015 /* Note: m_currently_recording_lines is left as false until we see
20016 DW_LNE_end_sequence. */
20020 /* Subroutine of dwarf_decode_lines to simplify it.
20021 Process the line number information in LH.
20022 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20023 program in order to set included_p for every referenced header. */
20026 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20027 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20029 const gdb_byte
*line_ptr
, *extended_end
;
20030 const gdb_byte
*line_end
;
20031 unsigned int bytes_read
, extended_len
;
20032 unsigned char op_code
, extended_op
;
20033 CORE_ADDR baseaddr
;
20034 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20035 bfd
*abfd
= objfile
->obfd
;
20036 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20037 /* True if we're recording line info (as opposed to building partial
20038 symtabs and just interested in finding include files mentioned by
20039 the line number program). */
20040 bool record_lines_p
= !decode_for_pst_p
;
20042 baseaddr
= objfile
->text_section_offset ();
20044 line_ptr
= lh
->statement_program_start
;
20045 line_end
= lh
->statement_program_end
;
20047 /* Read the statement sequences until there's nothing left. */
20048 while (line_ptr
< line_end
)
20050 /* The DWARF line number program state machine. Reset the state
20051 machine at the start of each sequence. */
20052 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20053 bool end_sequence
= false;
20055 if (record_lines_p
)
20057 /* Start a subfile for the current file of the state
20059 const file_entry
*fe
= state_machine
.current_file ();
20062 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20065 /* Decode the table. */
20066 while (line_ptr
< line_end
&& !end_sequence
)
20068 op_code
= read_1_byte (abfd
, line_ptr
);
20071 if (op_code
>= lh
->opcode_base
)
20073 /* Special opcode. */
20074 state_machine
.handle_special_opcode (op_code
);
20076 else switch (op_code
)
20078 case DW_LNS_extended_op
:
20079 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20081 line_ptr
+= bytes_read
;
20082 extended_end
= line_ptr
+ extended_len
;
20083 extended_op
= read_1_byte (abfd
, line_ptr
);
20085 switch (extended_op
)
20087 case DW_LNE_end_sequence
:
20088 state_machine
.handle_end_sequence ();
20089 end_sequence
= true;
20091 case DW_LNE_set_address
:
20094 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20095 line_ptr
+= bytes_read
;
20097 state_machine
.check_line_address (cu
, line_ptr
,
20098 lowpc
- baseaddr
, address
);
20099 state_machine
.handle_set_address (baseaddr
, address
);
20102 case DW_LNE_define_file
:
20104 const char *cur_file
;
20105 unsigned int mod_time
, length
;
20108 cur_file
= read_direct_string (abfd
, line_ptr
,
20110 line_ptr
+= bytes_read
;
20111 dindex
= (dir_index
)
20112 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20113 line_ptr
+= bytes_read
;
20115 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20116 line_ptr
+= bytes_read
;
20118 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20119 line_ptr
+= bytes_read
;
20120 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20123 case DW_LNE_set_discriminator
:
20125 /* The discriminator is not interesting to the
20126 debugger; just ignore it. We still need to
20127 check its value though:
20128 if there are consecutive entries for the same
20129 (non-prologue) line we want to coalesce them.
20132 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20133 line_ptr
+= bytes_read
;
20135 state_machine
.handle_set_discriminator (discr
);
20139 complaint (_("mangled .debug_line section"));
20142 /* Make sure that we parsed the extended op correctly. If e.g.
20143 we expected a different address size than the producer used,
20144 we may have read the wrong number of bytes. */
20145 if (line_ptr
!= extended_end
)
20147 complaint (_("mangled .debug_line section"));
20152 state_machine
.handle_copy ();
20154 case DW_LNS_advance_pc
:
20157 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20158 line_ptr
+= bytes_read
;
20160 state_machine
.handle_advance_pc (adjust
);
20163 case DW_LNS_advance_line
:
20166 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20167 line_ptr
+= bytes_read
;
20169 state_machine
.handle_advance_line (line_delta
);
20172 case DW_LNS_set_file
:
20174 file_name_index file
20175 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20177 line_ptr
+= bytes_read
;
20179 state_machine
.handle_set_file (file
);
20182 case DW_LNS_set_column
:
20183 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20184 line_ptr
+= bytes_read
;
20186 case DW_LNS_negate_stmt
:
20187 state_machine
.handle_negate_stmt ();
20189 case DW_LNS_set_basic_block
:
20191 /* Add to the address register of the state machine the
20192 address increment value corresponding to special opcode
20193 255. I.e., this value is scaled by the minimum
20194 instruction length since special opcode 255 would have
20195 scaled the increment. */
20196 case DW_LNS_const_add_pc
:
20197 state_machine
.handle_const_add_pc ();
20199 case DW_LNS_fixed_advance_pc
:
20201 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20204 state_machine
.handle_fixed_advance_pc (addr_adj
);
20209 /* Unknown standard opcode, ignore it. */
20212 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20214 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20215 line_ptr
+= bytes_read
;
20222 dwarf2_debug_line_missing_end_sequence_complaint ();
20224 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20225 in which case we still finish recording the last line). */
20226 state_machine
.record_line (true);
20230 /* Decode the Line Number Program (LNP) for the given line_header
20231 structure and CU. The actual information extracted and the type
20232 of structures created from the LNP depends on the value of PST.
20234 1. If PST is NULL, then this procedure uses the data from the program
20235 to create all necessary symbol tables, and their linetables.
20237 2. If PST is not NULL, this procedure reads the program to determine
20238 the list of files included by the unit represented by PST, and
20239 builds all the associated partial symbol tables.
20241 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20242 It is used for relative paths in the line table.
20243 NOTE: When processing partial symtabs (pst != NULL),
20244 comp_dir == pst->dirname.
20246 NOTE: It is important that psymtabs have the same file name (via strcmp)
20247 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20248 symtab we don't use it in the name of the psymtabs we create.
20249 E.g. expand_line_sal requires this when finding psymtabs to expand.
20250 A good testcase for this is mb-inline.exp.
20252 LOWPC is the lowest address in CU (or 0 if not known).
20254 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20255 for its PC<->lines mapping information. Otherwise only the filename
20256 table is read in. */
20259 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20260 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20261 CORE_ADDR lowpc
, int decode_mapping
)
20263 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20264 const int decode_for_pst_p
= (pst
!= NULL
);
20266 if (decode_mapping
)
20267 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20269 if (decode_for_pst_p
)
20271 /* Now that we're done scanning the Line Header Program, we can
20272 create the psymtab of each included file. */
20273 for (auto &file_entry
: lh
->file_names ())
20274 if (file_entry
.included_p
== 1)
20276 gdb::unique_xmalloc_ptr
<char> name_holder
;
20277 const char *include_name
=
20278 psymtab_include_file_name (lh
, file_entry
, pst
,
20279 comp_dir
, &name_holder
);
20280 if (include_name
!= NULL
)
20281 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20286 /* Make sure a symtab is created for every file, even files
20287 which contain only variables (i.e. no code with associated
20289 buildsym_compunit
*builder
= cu
->get_builder ();
20290 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20292 for (auto &fe
: lh
->file_names ())
20294 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20295 if (builder
->get_current_subfile ()->symtab
== NULL
)
20297 builder
->get_current_subfile ()->symtab
20298 = allocate_symtab (cust
,
20299 builder
->get_current_subfile ()->name
);
20301 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20306 /* Start a subfile for DWARF. FILENAME is the name of the file and
20307 DIRNAME the name of the source directory which contains FILENAME
20308 or NULL if not known.
20309 This routine tries to keep line numbers from identical absolute and
20310 relative file names in a common subfile.
20312 Using the `list' example from the GDB testsuite, which resides in
20313 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20314 of /srcdir/list0.c yields the following debugging information for list0.c:
20316 DW_AT_name: /srcdir/list0.c
20317 DW_AT_comp_dir: /compdir
20318 files.files[0].name: list0.h
20319 files.files[0].dir: /srcdir
20320 files.files[1].name: list0.c
20321 files.files[1].dir: /srcdir
20323 The line number information for list0.c has to end up in a single
20324 subfile, so that `break /srcdir/list0.c:1' works as expected.
20325 start_subfile will ensure that this happens provided that we pass the
20326 concatenation of files.files[1].dir and files.files[1].name as the
20330 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20331 const char *dirname
)
20333 gdb::unique_xmalloc_ptr
<char> copy
;
20335 /* In order not to lose the line information directory,
20336 we concatenate it to the filename when it makes sense.
20337 Note that the Dwarf3 standard says (speaking of filenames in line
20338 information): ``The directory index is ignored for file names
20339 that represent full path names''. Thus ignoring dirname in the
20340 `else' branch below isn't an issue. */
20342 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20344 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20345 filename
= copy
.get ();
20348 cu
->get_builder ()->start_subfile (filename
);
20351 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20352 buildsym_compunit constructor. */
20354 struct compunit_symtab
*
20355 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20358 gdb_assert (m_builder
== nullptr);
20360 m_builder
.reset (new struct buildsym_compunit
20361 (per_cu
->dwarf2_per_objfile
->objfile
,
20362 name
, comp_dir
, language
, low_pc
));
20364 list_in_scope
= get_builder ()->get_file_symbols ();
20366 get_builder ()->record_debugformat ("DWARF 2");
20367 get_builder ()->record_producer (producer
);
20369 processing_has_namespace_info
= false;
20371 return get_builder ()->get_compunit_symtab ();
20375 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20376 struct dwarf2_cu
*cu
)
20378 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20379 struct comp_unit_head
*cu_header
= &cu
->header
;
20381 /* NOTE drow/2003-01-30: There used to be a comment and some special
20382 code here to turn a symbol with DW_AT_external and a
20383 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20384 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20385 with some versions of binutils) where shared libraries could have
20386 relocations against symbols in their debug information - the
20387 minimal symbol would have the right address, but the debug info
20388 would not. It's no longer necessary, because we will explicitly
20389 apply relocations when we read in the debug information now. */
20391 /* A DW_AT_location attribute with no contents indicates that a
20392 variable has been optimized away. */
20393 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20395 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20399 /* Handle one degenerate form of location expression specially, to
20400 preserve GDB's previous behavior when section offsets are
20401 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20402 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20404 if (attr
->form_is_block ()
20405 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20406 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20407 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20408 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20409 && (DW_BLOCK (attr
)->size
20410 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20412 unsigned int dummy
;
20414 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20415 SET_SYMBOL_VALUE_ADDRESS
20416 (sym
, cu
->header
.read_address (objfile
->obfd
,
20417 DW_BLOCK (attr
)->data
+ 1,
20420 SET_SYMBOL_VALUE_ADDRESS
20421 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20423 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20424 fixup_symbol_section (sym
, objfile
);
20425 SET_SYMBOL_VALUE_ADDRESS
20427 SYMBOL_VALUE_ADDRESS (sym
)
20428 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20432 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20433 expression evaluator, and use LOC_COMPUTED only when necessary
20434 (i.e. when the value of a register or memory location is
20435 referenced, or a thread-local block, etc.). Then again, it might
20436 not be worthwhile. I'm assuming that it isn't unless performance
20437 or memory numbers show me otherwise. */
20439 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20441 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20442 cu
->has_loclist
= true;
20445 /* Given a pointer to a DWARF information entry, figure out if we need
20446 to make a symbol table entry for it, and if so, create a new entry
20447 and return a pointer to it.
20448 If TYPE is NULL, determine symbol type from the die, otherwise
20449 used the passed type.
20450 If SPACE is not NULL, use it to hold the new symbol. If it is
20451 NULL, allocate a new symbol on the objfile's obstack. */
20453 static struct symbol
*
20454 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20455 struct symbol
*space
)
20457 struct dwarf2_per_objfile
*dwarf2_per_objfile
20458 = cu
->per_cu
->dwarf2_per_objfile
;
20459 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20460 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20461 struct symbol
*sym
= NULL
;
20463 struct attribute
*attr
= NULL
;
20464 struct attribute
*attr2
= NULL
;
20465 CORE_ADDR baseaddr
;
20466 struct pending
**list_to_add
= NULL
;
20468 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20470 baseaddr
= objfile
->text_section_offset ();
20472 name
= dwarf2_name (die
, cu
);
20475 const char *linkagename
;
20476 int suppress_add
= 0;
20481 sym
= allocate_symbol (objfile
);
20482 OBJSTAT (objfile
, n_syms
++);
20484 /* Cache this symbol's name and the name's demangled form (if any). */
20485 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20486 linkagename
= dwarf2_physname (name
, die
, cu
);
20487 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20489 /* Fortran does not have mangling standard and the mangling does differ
20490 between gfortran, iFort etc. */
20491 if (cu
->language
== language_fortran
20492 && symbol_get_demangled_name (sym
) == NULL
)
20493 symbol_set_demangled_name (sym
,
20494 dwarf2_full_name (name
, die
, cu
),
20497 /* Default assumptions.
20498 Use the passed type or decode it from the die. */
20499 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20500 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20502 SYMBOL_TYPE (sym
) = type
;
20504 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20505 attr
= dwarf2_attr (die
,
20506 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20508 if (attr
!= nullptr)
20510 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20513 attr
= dwarf2_attr (die
,
20514 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20516 if (attr
!= nullptr)
20518 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20519 struct file_entry
*fe
;
20521 if (cu
->line_header
!= NULL
)
20522 fe
= cu
->line_header
->file_name_at (file_index
);
20527 complaint (_("file index out of range"));
20529 symbol_set_symtab (sym
, fe
->symtab
);
20535 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20536 if (attr
!= nullptr)
20540 addr
= attr
->value_as_address ();
20541 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20542 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20544 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20545 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20546 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20547 add_symbol_to_list (sym
, cu
->list_in_scope
);
20549 case DW_TAG_subprogram
:
20550 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20552 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20553 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20554 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20555 || cu
->language
== language_ada
20556 || cu
->language
== language_fortran
)
20558 /* Subprograms marked external are stored as a global symbol.
20559 Ada and Fortran subprograms, whether marked external or
20560 not, are always stored as a global symbol, because we want
20561 to be able to access them globally. For instance, we want
20562 to be able to break on a nested subprogram without having
20563 to specify the context. */
20564 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20568 list_to_add
= cu
->list_in_scope
;
20571 case DW_TAG_inlined_subroutine
:
20572 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20574 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20575 SYMBOL_INLINED (sym
) = 1;
20576 list_to_add
= cu
->list_in_scope
;
20578 case DW_TAG_template_value_param
:
20580 /* Fall through. */
20581 case DW_TAG_constant
:
20582 case DW_TAG_variable
:
20583 case DW_TAG_member
:
20584 /* Compilation with minimal debug info may result in
20585 variables with missing type entries. Change the
20586 misleading `void' type to something sensible. */
20587 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20588 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20590 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20591 /* In the case of DW_TAG_member, we should only be called for
20592 static const members. */
20593 if (die
->tag
== DW_TAG_member
)
20595 /* dwarf2_add_field uses die_is_declaration,
20596 so we do the same. */
20597 gdb_assert (die_is_declaration (die
, cu
));
20600 if (attr
!= nullptr)
20602 dwarf2_const_value (attr
, sym
, cu
);
20603 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20606 if (attr2
&& (DW_UNSND (attr2
) != 0))
20607 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20609 list_to_add
= cu
->list_in_scope
;
20613 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20614 if (attr
!= nullptr)
20616 var_decode_location (attr
, sym
, cu
);
20617 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20619 /* Fortran explicitly imports any global symbols to the local
20620 scope by DW_TAG_common_block. */
20621 if (cu
->language
== language_fortran
&& die
->parent
20622 && die
->parent
->tag
== DW_TAG_common_block
)
20625 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20626 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20627 && !dwarf2_per_objfile
->has_section_at_zero
)
20629 /* When a static variable is eliminated by the linker,
20630 the corresponding debug information is not stripped
20631 out, but the variable address is set to null;
20632 do not add such variables into symbol table. */
20634 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20636 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20637 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20638 && dwarf2_per_objfile
->can_copy
)
20640 /* A global static variable might be subject to
20641 copy relocation. We first check for a local
20642 minsym, though, because maybe the symbol was
20643 marked hidden, in which case this would not
20645 bound_minimal_symbol found
20646 = (lookup_minimal_symbol_linkage
20647 (sym
->linkage_name (), objfile
));
20648 if (found
.minsym
!= nullptr)
20649 sym
->maybe_copied
= 1;
20652 /* A variable with DW_AT_external is never static,
20653 but it may be block-scoped. */
20655 = ((cu
->list_in_scope
20656 == cu
->get_builder ()->get_file_symbols ())
20657 ? cu
->get_builder ()->get_global_symbols ()
20658 : cu
->list_in_scope
);
20661 list_to_add
= cu
->list_in_scope
;
20665 /* We do not know the address of this symbol.
20666 If it is an external symbol and we have type information
20667 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20668 The address of the variable will then be determined from
20669 the minimal symbol table whenever the variable is
20671 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20673 /* Fortran explicitly imports any global symbols to the local
20674 scope by DW_TAG_common_block. */
20675 if (cu
->language
== language_fortran
&& die
->parent
20676 && die
->parent
->tag
== DW_TAG_common_block
)
20678 /* SYMBOL_CLASS doesn't matter here because
20679 read_common_block is going to reset it. */
20681 list_to_add
= cu
->list_in_scope
;
20683 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20684 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20686 /* A variable with DW_AT_external is never static, but it
20687 may be block-scoped. */
20689 = ((cu
->list_in_scope
20690 == cu
->get_builder ()->get_file_symbols ())
20691 ? cu
->get_builder ()->get_global_symbols ()
20692 : cu
->list_in_scope
);
20694 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20696 else if (!die_is_declaration (die
, cu
))
20698 /* Use the default LOC_OPTIMIZED_OUT class. */
20699 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20701 list_to_add
= cu
->list_in_scope
;
20705 case DW_TAG_formal_parameter
:
20707 /* If we are inside a function, mark this as an argument. If
20708 not, we might be looking at an argument to an inlined function
20709 when we do not have enough information to show inlined frames;
20710 pretend it's a local variable in that case so that the user can
20712 struct context_stack
*curr
20713 = cu
->get_builder ()->get_current_context_stack ();
20714 if (curr
!= nullptr && curr
->name
!= nullptr)
20715 SYMBOL_IS_ARGUMENT (sym
) = 1;
20716 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20717 if (attr
!= nullptr)
20719 var_decode_location (attr
, sym
, cu
);
20721 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20722 if (attr
!= nullptr)
20724 dwarf2_const_value (attr
, sym
, cu
);
20727 list_to_add
= cu
->list_in_scope
;
20730 case DW_TAG_unspecified_parameters
:
20731 /* From varargs functions; gdb doesn't seem to have any
20732 interest in this information, so just ignore it for now.
20735 case DW_TAG_template_type_param
:
20737 /* Fall through. */
20738 case DW_TAG_class_type
:
20739 case DW_TAG_interface_type
:
20740 case DW_TAG_structure_type
:
20741 case DW_TAG_union_type
:
20742 case DW_TAG_set_type
:
20743 case DW_TAG_enumeration_type
:
20744 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20745 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20748 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20749 really ever be static objects: otherwise, if you try
20750 to, say, break of a class's method and you're in a file
20751 which doesn't mention that class, it won't work unless
20752 the check for all static symbols in lookup_symbol_aux
20753 saves you. See the OtherFileClass tests in
20754 gdb.c++/namespace.exp. */
20758 buildsym_compunit
*builder
= cu
->get_builder ();
20760 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20761 && cu
->language
== language_cplus
20762 ? builder
->get_global_symbols ()
20763 : cu
->list_in_scope
);
20765 /* The semantics of C++ state that "struct foo {
20766 ... }" also defines a typedef for "foo". */
20767 if (cu
->language
== language_cplus
20768 || cu
->language
== language_ada
20769 || cu
->language
== language_d
20770 || cu
->language
== language_rust
)
20772 /* The symbol's name is already allocated along
20773 with this objfile, so we don't need to
20774 duplicate it for the type. */
20775 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20776 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20781 case DW_TAG_typedef
:
20782 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20783 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20784 list_to_add
= cu
->list_in_scope
;
20786 case DW_TAG_base_type
:
20787 case DW_TAG_subrange_type
:
20788 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20789 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20790 list_to_add
= cu
->list_in_scope
;
20792 case DW_TAG_enumerator
:
20793 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20794 if (attr
!= nullptr)
20796 dwarf2_const_value (attr
, sym
, cu
);
20799 /* NOTE: carlton/2003-11-10: See comment above in the
20800 DW_TAG_class_type, etc. block. */
20803 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20804 && cu
->language
== language_cplus
20805 ? cu
->get_builder ()->get_global_symbols ()
20806 : cu
->list_in_scope
);
20809 case DW_TAG_imported_declaration
:
20810 case DW_TAG_namespace
:
20811 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20812 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20814 case DW_TAG_module
:
20815 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20816 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20817 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20819 case DW_TAG_common_block
:
20820 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20821 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20822 add_symbol_to_list (sym
, cu
->list_in_scope
);
20825 /* Not a tag we recognize. Hopefully we aren't processing
20826 trash data, but since we must specifically ignore things
20827 we don't recognize, there is nothing else we should do at
20829 complaint (_("unsupported tag: '%s'"),
20830 dwarf_tag_name (die
->tag
));
20836 sym
->hash_next
= objfile
->template_symbols
;
20837 objfile
->template_symbols
= sym
;
20838 list_to_add
= NULL
;
20841 if (list_to_add
!= NULL
)
20842 add_symbol_to_list (sym
, list_to_add
);
20844 /* For the benefit of old versions of GCC, check for anonymous
20845 namespaces based on the demangled name. */
20846 if (!cu
->processing_has_namespace_info
20847 && cu
->language
== language_cplus
)
20848 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20853 /* Given an attr with a DW_FORM_dataN value in host byte order,
20854 zero-extend it as appropriate for the symbol's type. The DWARF
20855 standard (v4) is not entirely clear about the meaning of using
20856 DW_FORM_dataN for a constant with a signed type, where the type is
20857 wider than the data. The conclusion of a discussion on the DWARF
20858 list was that this is unspecified. We choose to always zero-extend
20859 because that is the interpretation long in use by GCC. */
20862 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20863 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20865 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20866 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20867 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20868 LONGEST l
= DW_UNSND (attr
);
20870 if (bits
< sizeof (*value
) * 8)
20872 l
&= ((LONGEST
) 1 << bits
) - 1;
20875 else if (bits
== sizeof (*value
) * 8)
20879 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20880 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20887 /* Read a constant value from an attribute. Either set *VALUE, or if
20888 the value does not fit in *VALUE, set *BYTES - either already
20889 allocated on the objfile obstack, or newly allocated on OBSTACK,
20890 or, set *BATON, if we translated the constant to a location
20894 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20895 const char *name
, struct obstack
*obstack
,
20896 struct dwarf2_cu
*cu
,
20897 LONGEST
*value
, const gdb_byte
**bytes
,
20898 struct dwarf2_locexpr_baton
**baton
)
20900 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20901 struct comp_unit_head
*cu_header
= &cu
->header
;
20902 struct dwarf_block
*blk
;
20903 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20904 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20910 switch (attr
->form
)
20913 case DW_FORM_addrx
:
20914 case DW_FORM_GNU_addr_index
:
20918 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20919 dwarf2_const_value_length_mismatch_complaint (name
,
20920 cu_header
->addr_size
,
20921 TYPE_LENGTH (type
));
20922 /* Symbols of this form are reasonably rare, so we just
20923 piggyback on the existing location code rather than writing
20924 a new implementation of symbol_computed_ops. */
20925 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20926 (*baton
)->per_cu
= cu
->per_cu
;
20927 gdb_assert ((*baton
)->per_cu
);
20929 (*baton
)->size
= 2 + cu_header
->addr_size
;
20930 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20931 (*baton
)->data
= data
;
20933 data
[0] = DW_OP_addr
;
20934 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20935 byte_order
, DW_ADDR (attr
));
20936 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20939 case DW_FORM_string
:
20942 case DW_FORM_GNU_str_index
:
20943 case DW_FORM_GNU_strp_alt
:
20944 /* DW_STRING is already allocated on the objfile obstack, point
20946 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20948 case DW_FORM_block1
:
20949 case DW_FORM_block2
:
20950 case DW_FORM_block4
:
20951 case DW_FORM_block
:
20952 case DW_FORM_exprloc
:
20953 case DW_FORM_data16
:
20954 blk
= DW_BLOCK (attr
);
20955 if (TYPE_LENGTH (type
) != blk
->size
)
20956 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20957 TYPE_LENGTH (type
));
20958 *bytes
= blk
->data
;
20961 /* The DW_AT_const_value attributes are supposed to carry the
20962 symbol's value "represented as it would be on the target
20963 architecture." By the time we get here, it's already been
20964 converted to host endianness, so we just need to sign- or
20965 zero-extend it as appropriate. */
20966 case DW_FORM_data1
:
20967 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20969 case DW_FORM_data2
:
20970 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20972 case DW_FORM_data4
:
20973 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20975 case DW_FORM_data8
:
20976 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20979 case DW_FORM_sdata
:
20980 case DW_FORM_implicit_const
:
20981 *value
= DW_SND (attr
);
20984 case DW_FORM_udata
:
20985 *value
= DW_UNSND (attr
);
20989 complaint (_("unsupported const value attribute form: '%s'"),
20990 dwarf_form_name (attr
->form
));
20997 /* Copy constant value from an attribute to a symbol. */
21000 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21001 struct dwarf2_cu
*cu
)
21003 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21005 const gdb_byte
*bytes
;
21006 struct dwarf2_locexpr_baton
*baton
;
21008 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21009 sym
->print_name (),
21010 &objfile
->objfile_obstack
, cu
,
21011 &value
, &bytes
, &baton
);
21015 SYMBOL_LOCATION_BATON (sym
) = baton
;
21016 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21018 else if (bytes
!= NULL
)
21020 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21021 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21025 SYMBOL_VALUE (sym
) = value
;
21026 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21030 /* Return the type of the die in question using its DW_AT_type attribute. */
21032 static struct type
*
21033 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21035 struct attribute
*type_attr
;
21037 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21040 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21041 /* A missing DW_AT_type represents a void type. */
21042 return objfile_type (objfile
)->builtin_void
;
21045 return lookup_die_type (die
, type_attr
, cu
);
21048 /* True iff CU's producer generates GNAT Ada auxiliary information
21049 that allows to find parallel types through that information instead
21050 of having to do expensive parallel lookups by type name. */
21053 need_gnat_info (struct dwarf2_cu
*cu
)
21055 /* Assume that the Ada compiler was GNAT, which always produces
21056 the auxiliary information. */
21057 return (cu
->language
== language_ada
);
21060 /* Return the auxiliary type of the die in question using its
21061 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21062 attribute is not present. */
21064 static struct type
*
21065 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21067 struct attribute
*type_attr
;
21069 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21073 return lookup_die_type (die
, type_attr
, cu
);
21076 /* If DIE has a descriptive_type attribute, then set the TYPE's
21077 descriptive type accordingly. */
21080 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21081 struct dwarf2_cu
*cu
)
21083 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21085 if (descriptive_type
)
21087 ALLOCATE_GNAT_AUX_TYPE (type
);
21088 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21092 /* Return the containing type of the die in question using its
21093 DW_AT_containing_type attribute. */
21095 static struct type
*
21096 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21098 struct attribute
*type_attr
;
21099 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21101 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21103 error (_("Dwarf Error: Problem turning containing type into gdb type "
21104 "[in module %s]"), objfile_name (objfile
));
21106 return lookup_die_type (die
, type_attr
, cu
);
21109 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21111 static struct type
*
21112 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21114 struct dwarf2_per_objfile
*dwarf2_per_objfile
21115 = cu
->per_cu
->dwarf2_per_objfile
;
21116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21119 std::string message
21120 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21121 objfile_name (objfile
),
21122 sect_offset_str (cu
->header
.sect_off
),
21123 sect_offset_str (die
->sect_off
));
21124 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21126 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21129 /* Look up the type of DIE in CU using its type attribute ATTR.
21130 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21131 DW_AT_containing_type.
21132 If there is no type substitute an error marker. */
21134 static struct type
*
21135 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21136 struct dwarf2_cu
*cu
)
21138 struct dwarf2_per_objfile
*dwarf2_per_objfile
21139 = cu
->per_cu
->dwarf2_per_objfile
;
21140 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21141 struct type
*this_type
;
21143 gdb_assert (attr
->name
== DW_AT_type
21144 || attr
->name
== DW_AT_GNAT_descriptive_type
21145 || attr
->name
== DW_AT_containing_type
);
21147 /* First see if we have it cached. */
21149 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21151 struct dwarf2_per_cu_data
*per_cu
;
21152 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21154 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21155 dwarf2_per_objfile
);
21156 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21158 else if (attr
->form_is_ref ())
21160 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21162 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21164 else if (attr
->form
== DW_FORM_ref_sig8
)
21166 ULONGEST signature
= DW_SIGNATURE (attr
);
21168 return get_signatured_type (die
, signature
, cu
);
21172 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21173 " at %s [in module %s]"),
21174 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21175 objfile_name (objfile
));
21176 return build_error_marker_type (cu
, die
);
21179 /* If not cached we need to read it in. */
21181 if (this_type
== NULL
)
21183 struct die_info
*type_die
= NULL
;
21184 struct dwarf2_cu
*type_cu
= cu
;
21186 if (attr
->form_is_ref ())
21187 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21188 if (type_die
== NULL
)
21189 return build_error_marker_type (cu
, die
);
21190 /* If we find the type now, it's probably because the type came
21191 from an inter-CU reference and the type's CU got expanded before
21193 this_type
= read_type_die (type_die
, type_cu
);
21196 /* If we still don't have a type use an error marker. */
21198 if (this_type
== NULL
)
21199 return build_error_marker_type (cu
, die
);
21204 /* Return the type in DIE, CU.
21205 Returns NULL for invalid types.
21207 This first does a lookup in die_type_hash,
21208 and only reads the die in if necessary.
21210 NOTE: This can be called when reading in partial or full symbols. */
21212 static struct type
*
21213 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21215 struct type
*this_type
;
21217 this_type
= get_die_type (die
, cu
);
21221 return read_type_die_1 (die
, cu
);
21224 /* Read the type in DIE, CU.
21225 Returns NULL for invalid types. */
21227 static struct type
*
21228 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21230 struct type
*this_type
= NULL
;
21234 case DW_TAG_class_type
:
21235 case DW_TAG_interface_type
:
21236 case DW_TAG_structure_type
:
21237 case DW_TAG_union_type
:
21238 this_type
= read_structure_type (die
, cu
);
21240 case DW_TAG_enumeration_type
:
21241 this_type
= read_enumeration_type (die
, cu
);
21243 case DW_TAG_subprogram
:
21244 case DW_TAG_subroutine_type
:
21245 case DW_TAG_inlined_subroutine
:
21246 this_type
= read_subroutine_type (die
, cu
);
21248 case DW_TAG_array_type
:
21249 this_type
= read_array_type (die
, cu
);
21251 case DW_TAG_set_type
:
21252 this_type
= read_set_type (die
, cu
);
21254 case DW_TAG_pointer_type
:
21255 this_type
= read_tag_pointer_type (die
, cu
);
21257 case DW_TAG_ptr_to_member_type
:
21258 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21260 case DW_TAG_reference_type
:
21261 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21263 case DW_TAG_rvalue_reference_type
:
21264 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21266 case DW_TAG_const_type
:
21267 this_type
= read_tag_const_type (die
, cu
);
21269 case DW_TAG_volatile_type
:
21270 this_type
= read_tag_volatile_type (die
, cu
);
21272 case DW_TAG_restrict_type
:
21273 this_type
= read_tag_restrict_type (die
, cu
);
21275 case DW_TAG_string_type
:
21276 this_type
= read_tag_string_type (die
, cu
);
21278 case DW_TAG_typedef
:
21279 this_type
= read_typedef (die
, cu
);
21281 case DW_TAG_subrange_type
:
21282 this_type
= read_subrange_type (die
, cu
);
21284 case DW_TAG_base_type
:
21285 this_type
= read_base_type (die
, cu
);
21287 case DW_TAG_unspecified_type
:
21288 this_type
= read_unspecified_type (die
, cu
);
21290 case DW_TAG_namespace
:
21291 this_type
= read_namespace_type (die
, cu
);
21293 case DW_TAG_module
:
21294 this_type
= read_module_type (die
, cu
);
21296 case DW_TAG_atomic_type
:
21297 this_type
= read_tag_atomic_type (die
, cu
);
21300 complaint (_("unexpected tag in read_type_die: '%s'"),
21301 dwarf_tag_name (die
->tag
));
21308 /* See if we can figure out if the class lives in a namespace. We do
21309 this by looking for a member function; its demangled name will
21310 contain namespace info, if there is any.
21311 Return the computed name or NULL.
21312 Space for the result is allocated on the objfile's obstack.
21313 This is the full-die version of guess_partial_die_structure_name.
21314 In this case we know DIE has no useful parent. */
21316 static const char *
21317 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21319 struct die_info
*spec_die
;
21320 struct dwarf2_cu
*spec_cu
;
21321 struct die_info
*child
;
21322 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21325 spec_die
= die_specification (die
, &spec_cu
);
21326 if (spec_die
!= NULL
)
21332 for (child
= die
->child
;
21334 child
= child
->sibling
)
21336 if (child
->tag
== DW_TAG_subprogram
)
21338 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21340 if (linkage_name
!= NULL
)
21342 gdb::unique_xmalloc_ptr
<char> actual_name
21343 (language_class_name_from_physname (cu
->language_defn
,
21345 const char *name
= NULL
;
21347 if (actual_name
!= NULL
)
21349 const char *die_name
= dwarf2_name (die
, cu
);
21351 if (die_name
!= NULL
21352 && strcmp (die_name
, actual_name
.get ()) != 0)
21354 /* Strip off the class name from the full name.
21355 We want the prefix. */
21356 int die_name_len
= strlen (die_name
);
21357 int actual_name_len
= strlen (actual_name
.get ());
21358 const char *ptr
= actual_name
.get ();
21360 /* Test for '::' as a sanity check. */
21361 if (actual_name_len
> die_name_len
+ 2
21362 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21363 name
= obstack_strndup (
21364 &objfile
->per_bfd
->storage_obstack
,
21365 ptr
, actual_name_len
- die_name_len
- 2);
21376 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21377 prefix part in such case. See
21378 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21380 static const char *
21381 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21383 struct attribute
*attr
;
21386 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21387 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21390 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21393 attr
= dw2_linkage_name_attr (die
, cu
);
21394 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21397 /* dwarf2_name had to be already called. */
21398 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21400 /* Strip the base name, keep any leading namespaces/classes. */
21401 base
= strrchr (DW_STRING (attr
), ':');
21402 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21405 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21406 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21408 &base
[-1] - DW_STRING (attr
));
21411 /* Return the name of the namespace/class that DIE is defined within,
21412 or "" if we can't tell. The caller should not xfree the result.
21414 For example, if we're within the method foo() in the following
21424 then determine_prefix on foo's die will return "N::C". */
21426 static const char *
21427 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21429 struct dwarf2_per_objfile
*dwarf2_per_objfile
21430 = cu
->per_cu
->dwarf2_per_objfile
;
21431 struct die_info
*parent
, *spec_die
;
21432 struct dwarf2_cu
*spec_cu
;
21433 struct type
*parent_type
;
21434 const char *retval
;
21436 if (cu
->language
!= language_cplus
21437 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21438 && cu
->language
!= language_rust
)
21441 retval
= anonymous_struct_prefix (die
, cu
);
21445 /* We have to be careful in the presence of DW_AT_specification.
21446 For example, with GCC 3.4, given the code
21450 // Definition of N::foo.
21454 then we'll have a tree of DIEs like this:
21456 1: DW_TAG_compile_unit
21457 2: DW_TAG_namespace // N
21458 3: DW_TAG_subprogram // declaration of N::foo
21459 4: DW_TAG_subprogram // definition of N::foo
21460 DW_AT_specification // refers to die #3
21462 Thus, when processing die #4, we have to pretend that we're in
21463 the context of its DW_AT_specification, namely the contex of die
21466 spec_die
= die_specification (die
, &spec_cu
);
21467 if (spec_die
== NULL
)
21468 parent
= die
->parent
;
21471 parent
= spec_die
->parent
;
21475 if (parent
== NULL
)
21477 else if (parent
->building_fullname
)
21480 const char *parent_name
;
21482 /* It has been seen on RealView 2.2 built binaries,
21483 DW_TAG_template_type_param types actually _defined_ as
21484 children of the parent class:
21487 template class <class Enum> Class{};
21488 Class<enum E> class_e;
21490 1: DW_TAG_class_type (Class)
21491 2: DW_TAG_enumeration_type (E)
21492 3: DW_TAG_enumerator (enum1:0)
21493 3: DW_TAG_enumerator (enum2:1)
21495 2: DW_TAG_template_type_param
21496 DW_AT_type DW_FORM_ref_udata (E)
21498 Besides being broken debug info, it can put GDB into an
21499 infinite loop. Consider:
21501 When we're building the full name for Class<E>, we'll start
21502 at Class, and go look over its template type parameters,
21503 finding E. We'll then try to build the full name of E, and
21504 reach here. We're now trying to build the full name of E,
21505 and look over the parent DIE for containing scope. In the
21506 broken case, if we followed the parent DIE of E, we'd again
21507 find Class, and once again go look at its template type
21508 arguments, etc., etc. Simply don't consider such parent die
21509 as source-level parent of this die (it can't be, the language
21510 doesn't allow it), and break the loop here. */
21511 name
= dwarf2_name (die
, cu
);
21512 parent_name
= dwarf2_name (parent
, cu
);
21513 complaint (_("template param type '%s' defined within parent '%s'"),
21514 name
? name
: "<unknown>",
21515 parent_name
? parent_name
: "<unknown>");
21519 switch (parent
->tag
)
21521 case DW_TAG_namespace
:
21522 parent_type
= read_type_die (parent
, cu
);
21523 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21524 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21525 Work around this problem here. */
21526 if (cu
->language
== language_cplus
21527 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21529 /* We give a name to even anonymous namespaces. */
21530 return TYPE_NAME (parent_type
);
21531 case DW_TAG_class_type
:
21532 case DW_TAG_interface_type
:
21533 case DW_TAG_structure_type
:
21534 case DW_TAG_union_type
:
21535 case DW_TAG_module
:
21536 parent_type
= read_type_die (parent
, cu
);
21537 if (TYPE_NAME (parent_type
) != NULL
)
21538 return TYPE_NAME (parent_type
);
21540 /* An anonymous structure is only allowed non-static data
21541 members; no typedefs, no member functions, et cetera.
21542 So it does not need a prefix. */
21544 case DW_TAG_compile_unit
:
21545 case DW_TAG_partial_unit
:
21546 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21547 if (cu
->language
== language_cplus
21548 && !dwarf2_per_objfile
->types
.empty ()
21549 && die
->child
!= NULL
21550 && (die
->tag
== DW_TAG_class_type
21551 || die
->tag
== DW_TAG_structure_type
21552 || die
->tag
== DW_TAG_union_type
))
21554 const char *name
= guess_full_die_structure_name (die
, cu
);
21559 case DW_TAG_subprogram
:
21560 /* Nested subroutines in Fortran get a prefix with the name
21561 of the parent's subroutine. */
21562 if (cu
->language
== language_fortran
)
21564 if ((die
->tag
== DW_TAG_subprogram
)
21565 && (dwarf2_name (parent
, cu
) != NULL
))
21566 return dwarf2_name (parent
, cu
);
21568 return determine_prefix (parent
, cu
);
21569 case DW_TAG_enumeration_type
:
21570 parent_type
= read_type_die (parent
, cu
);
21571 if (TYPE_DECLARED_CLASS (parent_type
))
21573 if (TYPE_NAME (parent_type
) != NULL
)
21574 return TYPE_NAME (parent_type
);
21577 /* Fall through. */
21579 return determine_prefix (parent
, cu
);
21583 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21584 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21585 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21586 an obconcat, otherwise allocate storage for the result. The CU argument is
21587 used to determine the language and hence, the appropriate separator. */
21589 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21592 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21593 int physname
, struct dwarf2_cu
*cu
)
21595 const char *lead
= "";
21598 if (suffix
== NULL
|| suffix
[0] == '\0'
21599 || prefix
== NULL
|| prefix
[0] == '\0')
21601 else if (cu
->language
== language_d
)
21603 /* For D, the 'main' function could be defined in any module, but it
21604 should never be prefixed. */
21605 if (strcmp (suffix
, "D main") == 0)
21613 else if (cu
->language
== language_fortran
&& physname
)
21615 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21616 DW_AT_MIPS_linkage_name is preferred and used instead. */
21624 if (prefix
== NULL
)
21626 if (suffix
== NULL
)
21633 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21635 strcpy (retval
, lead
);
21636 strcat (retval
, prefix
);
21637 strcat (retval
, sep
);
21638 strcat (retval
, suffix
);
21643 /* We have an obstack. */
21644 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21648 /* Return sibling of die, NULL if no sibling. */
21650 static struct die_info
*
21651 sibling_die (struct die_info
*die
)
21653 return die
->sibling
;
21656 /* Get name of a die, return NULL if not found. */
21658 static const char *
21659 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21660 struct objfile
*objfile
)
21662 if (name
&& cu
->language
== language_cplus
)
21664 std::string canon_name
= cp_canonicalize_string (name
);
21666 if (!canon_name
.empty ())
21668 if (canon_name
!= name
)
21669 name
= objfile
->intern (canon_name
);
21676 /* Get name of a die, return NULL if not found.
21677 Anonymous namespaces are converted to their magic string. */
21679 static const char *
21680 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21682 struct attribute
*attr
;
21683 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21685 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21686 if ((!attr
|| !DW_STRING (attr
))
21687 && die
->tag
!= DW_TAG_namespace
21688 && die
->tag
!= DW_TAG_class_type
21689 && die
->tag
!= DW_TAG_interface_type
21690 && die
->tag
!= DW_TAG_structure_type
21691 && die
->tag
!= DW_TAG_union_type
)
21696 case DW_TAG_compile_unit
:
21697 case DW_TAG_partial_unit
:
21698 /* Compilation units have a DW_AT_name that is a filename, not
21699 a source language identifier. */
21700 case DW_TAG_enumeration_type
:
21701 case DW_TAG_enumerator
:
21702 /* These tags always have simple identifiers already; no need
21703 to canonicalize them. */
21704 return DW_STRING (attr
);
21706 case DW_TAG_namespace
:
21707 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21708 return DW_STRING (attr
);
21709 return CP_ANONYMOUS_NAMESPACE_STR
;
21711 case DW_TAG_class_type
:
21712 case DW_TAG_interface_type
:
21713 case DW_TAG_structure_type
:
21714 case DW_TAG_union_type
:
21715 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21716 structures or unions. These were of the form "._%d" in GCC 4.1,
21717 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21718 and GCC 4.4. We work around this problem by ignoring these. */
21719 if (attr
&& DW_STRING (attr
)
21720 && (startswith (DW_STRING (attr
), "._")
21721 || startswith (DW_STRING (attr
), "<anonymous")))
21724 /* GCC might emit a nameless typedef that has a linkage name. See
21725 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21726 if (!attr
|| DW_STRING (attr
) == NULL
)
21728 attr
= dw2_linkage_name_attr (die
, cu
);
21729 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21732 /* Avoid demangling DW_STRING (attr) the second time on a second
21733 call for the same DIE. */
21734 if (!DW_STRING_IS_CANONICAL (attr
))
21736 gdb::unique_xmalloc_ptr
<char> demangled
21737 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21738 if (demangled
== nullptr)
21741 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21742 DW_STRING_IS_CANONICAL (attr
) = 1;
21745 /* Strip any leading namespaces/classes, keep only the base name.
21746 DW_AT_name for named DIEs does not contain the prefixes. */
21747 const char *base
= strrchr (DW_STRING (attr
), ':');
21748 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21751 return DW_STRING (attr
);
21759 if (!DW_STRING_IS_CANONICAL (attr
))
21761 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21763 DW_STRING_IS_CANONICAL (attr
) = 1;
21765 return DW_STRING (attr
);
21768 /* Return the die that this die in an extension of, or NULL if there
21769 is none. *EXT_CU is the CU containing DIE on input, and the CU
21770 containing the return value on output. */
21772 static struct die_info
*
21773 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21775 struct attribute
*attr
;
21777 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21781 return follow_die_ref (die
, attr
, ext_cu
);
21784 /* A convenience function that returns an "unknown" DWARF name,
21785 including the value of V. STR is the name of the entity being
21786 printed, e.g., "TAG". */
21788 static const char *
21789 dwarf_unknown (const char *str
, unsigned v
)
21791 char *cell
= get_print_cell ();
21792 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21796 /* Convert a DIE tag into its string name. */
21798 static const char *
21799 dwarf_tag_name (unsigned tag
)
21801 const char *name
= get_DW_TAG_name (tag
);
21804 return dwarf_unknown ("TAG", tag
);
21809 /* Convert a DWARF attribute code into its string name. */
21811 static const char *
21812 dwarf_attr_name (unsigned attr
)
21816 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21817 if (attr
== DW_AT_MIPS_fde
)
21818 return "DW_AT_MIPS_fde";
21820 if (attr
== DW_AT_HP_block_index
)
21821 return "DW_AT_HP_block_index";
21824 name
= get_DW_AT_name (attr
);
21827 return dwarf_unknown ("AT", attr
);
21832 /* Convert a DWARF value form code into its string name. */
21834 static const char *
21835 dwarf_form_name (unsigned form
)
21837 const char *name
= get_DW_FORM_name (form
);
21840 return dwarf_unknown ("FORM", form
);
21845 static const char *
21846 dwarf_bool_name (unsigned mybool
)
21854 /* Convert a DWARF type code into its string name. */
21856 static const char *
21857 dwarf_type_encoding_name (unsigned enc
)
21859 const char *name
= get_DW_ATE_name (enc
);
21862 return dwarf_unknown ("ATE", enc
);
21868 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21872 print_spaces (indent
, f
);
21873 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21874 dwarf_tag_name (die
->tag
), die
->abbrev
,
21875 sect_offset_str (die
->sect_off
));
21877 if (die
->parent
!= NULL
)
21879 print_spaces (indent
, f
);
21880 fprintf_unfiltered (f
, " parent at offset: %s\n",
21881 sect_offset_str (die
->parent
->sect_off
));
21884 print_spaces (indent
, f
);
21885 fprintf_unfiltered (f
, " has children: %s\n",
21886 dwarf_bool_name (die
->child
!= NULL
));
21888 print_spaces (indent
, f
);
21889 fprintf_unfiltered (f
, " attributes:\n");
21891 for (i
= 0; i
< die
->num_attrs
; ++i
)
21893 print_spaces (indent
, f
);
21894 fprintf_unfiltered (f
, " %s (%s) ",
21895 dwarf_attr_name (die
->attrs
[i
].name
),
21896 dwarf_form_name (die
->attrs
[i
].form
));
21898 switch (die
->attrs
[i
].form
)
21901 case DW_FORM_addrx
:
21902 case DW_FORM_GNU_addr_index
:
21903 fprintf_unfiltered (f
, "address: ");
21904 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21906 case DW_FORM_block2
:
21907 case DW_FORM_block4
:
21908 case DW_FORM_block
:
21909 case DW_FORM_block1
:
21910 fprintf_unfiltered (f
, "block: size %s",
21911 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21913 case DW_FORM_exprloc
:
21914 fprintf_unfiltered (f
, "expression: size %s",
21915 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21917 case DW_FORM_data16
:
21918 fprintf_unfiltered (f
, "constant of 16 bytes");
21920 case DW_FORM_ref_addr
:
21921 fprintf_unfiltered (f
, "ref address: ");
21922 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21924 case DW_FORM_GNU_ref_alt
:
21925 fprintf_unfiltered (f
, "alt ref address: ");
21926 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21932 case DW_FORM_ref_udata
:
21933 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21934 (long) (DW_UNSND (&die
->attrs
[i
])));
21936 case DW_FORM_data1
:
21937 case DW_FORM_data2
:
21938 case DW_FORM_data4
:
21939 case DW_FORM_data8
:
21940 case DW_FORM_udata
:
21941 case DW_FORM_sdata
:
21942 fprintf_unfiltered (f
, "constant: %s",
21943 pulongest (DW_UNSND (&die
->attrs
[i
])));
21945 case DW_FORM_sec_offset
:
21946 fprintf_unfiltered (f
, "section offset: %s",
21947 pulongest (DW_UNSND (&die
->attrs
[i
])));
21949 case DW_FORM_ref_sig8
:
21950 fprintf_unfiltered (f
, "signature: %s",
21951 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21953 case DW_FORM_string
:
21955 case DW_FORM_line_strp
:
21957 case DW_FORM_GNU_str_index
:
21958 case DW_FORM_GNU_strp_alt
:
21959 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21960 DW_STRING (&die
->attrs
[i
])
21961 ? DW_STRING (&die
->attrs
[i
]) : "",
21962 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21965 if (DW_UNSND (&die
->attrs
[i
]))
21966 fprintf_unfiltered (f
, "flag: TRUE");
21968 fprintf_unfiltered (f
, "flag: FALSE");
21970 case DW_FORM_flag_present
:
21971 fprintf_unfiltered (f
, "flag: TRUE");
21973 case DW_FORM_indirect
:
21974 /* The reader will have reduced the indirect form to
21975 the "base form" so this form should not occur. */
21976 fprintf_unfiltered (f
,
21977 "unexpected attribute form: DW_FORM_indirect");
21979 case DW_FORM_implicit_const
:
21980 fprintf_unfiltered (f
, "constant: %s",
21981 plongest (DW_SND (&die
->attrs
[i
])));
21984 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21985 die
->attrs
[i
].form
);
21988 fprintf_unfiltered (f
, "\n");
21993 dump_die_for_error (struct die_info
*die
)
21995 dump_die_shallow (gdb_stderr
, 0, die
);
21999 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22001 int indent
= level
* 4;
22003 gdb_assert (die
!= NULL
);
22005 if (level
>= max_level
)
22008 dump_die_shallow (f
, indent
, die
);
22010 if (die
->child
!= NULL
)
22012 print_spaces (indent
, f
);
22013 fprintf_unfiltered (f
, " Children:");
22014 if (level
+ 1 < max_level
)
22016 fprintf_unfiltered (f
, "\n");
22017 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22021 fprintf_unfiltered (f
,
22022 " [not printed, max nesting level reached]\n");
22026 if (die
->sibling
!= NULL
&& level
> 0)
22028 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22032 /* This is called from the pdie macro in gdbinit.in.
22033 It's not static so gcc will keep a copy callable from gdb. */
22036 dump_die (struct die_info
*die
, int max_level
)
22038 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22042 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22046 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22047 to_underlying (die
->sect_off
),
22053 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22057 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22059 if (attr
->form_is_ref ())
22060 return (sect_offset
) DW_UNSND (attr
);
22062 complaint (_("unsupported die ref attribute form: '%s'"),
22063 dwarf_form_name (attr
->form
));
22067 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22068 * the value held by the attribute is not constant. */
22071 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22073 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22074 return DW_SND (attr
);
22075 else if (attr
->form
== DW_FORM_udata
22076 || attr
->form
== DW_FORM_data1
22077 || attr
->form
== DW_FORM_data2
22078 || attr
->form
== DW_FORM_data4
22079 || attr
->form
== DW_FORM_data8
)
22080 return DW_UNSND (attr
);
22083 /* For DW_FORM_data16 see attribute::form_is_constant. */
22084 complaint (_("Attribute value is not a constant (%s)"),
22085 dwarf_form_name (attr
->form
));
22086 return default_value
;
22090 /* Follow reference or signature attribute ATTR of SRC_DIE.
22091 On entry *REF_CU is the CU of SRC_DIE.
22092 On exit *REF_CU is the CU of the result. */
22094 static struct die_info
*
22095 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22096 struct dwarf2_cu
**ref_cu
)
22098 struct die_info
*die
;
22100 if (attr
->form_is_ref ())
22101 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22102 else if (attr
->form
== DW_FORM_ref_sig8
)
22103 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22106 dump_die_for_error (src_die
);
22107 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22108 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22114 /* Follow reference OFFSET.
22115 On entry *REF_CU is the CU of the source die referencing OFFSET.
22116 On exit *REF_CU is the CU of the result.
22117 Returns NULL if OFFSET is invalid. */
22119 static struct die_info
*
22120 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22121 struct dwarf2_cu
**ref_cu
)
22123 struct die_info temp_die
;
22124 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22125 struct dwarf2_per_objfile
*dwarf2_per_objfile
22126 = cu
->per_cu
->dwarf2_per_objfile
;
22128 gdb_assert (cu
->per_cu
!= NULL
);
22132 if (cu
->per_cu
->is_debug_types
)
22134 /* .debug_types CUs cannot reference anything outside their CU.
22135 If they need to, they have to reference a signatured type via
22136 DW_FORM_ref_sig8. */
22137 if (!cu
->header
.offset_in_cu_p (sect_off
))
22140 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22141 || !cu
->header
.offset_in_cu_p (sect_off
))
22143 struct dwarf2_per_cu_data
*per_cu
;
22145 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22146 dwarf2_per_objfile
);
22148 /* If necessary, add it to the queue and load its DIEs. */
22149 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22150 load_full_comp_unit (per_cu
, false, cu
->language
);
22152 target_cu
= per_cu
->cu
;
22154 else if (cu
->dies
== NULL
)
22156 /* We're loading full DIEs during partial symbol reading. */
22157 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22158 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22161 *ref_cu
= target_cu
;
22162 temp_die
.sect_off
= sect_off
;
22164 if (target_cu
!= cu
)
22165 target_cu
->ancestor
= cu
;
22167 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22169 to_underlying (sect_off
));
22172 /* Follow reference attribute ATTR of SRC_DIE.
22173 On entry *REF_CU is the CU of SRC_DIE.
22174 On exit *REF_CU is the CU of the result. */
22176 static struct die_info
*
22177 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22178 struct dwarf2_cu
**ref_cu
)
22180 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22181 struct dwarf2_cu
*cu
= *ref_cu
;
22182 struct die_info
*die
;
22184 die
= follow_die_offset (sect_off
,
22185 (attr
->form
== DW_FORM_GNU_ref_alt
22186 || cu
->per_cu
->is_dwz
),
22189 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22190 "at %s [in module %s]"),
22191 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22192 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22199 struct dwarf2_locexpr_baton
22200 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22201 dwarf2_per_cu_data
*per_cu
,
22202 CORE_ADDR (*get_frame_pc
) (void *baton
),
22203 void *baton
, bool resolve_abstract_p
)
22205 struct dwarf2_cu
*cu
;
22206 struct die_info
*die
;
22207 struct attribute
*attr
;
22208 struct dwarf2_locexpr_baton retval
;
22209 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22210 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22212 if (per_cu
->cu
== NULL
)
22213 load_cu (per_cu
, false);
22217 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22218 Instead just throw an error, not much else we can do. */
22219 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22220 sect_offset_str (sect_off
), objfile_name (objfile
));
22223 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22225 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22226 sect_offset_str (sect_off
), objfile_name (objfile
));
22228 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22229 if (!attr
&& resolve_abstract_p
22230 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22231 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22233 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22234 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22235 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22237 for (const auto &cand_off
22238 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22240 struct dwarf2_cu
*cand_cu
= cu
;
22241 struct die_info
*cand
22242 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22245 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22248 CORE_ADDR pc_low
, pc_high
;
22249 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22250 if (pc_low
== ((CORE_ADDR
) -1))
22252 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22253 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22254 if (!(pc_low
<= pc
&& pc
< pc_high
))
22258 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22265 /* DWARF: "If there is no such attribute, then there is no effect.".
22266 DATA is ignored if SIZE is 0. */
22268 retval
.data
= NULL
;
22271 else if (attr
->form_is_section_offset ())
22273 struct dwarf2_loclist_baton loclist_baton
;
22274 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22277 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22279 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22281 retval
.size
= size
;
22285 if (!attr
->form_is_block ())
22286 error (_("Dwarf Error: DIE at %s referenced in module %s "
22287 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22288 sect_offset_str (sect_off
), objfile_name (objfile
));
22290 retval
.data
= DW_BLOCK (attr
)->data
;
22291 retval
.size
= DW_BLOCK (attr
)->size
;
22293 retval
.per_cu
= cu
->per_cu
;
22295 age_cached_comp_units (dwarf2_per_objfile
);
22302 struct dwarf2_locexpr_baton
22303 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22304 dwarf2_per_cu_data
*per_cu
,
22305 CORE_ADDR (*get_frame_pc
) (void *baton
),
22308 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22310 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22313 /* Write a constant of a given type as target-ordered bytes into
22316 static const gdb_byte
*
22317 write_constant_as_bytes (struct obstack
*obstack
,
22318 enum bfd_endian byte_order
,
22325 *len
= TYPE_LENGTH (type
);
22326 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22327 store_unsigned_integer (result
, *len
, byte_order
, value
);
22335 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22336 dwarf2_per_cu_data
*per_cu
,
22340 struct dwarf2_cu
*cu
;
22341 struct die_info
*die
;
22342 struct attribute
*attr
;
22343 const gdb_byte
*result
= NULL
;
22346 enum bfd_endian byte_order
;
22347 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22349 if (per_cu
->cu
== NULL
)
22350 load_cu (per_cu
, false);
22354 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22355 Instead just throw an error, not much else we can do. */
22356 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22357 sect_offset_str (sect_off
), objfile_name (objfile
));
22360 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22362 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22363 sect_offset_str (sect_off
), objfile_name (objfile
));
22365 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22369 byte_order
= (bfd_big_endian (objfile
->obfd
)
22370 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22372 switch (attr
->form
)
22375 case DW_FORM_addrx
:
22376 case DW_FORM_GNU_addr_index
:
22380 *len
= cu
->header
.addr_size
;
22381 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22382 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22386 case DW_FORM_string
:
22389 case DW_FORM_GNU_str_index
:
22390 case DW_FORM_GNU_strp_alt
:
22391 /* DW_STRING is already allocated on the objfile obstack, point
22393 result
= (const gdb_byte
*) DW_STRING (attr
);
22394 *len
= strlen (DW_STRING (attr
));
22396 case DW_FORM_block1
:
22397 case DW_FORM_block2
:
22398 case DW_FORM_block4
:
22399 case DW_FORM_block
:
22400 case DW_FORM_exprloc
:
22401 case DW_FORM_data16
:
22402 result
= DW_BLOCK (attr
)->data
;
22403 *len
= DW_BLOCK (attr
)->size
;
22406 /* The DW_AT_const_value attributes are supposed to carry the
22407 symbol's value "represented as it would be on the target
22408 architecture." By the time we get here, it's already been
22409 converted to host endianness, so we just need to sign- or
22410 zero-extend it as appropriate. */
22411 case DW_FORM_data1
:
22412 type
= die_type (die
, cu
);
22413 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22414 if (result
== NULL
)
22415 result
= write_constant_as_bytes (obstack
, byte_order
,
22418 case DW_FORM_data2
:
22419 type
= die_type (die
, cu
);
22420 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22421 if (result
== NULL
)
22422 result
= write_constant_as_bytes (obstack
, byte_order
,
22425 case DW_FORM_data4
:
22426 type
= die_type (die
, cu
);
22427 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22428 if (result
== NULL
)
22429 result
= write_constant_as_bytes (obstack
, byte_order
,
22432 case DW_FORM_data8
:
22433 type
= die_type (die
, cu
);
22434 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22435 if (result
== NULL
)
22436 result
= write_constant_as_bytes (obstack
, byte_order
,
22440 case DW_FORM_sdata
:
22441 case DW_FORM_implicit_const
:
22442 type
= die_type (die
, cu
);
22443 result
= write_constant_as_bytes (obstack
, byte_order
,
22444 type
, DW_SND (attr
), len
);
22447 case DW_FORM_udata
:
22448 type
= die_type (die
, cu
);
22449 result
= write_constant_as_bytes (obstack
, byte_order
,
22450 type
, DW_UNSND (attr
), len
);
22454 complaint (_("unsupported const value attribute form: '%s'"),
22455 dwarf_form_name (attr
->form
));
22465 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22466 dwarf2_per_cu_data
*per_cu
)
22468 struct dwarf2_cu
*cu
;
22469 struct die_info
*die
;
22471 if (per_cu
->cu
== NULL
)
22472 load_cu (per_cu
, false);
22477 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22481 return die_type (die
, cu
);
22487 dwarf2_get_die_type (cu_offset die_offset
,
22488 struct dwarf2_per_cu_data
*per_cu
)
22490 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22491 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22494 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22495 On entry *REF_CU is the CU of SRC_DIE.
22496 On exit *REF_CU is the CU of the result.
22497 Returns NULL if the referenced DIE isn't found. */
22499 static struct die_info
*
22500 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22501 struct dwarf2_cu
**ref_cu
)
22503 struct die_info temp_die
;
22504 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22505 struct die_info
*die
;
22507 /* While it might be nice to assert sig_type->type == NULL here,
22508 we can get here for DW_AT_imported_declaration where we need
22509 the DIE not the type. */
22511 /* If necessary, add it to the queue and load its DIEs. */
22513 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22514 read_signatured_type (sig_type
);
22516 sig_cu
= sig_type
->per_cu
.cu
;
22517 gdb_assert (sig_cu
!= NULL
);
22518 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22519 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22520 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22521 to_underlying (temp_die
.sect_off
));
22524 struct dwarf2_per_objfile
*dwarf2_per_objfile
22525 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22527 /* For .gdb_index version 7 keep track of included TUs.
22528 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22529 if (dwarf2_per_objfile
->index_table
!= NULL
22530 && dwarf2_per_objfile
->index_table
->version
<= 7)
22532 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22537 sig_cu
->ancestor
= cu
;
22545 /* Follow signatured type referenced by ATTR in SRC_DIE.
22546 On entry *REF_CU is the CU of SRC_DIE.
22547 On exit *REF_CU is the CU of the result.
22548 The result is the DIE of the type.
22549 If the referenced type cannot be found an error is thrown. */
22551 static struct die_info
*
22552 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22553 struct dwarf2_cu
**ref_cu
)
22555 ULONGEST signature
= DW_SIGNATURE (attr
);
22556 struct signatured_type
*sig_type
;
22557 struct die_info
*die
;
22559 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22561 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22562 /* sig_type will be NULL if the signatured type is missing from
22564 if (sig_type
== NULL
)
22566 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22567 " from DIE at %s [in module %s]"),
22568 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22569 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22572 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22575 dump_die_for_error (src_die
);
22576 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22577 " from DIE at %s [in module %s]"),
22578 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22579 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22585 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22586 reading in and processing the type unit if necessary. */
22588 static struct type
*
22589 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22590 struct dwarf2_cu
*cu
)
22592 struct dwarf2_per_objfile
*dwarf2_per_objfile
22593 = cu
->per_cu
->dwarf2_per_objfile
;
22594 struct signatured_type
*sig_type
;
22595 struct dwarf2_cu
*type_cu
;
22596 struct die_info
*type_die
;
22599 sig_type
= lookup_signatured_type (cu
, signature
);
22600 /* sig_type will be NULL if the signatured type is missing from
22602 if (sig_type
== NULL
)
22604 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22605 " from DIE at %s [in module %s]"),
22606 hex_string (signature
), sect_offset_str (die
->sect_off
),
22607 objfile_name (dwarf2_per_objfile
->objfile
));
22608 return build_error_marker_type (cu
, die
);
22611 /* If we already know the type we're done. */
22612 if (sig_type
->type
!= NULL
)
22613 return sig_type
->type
;
22616 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22617 if (type_die
!= NULL
)
22619 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22620 is created. This is important, for example, because for c++ classes
22621 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22622 type
= read_type_die (type_die
, type_cu
);
22625 complaint (_("Dwarf Error: Cannot build signatured type %s"
22626 " referenced from DIE at %s [in module %s]"),
22627 hex_string (signature
), sect_offset_str (die
->sect_off
),
22628 objfile_name (dwarf2_per_objfile
->objfile
));
22629 type
= build_error_marker_type (cu
, die
);
22634 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22635 " from DIE at %s [in module %s]"),
22636 hex_string (signature
), sect_offset_str (die
->sect_off
),
22637 objfile_name (dwarf2_per_objfile
->objfile
));
22638 type
= build_error_marker_type (cu
, die
);
22640 sig_type
->type
= type
;
22645 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22646 reading in and processing the type unit if necessary. */
22648 static struct type
*
22649 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22650 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22652 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22653 if (attr
->form_is_ref ())
22655 struct dwarf2_cu
*type_cu
= cu
;
22656 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22658 return read_type_die (type_die
, type_cu
);
22660 else if (attr
->form
== DW_FORM_ref_sig8
)
22662 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22666 struct dwarf2_per_objfile
*dwarf2_per_objfile
22667 = cu
->per_cu
->dwarf2_per_objfile
;
22669 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22670 " at %s [in module %s]"),
22671 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22672 objfile_name (dwarf2_per_objfile
->objfile
));
22673 return build_error_marker_type (cu
, die
);
22677 /* Load the DIEs associated with type unit PER_CU into memory. */
22680 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22682 struct signatured_type
*sig_type
;
22684 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22685 gdb_assert (! per_cu
->type_unit_group_p ());
22687 /* We have the per_cu, but we need the signatured_type.
22688 Fortunately this is an easy translation. */
22689 gdb_assert (per_cu
->is_debug_types
);
22690 sig_type
= (struct signatured_type
*) per_cu
;
22692 gdb_assert (per_cu
->cu
== NULL
);
22694 read_signatured_type (sig_type
);
22696 gdb_assert (per_cu
->cu
!= NULL
);
22699 /* Read in a signatured type and build its CU and DIEs.
22700 If the type is a stub for the real type in a DWO file,
22701 read in the real type from the DWO file as well. */
22704 read_signatured_type (struct signatured_type
*sig_type
)
22706 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22708 gdb_assert (per_cu
->is_debug_types
);
22709 gdb_assert (per_cu
->cu
== NULL
);
22711 cutu_reader
reader (per_cu
, NULL
, 0, false);
22713 if (!reader
.dummy_p
)
22715 struct dwarf2_cu
*cu
= reader
.cu
;
22716 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22718 gdb_assert (cu
->die_hash
== NULL
);
22720 htab_create_alloc_ex (cu
->header
.length
/ 12,
22724 &cu
->comp_unit_obstack
,
22725 hashtab_obstack_allocate
,
22726 dummy_obstack_deallocate
);
22728 if (reader
.comp_unit_die
->has_children
)
22729 reader
.comp_unit_die
->child
22730 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22731 reader
.comp_unit_die
);
22732 cu
->dies
= reader
.comp_unit_die
;
22733 /* comp_unit_die is not stored in die_hash, no need. */
22735 /* We try not to read any attributes in this function, because
22736 not all CUs needed for references have been loaded yet, and
22737 symbol table processing isn't initialized. But we have to
22738 set the CU language, or we won't be able to build types
22739 correctly. Similarly, if we do not read the producer, we can
22740 not apply producer-specific interpretation. */
22741 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22746 sig_type
->per_cu
.tu_read
= 1;
22749 /* Decode simple location descriptions.
22750 Given a pointer to a dwarf block that defines a location, compute
22751 the location and return the value.
22753 NOTE drow/2003-11-18: This function is called in two situations
22754 now: for the address of static or global variables (partial symbols
22755 only) and for offsets into structures which are expected to be
22756 (more or less) constant. The partial symbol case should go away,
22757 and only the constant case should remain. That will let this
22758 function complain more accurately. A few special modes are allowed
22759 without complaint for global variables (for instance, global
22760 register values and thread-local values).
22762 A location description containing no operations indicates that the
22763 object is optimized out. The return value is 0 for that case.
22764 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22765 callers will only want a very basic result and this can become a
22768 Note that stack[0] is unused except as a default error return. */
22771 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22773 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22775 size_t size
= blk
->size
;
22776 const gdb_byte
*data
= blk
->data
;
22777 CORE_ADDR stack
[64];
22779 unsigned int bytes_read
, unsnd
;
22785 stack
[++stacki
] = 0;
22824 stack
[++stacki
] = op
- DW_OP_lit0
;
22859 stack
[++stacki
] = op
- DW_OP_reg0
;
22861 dwarf2_complex_location_expr_complaint ();
22865 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22867 stack
[++stacki
] = unsnd
;
22869 dwarf2_complex_location_expr_complaint ();
22873 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22878 case DW_OP_const1u
:
22879 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22883 case DW_OP_const1s
:
22884 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22888 case DW_OP_const2u
:
22889 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22893 case DW_OP_const2s
:
22894 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22898 case DW_OP_const4u
:
22899 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22903 case DW_OP_const4s
:
22904 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22908 case DW_OP_const8u
:
22909 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22914 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22920 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22925 stack
[stacki
+ 1] = stack
[stacki
];
22930 stack
[stacki
- 1] += stack
[stacki
];
22934 case DW_OP_plus_uconst
:
22935 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22941 stack
[stacki
- 1] -= stack
[stacki
];
22946 /* If we're not the last op, then we definitely can't encode
22947 this using GDB's address_class enum. This is valid for partial
22948 global symbols, although the variable's address will be bogus
22951 dwarf2_complex_location_expr_complaint ();
22954 case DW_OP_GNU_push_tls_address
:
22955 case DW_OP_form_tls_address
:
22956 /* The top of the stack has the offset from the beginning
22957 of the thread control block at which the variable is located. */
22958 /* Nothing should follow this operator, so the top of stack would
22960 /* This is valid for partial global symbols, but the variable's
22961 address will be bogus in the psymtab. Make it always at least
22962 non-zero to not look as a variable garbage collected by linker
22963 which have DW_OP_addr 0. */
22965 dwarf2_complex_location_expr_complaint ();
22969 case DW_OP_GNU_uninit
:
22973 case DW_OP_GNU_addr_index
:
22974 case DW_OP_GNU_const_index
:
22975 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22982 const char *name
= get_DW_OP_name (op
);
22985 complaint (_("unsupported stack op: '%s'"),
22988 complaint (_("unsupported stack op: '%02x'"),
22992 return (stack
[stacki
]);
22995 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22996 outside of the allocated space. Also enforce minimum>0. */
22997 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22999 complaint (_("location description stack overflow"));
23005 complaint (_("location description stack underflow"));
23009 return (stack
[stacki
]);
23012 /* memory allocation interface */
23014 static struct dwarf_block
*
23015 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23017 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23020 static struct die_info
*
23021 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23023 struct die_info
*die
;
23024 size_t size
= sizeof (struct die_info
);
23027 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23029 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23030 memset (die
, 0, sizeof (struct die_info
));
23036 /* Macro support. */
23038 /* An overload of dwarf_decode_macros that finds the correct section
23039 and ensures it is read in before calling the other overload. */
23042 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23043 int section_is_gnu
)
23045 struct dwarf2_per_objfile
*dwarf2_per_objfile
23046 = cu
->per_cu
->dwarf2_per_objfile
;
23047 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23048 const struct line_header
*lh
= cu
->line_header
;
23049 unsigned int offset_size
= cu
->header
.offset_size
;
23050 struct dwarf2_section_info
*section
;
23051 const char *section_name
;
23053 if (cu
->dwo_unit
!= nullptr)
23055 if (section_is_gnu
)
23057 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23058 section_name
= ".debug_macro.dwo";
23062 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23063 section_name
= ".debug_macinfo.dwo";
23068 if (section_is_gnu
)
23070 section
= &dwarf2_per_objfile
->macro
;
23071 section_name
= ".debug_macro";
23075 section
= &dwarf2_per_objfile
->macinfo
;
23076 section_name
= ".debug_macinfo";
23080 section
->read (objfile
);
23081 if (section
->buffer
== nullptr)
23083 complaint (_("missing %s section"), section_name
);
23087 buildsym_compunit
*builder
= cu
->get_builder ();
23089 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23090 offset_size
, offset
, section_is_gnu
);
23093 /* Return the .debug_loc section to use for CU.
23094 For DWO files use .debug_loc.dwo. */
23096 static struct dwarf2_section_info
*
23097 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23099 struct dwarf2_per_objfile
*dwarf2_per_objfile
23100 = cu
->per_cu
->dwarf2_per_objfile
;
23104 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23106 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23108 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23109 : &dwarf2_per_objfile
->loc
);
23112 /* A helper function that fills in a dwarf2_loclist_baton. */
23115 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23116 struct dwarf2_loclist_baton
*baton
,
23117 const struct attribute
*attr
)
23119 struct dwarf2_per_objfile
*dwarf2_per_objfile
23120 = cu
->per_cu
->dwarf2_per_objfile
;
23121 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23123 section
->read (dwarf2_per_objfile
->objfile
);
23125 baton
->per_cu
= cu
->per_cu
;
23126 gdb_assert (baton
->per_cu
);
23127 /* We don't know how long the location list is, but make sure we
23128 don't run off the edge of the section. */
23129 baton
->size
= section
->size
- DW_UNSND (attr
);
23130 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23131 baton
->base_address
= cu
->base_address
;
23132 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23136 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23137 struct dwarf2_cu
*cu
, int is_block
)
23139 struct dwarf2_per_objfile
*dwarf2_per_objfile
23140 = cu
->per_cu
->dwarf2_per_objfile
;
23141 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23142 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23144 if (attr
->form_is_section_offset ()
23145 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23146 the section. If so, fall through to the complaint in the
23148 && DW_UNSND (attr
) < section
->get_size (objfile
))
23150 struct dwarf2_loclist_baton
*baton
;
23152 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23154 fill_in_loclist_baton (cu
, baton
, attr
);
23156 if (cu
->base_known
== 0)
23157 complaint (_("Location list used without "
23158 "specifying the CU base address."));
23160 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23161 ? dwarf2_loclist_block_index
23162 : dwarf2_loclist_index
);
23163 SYMBOL_LOCATION_BATON (sym
) = baton
;
23167 struct dwarf2_locexpr_baton
*baton
;
23169 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23170 baton
->per_cu
= cu
->per_cu
;
23171 gdb_assert (baton
->per_cu
);
23173 if (attr
->form_is_block ())
23175 /* Note that we're just copying the block's data pointer
23176 here, not the actual data. We're still pointing into the
23177 info_buffer for SYM's objfile; right now we never release
23178 that buffer, but when we do clean up properly this may
23180 baton
->size
= DW_BLOCK (attr
)->size
;
23181 baton
->data
= DW_BLOCK (attr
)->data
;
23185 dwarf2_invalid_attrib_class_complaint ("location description",
23186 sym
->natural_name ());
23190 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23191 ? dwarf2_locexpr_block_index
23192 : dwarf2_locexpr_index
);
23193 SYMBOL_LOCATION_BATON (sym
) = baton
;
23200 dwarf2_per_cu_data::objfile () const
23202 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23204 /* Return the master objfile, so that we can report and look up the
23205 correct file containing this variable. */
23206 if (objfile
->separate_debug_objfile_backlink
)
23207 objfile
= objfile
->separate_debug_objfile_backlink
;
23212 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23213 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23214 CU_HEADERP first. */
23216 static const struct comp_unit_head
*
23217 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23218 const struct dwarf2_per_cu_data
*per_cu
)
23220 const gdb_byte
*info_ptr
;
23223 return &per_cu
->cu
->header
;
23225 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23227 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23228 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23229 rcuh_kind::COMPILE
);
23237 dwarf2_per_cu_data::addr_size () const
23239 struct comp_unit_head cu_header_local
;
23240 const struct comp_unit_head
*cu_headerp
;
23242 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23244 return cu_headerp
->addr_size
;
23250 dwarf2_per_cu_data::offset_size () const
23252 struct comp_unit_head cu_header_local
;
23253 const struct comp_unit_head
*cu_headerp
;
23255 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23257 return cu_headerp
->offset_size
;
23263 dwarf2_per_cu_data::ref_addr_size () const
23265 struct comp_unit_head cu_header_local
;
23266 const struct comp_unit_head
*cu_headerp
;
23268 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23270 if (cu_headerp
->version
== 2)
23271 return cu_headerp
->addr_size
;
23273 return cu_headerp
->offset_size
;
23279 dwarf2_per_cu_data::text_offset () const
23281 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23283 return objfile
->text_section_offset ();
23289 dwarf2_per_cu_data::addr_type () const
23291 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23292 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23293 struct type
*addr_type
= lookup_pointer_type (void_type
);
23294 int addr_size
= this->addr_size ();
23296 if (TYPE_LENGTH (addr_type
) == addr_size
)
23299 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23303 /* A helper function for dwarf2_find_containing_comp_unit that returns
23304 the index of the result, and that searches a vector. It will
23305 return a result even if the offset in question does not actually
23306 occur in any CU. This is separate so that it can be unit
23310 dwarf2_find_containing_comp_unit
23311 (sect_offset sect_off
,
23312 unsigned int offset_in_dwz
,
23313 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23318 high
= all_comp_units
.size () - 1;
23321 struct dwarf2_per_cu_data
*mid_cu
;
23322 int mid
= low
+ (high
- low
) / 2;
23324 mid_cu
= all_comp_units
[mid
];
23325 if (mid_cu
->is_dwz
> offset_in_dwz
23326 || (mid_cu
->is_dwz
== offset_in_dwz
23327 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23332 gdb_assert (low
== high
);
23336 /* Locate the .debug_info compilation unit from CU's objfile which contains
23337 the DIE at OFFSET. Raises an error on failure. */
23339 static struct dwarf2_per_cu_data
*
23340 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23341 unsigned int offset_in_dwz
,
23342 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23345 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23346 dwarf2_per_objfile
->all_comp_units
);
23347 struct dwarf2_per_cu_data
*this_cu
23348 = dwarf2_per_objfile
->all_comp_units
[low
];
23350 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23352 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23353 error (_("Dwarf Error: could not find partial DIE containing "
23354 "offset %s [in module %s]"),
23355 sect_offset_str (sect_off
),
23356 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23358 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23360 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23364 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
23365 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23366 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23367 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23374 namespace selftests
{
23375 namespace find_containing_comp_unit
{
23380 struct dwarf2_per_cu_data one
{};
23381 struct dwarf2_per_cu_data two
{};
23382 struct dwarf2_per_cu_data three
{};
23383 struct dwarf2_per_cu_data four
{};
23386 two
.sect_off
= sect_offset (one
.length
);
23391 four
.sect_off
= sect_offset (three
.length
);
23395 std::vector
<dwarf2_per_cu_data
*> units
;
23396 units
.push_back (&one
);
23397 units
.push_back (&two
);
23398 units
.push_back (&three
);
23399 units
.push_back (&four
);
23403 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23404 SELF_CHECK (units
[result
] == &one
);
23405 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23406 SELF_CHECK (units
[result
] == &one
);
23407 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23408 SELF_CHECK (units
[result
] == &two
);
23410 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23411 SELF_CHECK (units
[result
] == &three
);
23412 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23413 SELF_CHECK (units
[result
] == &three
);
23414 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23415 SELF_CHECK (units
[result
] == &four
);
23421 #endif /* GDB_SELF_TEST */
23423 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23425 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23426 : per_cu (per_cu_
),
23428 has_loclist (false),
23429 checked_producer (false),
23430 producer_is_gxx_lt_4_6 (false),
23431 producer_is_gcc_lt_4_3 (false),
23432 producer_is_icc (false),
23433 producer_is_icc_lt_14 (false),
23434 producer_is_codewarrior (false),
23435 processing_has_namespace_info (false)
23440 /* Destroy a dwarf2_cu. */
23442 dwarf2_cu::~dwarf2_cu ()
23447 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23450 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23451 enum language pretend_language
)
23453 struct attribute
*attr
;
23455 /* Set the language we're debugging. */
23456 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23457 if (attr
!= nullptr)
23458 set_cu_language (DW_UNSND (attr
), cu
);
23461 cu
->language
= pretend_language
;
23462 cu
->language_defn
= language_def (cu
->language
);
23465 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23468 /* Increase the age counter on each cached compilation unit, and free
23469 any that are too old. */
23472 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23474 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23476 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23477 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23478 while (per_cu
!= NULL
)
23480 per_cu
->cu
->last_used
++;
23481 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23482 dwarf2_mark (per_cu
->cu
);
23483 per_cu
= per_cu
->cu
->read_in_chain
;
23486 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23487 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23488 while (per_cu
!= NULL
)
23490 struct dwarf2_per_cu_data
*next_cu
;
23492 next_cu
= per_cu
->cu
->read_in_chain
;
23494 if (!per_cu
->cu
->mark
)
23497 *last_chain
= next_cu
;
23500 last_chain
= &per_cu
->cu
->read_in_chain
;
23506 /* Remove a single compilation unit from the cache. */
23509 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23511 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23512 struct dwarf2_per_objfile
*dwarf2_per_objfile
23513 = target_per_cu
->dwarf2_per_objfile
;
23515 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23516 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23517 while (per_cu
!= NULL
)
23519 struct dwarf2_per_cu_data
*next_cu
;
23521 next_cu
= per_cu
->cu
->read_in_chain
;
23523 if (per_cu
== target_per_cu
)
23527 *last_chain
= next_cu
;
23531 last_chain
= &per_cu
->cu
->read_in_chain
;
23537 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23538 We store these in a hash table separate from the DIEs, and preserve them
23539 when the DIEs are flushed out of cache.
23541 The CU "per_cu" pointer is needed because offset alone is not enough to
23542 uniquely identify the type. A file may have multiple .debug_types sections,
23543 or the type may come from a DWO file. Furthermore, while it's more logical
23544 to use per_cu->section+offset, with Fission the section with the data is in
23545 the DWO file but we don't know that section at the point we need it.
23546 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23547 because we can enter the lookup routine, get_die_type_at_offset, from
23548 outside this file, and thus won't necessarily have PER_CU->cu.
23549 Fortunately, PER_CU is stable for the life of the objfile. */
23551 struct dwarf2_per_cu_offset_and_type
23553 const struct dwarf2_per_cu_data
*per_cu
;
23554 sect_offset sect_off
;
23558 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23561 per_cu_offset_and_type_hash (const void *item
)
23563 const struct dwarf2_per_cu_offset_and_type
*ofs
23564 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23566 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23569 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23572 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23574 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23575 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23576 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23577 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23579 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23580 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23583 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23584 table if necessary. For convenience, return TYPE.
23586 The DIEs reading must have careful ordering to:
23587 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23588 reading current DIE.
23589 * Not trying to dereference contents of still incompletely read in types
23590 while reading in other DIEs.
23591 * Enable referencing still incompletely read in types just by a pointer to
23592 the type without accessing its fields.
23594 Therefore caller should follow these rules:
23595 * Try to fetch any prerequisite types we may need to build this DIE type
23596 before building the type and calling set_die_type.
23597 * After building type call set_die_type for current DIE as soon as
23598 possible before fetching more types to complete the current type.
23599 * Make the type as complete as possible before fetching more types. */
23601 static struct type
*
23602 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23604 struct dwarf2_per_objfile
*dwarf2_per_objfile
23605 = cu
->per_cu
->dwarf2_per_objfile
;
23606 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23607 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23608 struct attribute
*attr
;
23609 struct dynamic_prop prop
;
23611 /* For Ada types, make sure that the gnat-specific data is always
23612 initialized (if not already set). There are a few types where
23613 we should not be doing so, because the type-specific area is
23614 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23615 where the type-specific area is used to store the floatformat).
23616 But this is not a problem, because the gnat-specific information
23617 is actually not needed for these types. */
23618 if (need_gnat_info (cu
)
23619 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23620 && TYPE_CODE (type
) != TYPE_CODE_FLT
23621 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23622 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23623 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23624 && !HAVE_GNAT_AUX_INFO (type
))
23625 INIT_GNAT_SPECIFIC (type
);
23627 /* Read DW_AT_allocated and set in type. */
23628 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23629 if (attr
!= NULL
&& attr
->form_is_block ())
23631 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23632 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23633 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23635 else if (attr
!= NULL
)
23637 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23638 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23639 sect_offset_str (die
->sect_off
));
23642 /* Read DW_AT_associated and set in type. */
23643 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23644 if (attr
!= NULL
&& attr
->form_is_block ())
23646 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23647 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23648 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23650 else if (attr
!= NULL
)
23652 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23653 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23654 sect_offset_str (die
->sect_off
));
23657 /* Read DW_AT_data_location and set in type. */
23658 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23659 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23660 cu
->per_cu
->addr_type ()))
23661 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23663 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23664 dwarf2_per_objfile
->die_type_hash
23665 = htab_up (htab_create_alloc (127,
23666 per_cu_offset_and_type_hash
,
23667 per_cu_offset_and_type_eq
,
23668 NULL
, xcalloc
, xfree
));
23670 ofs
.per_cu
= cu
->per_cu
;
23671 ofs
.sect_off
= die
->sect_off
;
23673 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23674 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23676 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23677 sect_offset_str (die
->sect_off
));
23678 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23679 struct dwarf2_per_cu_offset_and_type
);
23684 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23685 or return NULL if the die does not have a saved type. */
23687 static struct type
*
23688 get_die_type_at_offset (sect_offset sect_off
,
23689 struct dwarf2_per_cu_data
*per_cu
)
23691 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23692 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23694 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23697 ofs
.per_cu
= per_cu
;
23698 ofs
.sect_off
= sect_off
;
23699 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23700 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23707 /* Look up the type for DIE in CU in die_type_hash,
23708 or return NULL if DIE does not have a saved type. */
23710 static struct type
*
23711 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23713 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23716 /* Add a dependence relationship from CU to REF_PER_CU. */
23719 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23720 struct dwarf2_per_cu_data
*ref_per_cu
)
23724 if (cu
->dependencies
== NULL
)
23726 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23727 NULL
, &cu
->comp_unit_obstack
,
23728 hashtab_obstack_allocate
,
23729 dummy_obstack_deallocate
);
23731 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23733 *slot
= ref_per_cu
;
23736 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23737 Set the mark field in every compilation unit in the
23738 cache that we must keep because we are keeping CU. */
23741 dwarf2_mark_helper (void **slot
, void *data
)
23743 struct dwarf2_per_cu_data
*per_cu
;
23745 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23747 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23748 reading of the chain. As such dependencies remain valid it is not much
23749 useful to track and undo them during QUIT cleanups. */
23750 if (per_cu
->cu
== NULL
)
23753 if (per_cu
->cu
->mark
)
23755 per_cu
->cu
->mark
= true;
23757 if (per_cu
->cu
->dependencies
!= NULL
)
23758 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23763 /* Set the mark field in CU and in every other compilation unit in the
23764 cache that we must keep because we are keeping CU. */
23767 dwarf2_mark (struct dwarf2_cu
*cu
)
23772 if (cu
->dependencies
!= NULL
)
23773 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23777 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23781 per_cu
->cu
->mark
= false;
23782 per_cu
= per_cu
->cu
->read_in_chain
;
23786 /* Trivial hash function for partial_die_info: the hash value of a DIE
23787 is its offset in .debug_info for this objfile. */
23790 partial_die_hash (const void *item
)
23792 const struct partial_die_info
*part_die
23793 = (const struct partial_die_info
*) item
;
23795 return to_underlying (part_die
->sect_off
);
23798 /* Trivial comparison function for partial_die_info structures: two DIEs
23799 are equal if they have the same offset. */
23802 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23804 const struct partial_die_info
*part_die_lhs
23805 = (const struct partial_die_info
*) item_lhs
;
23806 const struct partial_die_info
*part_die_rhs
23807 = (const struct partial_die_info
*) item_rhs
;
23809 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23812 struct cmd_list_element
*set_dwarf_cmdlist
;
23813 struct cmd_list_element
*show_dwarf_cmdlist
;
23816 set_dwarf_cmd (const char *args
, int from_tty
)
23818 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23823 show_dwarf_cmd (const char *args
, int from_tty
)
23825 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23829 show_check_physname (struct ui_file
*file
, int from_tty
,
23830 struct cmd_list_element
*c
, const char *value
)
23832 fprintf_filtered (file
,
23833 _("Whether to check \"physname\" is %s.\n"),
23837 void _initialize_dwarf2_read ();
23839 _initialize_dwarf2_read ()
23841 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23842 Set DWARF specific variables.\n\
23843 Configure DWARF variables such as the cache size."),
23844 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23845 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23847 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23848 Show DWARF specific variables.\n\
23849 Show DWARF variables such as the cache size."),
23850 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23851 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23853 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23854 &dwarf_max_cache_age
, _("\
23855 Set the upper bound on the age of cached DWARF compilation units."), _("\
23856 Show the upper bound on the age of cached DWARF compilation units."), _("\
23857 A higher limit means that cached compilation units will be stored\n\
23858 in memory longer, and more total memory will be used. Zero disables\n\
23859 caching, which can slow down startup."),
23861 show_dwarf_max_cache_age
,
23862 &set_dwarf_cmdlist
,
23863 &show_dwarf_cmdlist
);
23865 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23866 Set debugging of the DWARF reader."), _("\
23867 Show debugging of the DWARF reader."), _("\
23868 When enabled (non-zero), debugging messages are printed during DWARF\n\
23869 reading and symtab expansion. A value of 1 (one) provides basic\n\
23870 information. A value greater than 1 provides more verbose information."),
23873 &setdebuglist
, &showdebuglist
);
23875 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23876 Set debugging of the DWARF DIE reader."), _("\
23877 Show debugging of the DWARF DIE reader."), _("\
23878 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23879 The value is the maximum depth to print."),
23882 &setdebuglist
, &showdebuglist
);
23884 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23885 Set debugging of the dwarf line reader."), _("\
23886 Show debugging of the dwarf line reader."), _("\
23887 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23888 A value of 1 (one) provides basic information.\n\
23889 A value greater than 1 provides more verbose information."),
23892 &setdebuglist
, &showdebuglist
);
23894 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23895 Set cross-checking of \"physname\" code against demangler."), _("\
23896 Show cross-checking of \"physname\" code against demangler."), _("\
23897 When enabled, GDB's internal \"physname\" code is checked against\n\
23899 NULL
, show_check_physname
,
23900 &setdebuglist
, &showdebuglist
);
23902 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23903 no_class
, &use_deprecated_index_sections
, _("\
23904 Set whether to use deprecated gdb_index sections."), _("\
23905 Show whether to use deprecated gdb_index sections."), _("\
23906 When enabled, deprecated .gdb_index sections are used anyway.\n\
23907 Normally they are ignored either because of a missing feature or\n\
23908 performance issue.\n\
23909 Warning: This option must be enabled before gdb reads the file."),
23912 &setlist
, &showlist
);
23914 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23915 &dwarf2_locexpr_funcs
);
23916 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23917 &dwarf2_loclist_funcs
);
23919 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23920 &dwarf2_block_frame_base_locexpr_funcs
);
23921 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23922 &dwarf2_block_frame_base_loclist_funcs
);
23925 selftests::register_test ("dw2_expand_symtabs_matching",
23926 selftests::dw2_expand_symtabs_matching::run_test
);
23927 selftests::register_test ("dwarf2_find_containing_comp_unit",
23928 selftests::find_containing_comp_unit::run_test
);