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_string_at_offset
1255 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1257 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1261 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1262 ULONGEST str_index
);
1264 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1265 ULONGEST str_index
);
1267 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1269 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1270 struct dwarf2_cu
*);
1272 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1275 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1276 struct dwarf2_cu
*cu
);
1278 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1280 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1281 struct dwarf2_cu
*cu
);
1283 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1285 static struct die_info
*die_specification (struct die_info
*die
,
1286 struct dwarf2_cu
**);
1288 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1289 struct dwarf2_cu
*cu
);
1291 static void dwarf_decode_lines (struct line_header
*, const char *,
1292 struct dwarf2_cu
*, dwarf2_psymtab
*,
1293 CORE_ADDR
, int decode_mapping
);
1295 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1298 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1299 struct dwarf2_cu
*, struct symbol
* = NULL
);
1301 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1302 struct dwarf2_cu
*);
1304 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1307 struct obstack
*obstack
,
1308 struct dwarf2_cu
*cu
, LONGEST
*value
,
1309 const gdb_byte
**bytes
,
1310 struct dwarf2_locexpr_baton
**baton
);
1312 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1314 static int need_gnat_info (struct dwarf2_cu
*);
1316 static struct type
*die_descriptive_type (struct die_info
*,
1317 struct dwarf2_cu
*);
1319 static void set_descriptive_type (struct type
*, struct die_info
*,
1320 struct dwarf2_cu
*);
1322 static struct type
*die_containing_type (struct die_info
*,
1323 struct dwarf2_cu
*);
1325 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1326 struct dwarf2_cu
*);
1328 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1330 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1332 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1334 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1335 const char *suffix
, int physname
,
1336 struct dwarf2_cu
*cu
);
1338 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1340 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1342 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1344 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1346 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1348 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1350 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1351 struct dwarf2_cu
*, dwarf2_psymtab
*);
1353 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1354 values. Keep the items ordered with increasing constraints compliance. */
1357 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1358 PC_BOUNDS_NOT_PRESENT
,
1360 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1361 were present but they do not form a valid range of PC addresses. */
1364 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1367 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1371 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1372 CORE_ADDR
*, CORE_ADDR
*,
1376 static void get_scope_pc_bounds (struct die_info
*,
1377 CORE_ADDR
*, CORE_ADDR
*,
1378 struct dwarf2_cu
*);
1380 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1381 CORE_ADDR
, struct dwarf2_cu
*);
1383 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1384 struct dwarf2_cu
*);
1386 static void dwarf2_attach_fields_to_type (struct field_info
*,
1387 struct type
*, struct dwarf2_cu
*);
1389 static void dwarf2_add_member_fn (struct field_info
*,
1390 struct die_info
*, struct type
*,
1391 struct dwarf2_cu
*);
1393 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1395 struct dwarf2_cu
*);
1397 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1399 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1401 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1403 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1405 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1407 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1409 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1411 static struct type
*read_module_type (struct die_info
*die
,
1412 struct dwarf2_cu
*cu
);
1414 static const char *namespace_name (struct die_info
*die
,
1415 int *is_anonymous
, struct dwarf2_cu
*);
1417 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1419 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1421 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1422 struct dwarf2_cu
*);
1424 static struct die_info
*read_die_and_siblings_1
1425 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1428 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1429 const gdb_byte
*info_ptr
,
1430 const gdb_byte
**new_info_ptr
,
1431 struct die_info
*parent
);
1433 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1434 struct die_info
**, const gdb_byte
*,
1437 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1438 struct die_info
**, const gdb_byte
*);
1440 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1442 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1445 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1447 static const char *dwarf2_full_name (const char *name
,
1448 struct die_info
*die
,
1449 struct dwarf2_cu
*cu
);
1451 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1452 struct dwarf2_cu
*cu
);
1454 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1455 struct dwarf2_cu
**);
1457 static const char *dwarf_tag_name (unsigned int);
1459 static const char *dwarf_attr_name (unsigned int);
1461 static const char *dwarf_form_name (unsigned int);
1463 static const char *dwarf_bool_name (unsigned int);
1465 static const char *dwarf_type_encoding_name (unsigned int);
1467 static struct die_info
*sibling_die (struct die_info
*);
1469 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1471 static void dump_die_for_error (struct die_info
*);
1473 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1476 /*static*/ void dump_die (struct die_info
*, int max_level
);
1478 static void store_in_ref_table (struct die_info
*,
1479 struct dwarf2_cu
*);
1481 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1483 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1485 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1486 const struct attribute
*,
1487 struct dwarf2_cu
**);
1489 static struct die_info
*follow_die_ref (struct die_info
*,
1490 const struct attribute
*,
1491 struct dwarf2_cu
**);
1493 static struct die_info
*follow_die_sig (struct die_info
*,
1494 const struct attribute
*,
1495 struct dwarf2_cu
**);
1497 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1498 struct dwarf2_cu
*);
1500 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1501 const struct attribute
*,
1502 struct dwarf2_cu
*);
1504 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1506 static void read_signatured_type (struct signatured_type
*);
1508 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1509 struct die_info
*die
, struct dwarf2_cu
*cu
,
1510 struct dynamic_prop
*prop
, struct type
*type
);
1512 /* memory allocation interface */
1514 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1516 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1518 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1520 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1521 struct dwarf2_loclist_baton
*baton
,
1522 const struct attribute
*attr
);
1524 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1526 struct dwarf2_cu
*cu
,
1529 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1530 const gdb_byte
*info_ptr
,
1531 struct abbrev_info
*abbrev
);
1533 static hashval_t
partial_die_hash (const void *item
);
1535 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1537 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1538 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1539 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1541 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1542 struct die_info
*comp_unit_die
,
1543 enum language pretend_language
);
1545 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1547 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1549 static struct type
*set_die_type (struct die_info
*, struct type
*,
1550 struct dwarf2_cu
*);
1552 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1554 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1556 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1559 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1562 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1565 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1566 struct dwarf2_per_cu_data
*);
1568 static void dwarf2_mark (struct dwarf2_cu
*);
1570 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1572 static struct type
*get_die_type_at_offset (sect_offset
,
1573 struct dwarf2_per_cu_data
*);
1575 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1577 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1578 enum language pretend_language
);
1580 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1582 /* Class, the destructor of which frees all allocated queue entries. This
1583 will only have work to do if an error was thrown while processing the
1584 dwarf. If no error was thrown then the queue entries should have all
1585 been processed, and freed, as we went along. */
1587 class dwarf2_queue_guard
1590 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1591 : m_per_objfile (per_objfile
)
1595 /* Free any entries remaining on the queue. There should only be
1596 entries left if we hit an error while processing the dwarf. */
1597 ~dwarf2_queue_guard ()
1599 /* Ensure that no memory is allocated by the queue. */
1600 std::queue
<dwarf2_queue_item
> empty
;
1601 std::swap (m_per_objfile
->queue
, empty
);
1604 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1607 dwarf2_per_objfile
*m_per_objfile
;
1610 dwarf2_queue_item::~dwarf2_queue_item ()
1612 /* Anything still marked queued is likely to be in an
1613 inconsistent state, so discard it. */
1616 if (per_cu
->cu
!= NULL
)
1617 free_one_cached_comp_unit (per_cu
);
1622 /* The return type of find_file_and_directory. Note, the enclosed
1623 string pointers are only valid while this object is valid. */
1625 struct file_and_directory
1627 /* The filename. This is never NULL. */
1630 /* The compilation directory. NULL if not known. If we needed to
1631 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1632 points directly to the DW_AT_comp_dir string attribute owned by
1633 the obstack that owns the DIE. */
1634 const char *comp_dir
;
1636 /* If we needed to build a new string for comp_dir, this is what
1637 owns the storage. */
1638 std::string comp_dir_storage
;
1641 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1642 struct dwarf2_cu
*cu
);
1644 static htab_up
allocate_signatured_type_table ();
1646 static htab_up
allocate_dwo_unit_table ();
1648 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1649 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1650 struct dwp_file
*dwp_file
, const char *comp_dir
,
1651 ULONGEST signature
, int is_debug_types
);
1653 static struct dwp_file
*get_dwp_file
1654 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1656 static struct dwo_unit
*lookup_dwo_comp_unit
1657 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1659 static struct dwo_unit
*lookup_dwo_type_unit
1660 (struct signatured_type
*, const char *, const char *);
1662 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1664 /* A unique pointer to a dwo_file. */
1666 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1668 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1670 static void check_producer (struct dwarf2_cu
*cu
);
1672 static void free_line_header_voidp (void *arg
);
1674 /* Various complaints about symbol reading that don't abort the process. */
1677 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1679 complaint (_("statement list doesn't fit in .debug_line section"));
1683 dwarf2_debug_line_missing_file_complaint (void)
1685 complaint (_(".debug_line section has line data without a file"));
1689 dwarf2_debug_line_missing_end_sequence_complaint (void)
1691 complaint (_(".debug_line section has line "
1692 "program sequence without an end"));
1696 dwarf2_complex_location_expr_complaint (void)
1698 complaint (_("location expression too complex"));
1702 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1705 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1710 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1712 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1716 /* Hash function for line_header_hash. */
1719 line_header_hash (const struct line_header
*ofs
)
1721 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1724 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1727 line_header_hash_voidp (const void *item
)
1729 const struct line_header
*ofs
= (const struct line_header
*) item
;
1731 return line_header_hash (ofs
);
1734 /* Equality function for line_header_hash. */
1737 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1739 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1740 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1742 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1743 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1748 /* See declaration. */
1750 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1751 const dwarf2_debug_sections
*names
,
1753 : objfile (objfile_
),
1754 can_copy (can_copy_
)
1757 names
= &dwarf2_elf_names
;
1759 bfd
*obfd
= objfile
->obfd
;
1761 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1762 locate_sections (obfd
, sec
, *names
);
1765 dwarf2_per_objfile::~dwarf2_per_objfile ()
1767 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1768 free_cached_comp_units ();
1770 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1771 per_cu
->imported_symtabs_free ();
1773 for (signatured_type
*sig_type
: all_type_units
)
1774 sig_type
->per_cu
.imported_symtabs_free ();
1776 /* Everything else should be on the objfile obstack. */
1779 /* See declaration. */
1782 dwarf2_per_objfile::free_cached_comp_units ()
1784 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1785 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1786 while (per_cu
!= NULL
)
1788 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1791 *last_chain
= next_cu
;
1796 /* A helper class that calls free_cached_comp_units on
1799 class free_cached_comp_units
1803 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1804 : m_per_objfile (per_objfile
)
1808 ~free_cached_comp_units ()
1810 m_per_objfile
->free_cached_comp_units ();
1813 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1817 dwarf2_per_objfile
*m_per_objfile
;
1820 /* Try to locate the sections we need for DWARF 2 debugging
1821 information and return true if we have enough to do something.
1822 NAMES points to the dwarf2 section names, or is NULL if the standard
1823 ELF names are used. CAN_COPY is true for formats where symbol
1824 interposition is possible and so symbol values must follow copy
1825 relocation rules. */
1828 dwarf2_has_info (struct objfile
*objfile
,
1829 const struct dwarf2_debug_sections
*names
,
1832 if (objfile
->flags
& OBJF_READNEVER
)
1835 struct dwarf2_per_objfile
*dwarf2_per_objfile
1836 = get_dwarf2_per_objfile (objfile
);
1838 if (dwarf2_per_objfile
== NULL
)
1839 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1843 return (!dwarf2_per_objfile
->info
.is_virtual
1844 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1845 && !dwarf2_per_objfile
->abbrev
.is_virtual
1846 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1849 /* When loading sections, we look either for uncompressed section or for
1850 compressed section names. */
1853 section_is_p (const char *section_name
,
1854 const struct dwarf2_section_names
*names
)
1856 if (names
->normal
!= NULL
1857 && strcmp (section_name
, names
->normal
) == 0)
1859 if (names
->compressed
!= NULL
1860 && strcmp (section_name
, names
->compressed
) == 0)
1865 /* See declaration. */
1868 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1869 const dwarf2_debug_sections
&names
)
1871 flagword aflag
= bfd_section_flags (sectp
);
1873 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1876 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1877 > bfd_get_file_size (abfd
))
1879 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1880 warning (_("Discarding section %s which has a section size (%s"
1881 ") larger than the file size [in module %s]"),
1882 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1883 bfd_get_filename (abfd
));
1885 else if (section_is_p (sectp
->name
, &names
.info
))
1887 this->info
.s
.section
= sectp
;
1888 this->info
.size
= bfd_section_size (sectp
);
1890 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1892 this->abbrev
.s
.section
= sectp
;
1893 this->abbrev
.size
= bfd_section_size (sectp
);
1895 else if (section_is_p (sectp
->name
, &names
.line
))
1897 this->line
.s
.section
= sectp
;
1898 this->line
.size
= bfd_section_size (sectp
);
1900 else if (section_is_p (sectp
->name
, &names
.loc
))
1902 this->loc
.s
.section
= sectp
;
1903 this->loc
.size
= bfd_section_size (sectp
);
1905 else if (section_is_p (sectp
->name
, &names
.loclists
))
1907 this->loclists
.s
.section
= sectp
;
1908 this->loclists
.size
= bfd_section_size (sectp
);
1910 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1912 this->macinfo
.s
.section
= sectp
;
1913 this->macinfo
.size
= bfd_section_size (sectp
);
1915 else if (section_is_p (sectp
->name
, &names
.macro
))
1917 this->macro
.s
.section
= sectp
;
1918 this->macro
.size
= bfd_section_size (sectp
);
1920 else if (section_is_p (sectp
->name
, &names
.str
))
1922 this->str
.s
.section
= sectp
;
1923 this->str
.size
= bfd_section_size (sectp
);
1925 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1927 this->str_offsets
.s
.section
= sectp
;
1928 this->str_offsets
.size
= bfd_section_size (sectp
);
1930 else if (section_is_p (sectp
->name
, &names
.line_str
))
1932 this->line_str
.s
.section
= sectp
;
1933 this->line_str
.size
= bfd_section_size (sectp
);
1935 else if (section_is_p (sectp
->name
, &names
.addr
))
1937 this->addr
.s
.section
= sectp
;
1938 this->addr
.size
= bfd_section_size (sectp
);
1940 else if (section_is_p (sectp
->name
, &names
.frame
))
1942 this->frame
.s
.section
= sectp
;
1943 this->frame
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1947 this->eh_frame
.s
.section
= sectp
;
1948 this->eh_frame
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.ranges
))
1952 this->ranges
.s
.section
= sectp
;
1953 this->ranges
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1957 this->rnglists
.s
.section
= sectp
;
1958 this->rnglists
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.types
))
1962 struct dwarf2_section_info type_section
;
1964 memset (&type_section
, 0, sizeof (type_section
));
1965 type_section
.s
.section
= sectp
;
1966 type_section
.size
= bfd_section_size (sectp
);
1968 this->types
.push_back (type_section
);
1970 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1972 this->gdb_index
.s
.section
= sectp
;
1973 this->gdb_index
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1977 this->debug_names
.s
.section
= sectp
;
1978 this->debug_names
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1982 this->debug_aranges
.s
.section
= sectp
;
1983 this->debug_aranges
.size
= bfd_section_size (sectp
);
1986 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1987 && bfd_section_vma (sectp
) == 0)
1988 this->has_section_at_zero
= true;
1991 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1995 dwarf2_get_section_info (struct objfile
*objfile
,
1996 enum dwarf2_section_enum sect
,
1997 asection
**sectp
, const gdb_byte
**bufp
,
1998 bfd_size_type
*sizep
)
2000 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2001 struct dwarf2_section_info
*info
;
2003 /* We may see an objfile without any DWARF, in which case we just
2014 case DWARF2_DEBUG_FRAME
:
2015 info
= &data
->frame
;
2017 case DWARF2_EH_FRAME
:
2018 info
= &data
->eh_frame
;
2021 gdb_assert_not_reached ("unexpected section");
2024 info
->read (objfile
);
2026 *sectp
= info
->get_bfd_section ();
2027 *bufp
= info
->buffer
;
2028 *sizep
= info
->size
;
2031 /* A helper function to find the sections for a .dwz file. */
2034 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2036 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2038 /* Note that we only support the standard ELF names, because .dwz
2039 is ELF-only (at the time of writing). */
2040 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2042 dwz_file
->abbrev
.s
.section
= sectp
;
2043 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2045 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2047 dwz_file
->info
.s
.section
= sectp
;
2048 dwz_file
->info
.size
= bfd_section_size (sectp
);
2050 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2052 dwz_file
->str
.s
.section
= sectp
;
2053 dwz_file
->str
.size
= bfd_section_size (sectp
);
2055 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2057 dwz_file
->line
.s
.section
= sectp
;
2058 dwz_file
->line
.size
= bfd_section_size (sectp
);
2060 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2062 dwz_file
->macro
.s
.section
= sectp
;
2063 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2065 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2067 dwz_file
->gdb_index
.s
.section
= sectp
;
2068 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2070 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2072 dwz_file
->debug_names
.s
.section
= sectp
;
2073 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2077 /* See dwarf2read.h. */
2080 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2082 const char *filename
;
2083 bfd_size_type buildid_len_arg
;
2087 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2088 return dwarf2_per_objfile
->dwz_file
.get ();
2090 bfd_set_error (bfd_error_no_error
);
2091 gdb::unique_xmalloc_ptr
<char> data
2092 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2093 &buildid_len_arg
, &buildid
));
2096 if (bfd_get_error () == bfd_error_no_error
)
2098 error (_("could not read '.gnu_debugaltlink' section: %s"),
2099 bfd_errmsg (bfd_get_error ()));
2102 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2104 buildid_len
= (size_t) buildid_len_arg
;
2106 filename
= data
.get ();
2108 std::string abs_storage
;
2109 if (!IS_ABSOLUTE_PATH (filename
))
2111 gdb::unique_xmalloc_ptr
<char> abs
2112 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2114 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2115 filename
= abs_storage
.c_str ();
2118 /* First try the file name given in the section. If that doesn't
2119 work, try to use the build-id instead. */
2120 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2121 if (dwz_bfd
!= NULL
)
2123 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2124 dwz_bfd
.reset (nullptr);
2127 if (dwz_bfd
== NULL
)
2128 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2130 if (dwz_bfd
== nullptr)
2132 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2133 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2135 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2142 /* File successfully retrieved from server. */
2143 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2145 if (dwz_bfd
== nullptr)
2146 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2147 alt_filename
.get ());
2148 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2149 dwz_bfd
.reset (nullptr);
2153 if (dwz_bfd
== NULL
)
2154 error (_("could not find '.gnu_debugaltlink' file for %s"),
2155 objfile_name (dwarf2_per_objfile
->objfile
));
2157 std::unique_ptr
<struct dwz_file
> result
2158 (new struct dwz_file (std::move (dwz_bfd
)));
2160 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2163 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2164 result
->dwz_bfd
.get ());
2165 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2166 return dwarf2_per_objfile
->dwz_file
.get ();
2169 /* DWARF quick_symbols_functions support. */
2171 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2172 unique line tables, so we maintain a separate table of all .debug_line
2173 derived entries to support the sharing.
2174 All the quick functions need is the list of file names. We discard the
2175 line_header when we're done and don't need to record it here. */
2176 struct quick_file_names
2178 /* The data used to construct the hash key. */
2179 struct stmt_list_hash hash
;
2181 /* The number of entries in file_names, real_names. */
2182 unsigned int num_file_names
;
2184 /* The file names from the line table, after being run through
2186 const char **file_names
;
2188 /* The file names from the line table after being run through
2189 gdb_realpath. These are computed lazily. */
2190 const char **real_names
;
2193 /* When using the index (and thus not using psymtabs), each CU has an
2194 object of this type. This is used to hold information needed by
2195 the various "quick" methods. */
2196 struct dwarf2_per_cu_quick_data
2198 /* The file table. This can be NULL if there was no file table
2199 or it's currently not read in.
2200 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2201 struct quick_file_names
*file_names
;
2203 /* The corresponding symbol table. This is NULL if symbols for this
2204 CU have not yet been read. */
2205 struct compunit_symtab
*compunit_symtab
;
2207 /* A temporary mark bit used when iterating over all CUs in
2208 expand_symtabs_matching. */
2209 unsigned int mark
: 1;
2211 /* True if we've tried to read the file table and found there isn't one.
2212 There will be no point in trying to read it again next time. */
2213 unsigned int no_file_data
: 1;
2216 /* Utility hash function for a stmt_list_hash. */
2219 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2223 if (stmt_list_hash
->dwo_unit
!= NULL
)
2224 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2225 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2229 /* Utility equality function for a stmt_list_hash. */
2232 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2233 const struct stmt_list_hash
*rhs
)
2235 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2237 if (lhs
->dwo_unit
!= NULL
2238 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2241 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2244 /* Hash function for a quick_file_names. */
2247 hash_file_name_entry (const void *e
)
2249 const struct quick_file_names
*file_data
2250 = (const struct quick_file_names
*) e
;
2252 return hash_stmt_list_entry (&file_data
->hash
);
2255 /* Equality function for a quick_file_names. */
2258 eq_file_name_entry (const void *a
, const void *b
)
2260 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2261 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2263 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2266 /* Delete function for a quick_file_names. */
2269 delete_file_name_entry (void *e
)
2271 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2274 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2276 xfree ((void*) file_data
->file_names
[i
]);
2277 if (file_data
->real_names
)
2278 xfree ((void*) file_data
->real_names
[i
]);
2281 /* The space for the struct itself lives on objfile_obstack,
2282 so we don't free it here. */
2285 /* Create a quick_file_names hash table. */
2288 create_quick_file_names_table (unsigned int nr_initial_entries
)
2290 return htab_up (htab_create_alloc (nr_initial_entries
,
2291 hash_file_name_entry
, eq_file_name_entry
,
2292 delete_file_name_entry
, xcalloc
, xfree
));
2295 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2296 have to be created afterwards. You should call age_cached_comp_units after
2297 processing PER_CU->CU. dw2_setup must have been already called. */
2300 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2302 if (per_cu
->is_debug_types
)
2303 load_full_type_unit (per_cu
);
2305 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2307 if (per_cu
->cu
== NULL
)
2308 return; /* Dummy CU. */
2310 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2313 /* Read in the symbols for PER_CU. */
2316 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2318 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2320 /* Skip type_unit_groups, reading the type units they contain
2321 is handled elsewhere. */
2322 if (per_cu
->type_unit_group_p ())
2325 /* The destructor of dwarf2_queue_guard frees any entries left on
2326 the queue. After this point we're guaranteed to leave this function
2327 with the dwarf queue empty. */
2328 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2330 if (dwarf2_per_objfile
->using_index
2331 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2332 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2334 queue_comp_unit (per_cu
, language_minimal
);
2335 load_cu (per_cu
, skip_partial
);
2337 /* If we just loaded a CU from a DWO, and we're working with an index
2338 that may badly handle TUs, load all the TUs in that DWO as well.
2339 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2340 if (!per_cu
->is_debug_types
2341 && per_cu
->cu
!= NULL
2342 && per_cu
->cu
->dwo_unit
!= NULL
2343 && dwarf2_per_objfile
->index_table
!= NULL
2344 && dwarf2_per_objfile
->index_table
->version
<= 7
2345 /* DWP files aren't supported yet. */
2346 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2347 queue_and_load_all_dwo_tus (per_cu
);
2350 process_queue (dwarf2_per_objfile
);
2352 /* Age the cache, releasing compilation units that have not
2353 been used recently. */
2354 age_cached_comp_units (dwarf2_per_objfile
);
2357 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2358 the objfile from which this CU came. Returns the resulting symbol
2361 static struct compunit_symtab
*
2362 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2364 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2366 gdb_assert (dwarf2_per_objfile
->using_index
);
2367 if (!per_cu
->v
.quick
->compunit_symtab
)
2369 free_cached_comp_units
freer (dwarf2_per_objfile
);
2370 scoped_restore decrementer
= increment_reading_symtab ();
2371 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2372 process_cu_includes (dwarf2_per_objfile
);
2375 return per_cu
->v
.quick
->compunit_symtab
;
2378 /* See declaration. */
2380 dwarf2_per_cu_data
*
2381 dwarf2_per_objfile::get_cutu (int index
)
2383 if (index
>= this->all_comp_units
.size ())
2385 index
-= this->all_comp_units
.size ();
2386 gdb_assert (index
< this->all_type_units
.size ());
2387 return &this->all_type_units
[index
]->per_cu
;
2390 return this->all_comp_units
[index
];
2393 /* See declaration. */
2395 dwarf2_per_cu_data
*
2396 dwarf2_per_objfile::get_cu (int index
)
2398 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2400 return this->all_comp_units
[index
];
2403 /* See declaration. */
2406 dwarf2_per_objfile::get_tu (int index
)
2408 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2410 return this->all_type_units
[index
];
2413 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2414 objfile_obstack, and constructed with the specified field
2417 static dwarf2_per_cu_data
*
2418 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2419 struct dwarf2_section_info
*section
,
2421 sect_offset sect_off
, ULONGEST length
)
2423 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2424 dwarf2_per_cu_data
*the_cu
2425 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2426 struct dwarf2_per_cu_data
);
2427 the_cu
->sect_off
= sect_off
;
2428 the_cu
->length
= length
;
2429 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2430 the_cu
->section
= section
;
2431 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2432 struct dwarf2_per_cu_quick_data
);
2433 the_cu
->is_dwz
= is_dwz
;
2437 /* A helper for create_cus_from_index that handles a given list of
2441 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2442 const gdb_byte
*cu_list
, offset_type n_elements
,
2443 struct dwarf2_section_info
*section
,
2446 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2448 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2450 sect_offset sect_off
2451 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2452 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2455 dwarf2_per_cu_data
*per_cu
2456 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2458 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2462 /* Read the CU list from the mapped index, and use it to create all
2463 the CU objects for this objfile. */
2466 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2467 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2468 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2470 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2471 dwarf2_per_objfile
->all_comp_units
.reserve
2472 ((cu_list_elements
+ dwz_elements
) / 2);
2474 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2475 &dwarf2_per_objfile
->info
, 0);
2477 if (dwz_elements
== 0)
2480 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2481 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2485 /* Create the signatured type hash table from the index. */
2488 create_signatured_type_table_from_index
2489 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2490 struct dwarf2_section_info
*section
,
2491 const gdb_byte
*bytes
,
2492 offset_type elements
)
2494 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2496 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2497 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2499 htab_up sig_types_hash
= allocate_signatured_type_table ();
2501 for (offset_type i
= 0; i
< elements
; i
+= 3)
2503 struct signatured_type
*sig_type
;
2506 cu_offset type_offset_in_tu
;
2508 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2509 sect_offset sect_off
2510 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2512 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2514 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2517 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2518 struct signatured_type
);
2519 sig_type
->signature
= signature
;
2520 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2521 sig_type
->per_cu
.is_debug_types
= 1;
2522 sig_type
->per_cu
.section
= section
;
2523 sig_type
->per_cu
.sect_off
= sect_off
;
2524 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2525 sig_type
->per_cu
.v
.quick
2526 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2527 struct dwarf2_per_cu_quick_data
);
2529 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2532 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2535 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2538 /* Create the signatured type hash table from .debug_names. */
2541 create_signatured_type_table_from_debug_names
2542 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2543 const mapped_debug_names
&map
,
2544 struct dwarf2_section_info
*section
,
2545 struct dwarf2_section_info
*abbrev_section
)
2547 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2549 section
->read (objfile
);
2550 abbrev_section
->read (objfile
);
2552 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2553 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2555 htab_up sig_types_hash
= allocate_signatured_type_table ();
2557 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2559 struct signatured_type
*sig_type
;
2562 sect_offset sect_off
2563 = (sect_offset
) (extract_unsigned_integer
2564 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2566 map
.dwarf5_byte_order
));
2568 comp_unit_head cu_header
;
2569 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2571 section
->buffer
+ to_underlying (sect_off
),
2574 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2575 struct signatured_type
);
2576 sig_type
->signature
= cu_header
.signature
;
2577 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2578 sig_type
->per_cu
.is_debug_types
= 1;
2579 sig_type
->per_cu
.section
= section
;
2580 sig_type
->per_cu
.sect_off
= sect_off
;
2581 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2582 sig_type
->per_cu
.v
.quick
2583 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2584 struct dwarf2_per_cu_quick_data
);
2586 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2589 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2592 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2595 /* Read the address map data from the mapped index, and use it to
2596 populate the objfile's psymtabs_addrmap. */
2599 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2600 struct mapped_index
*index
)
2602 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2603 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2604 const gdb_byte
*iter
, *end
;
2605 struct addrmap
*mutable_map
;
2608 auto_obstack temp_obstack
;
2610 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2612 iter
= index
->address_table
.data ();
2613 end
= iter
+ index
->address_table
.size ();
2615 baseaddr
= objfile
->text_section_offset ();
2619 ULONGEST hi
, lo
, cu_index
;
2620 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2622 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2624 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2629 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2630 hex_string (lo
), hex_string (hi
));
2634 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2636 complaint (_(".gdb_index address table has invalid CU number %u"),
2637 (unsigned) cu_index
);
2641 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2642 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2643 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2644 dwarf2_per_objfile
->get_cu (cu_index
));
2647 objfile
->partial_symtabs
->psymtabs_addrmap
2648 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2651 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2652 populate the objfile's psymtabs_addrmap. */
2655 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2656 struct dwarf2_section_info
*section
)
2658 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2659 bfd
*abfd
= objfile
->obfd
;
2660 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2661 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2663 auto_obstack temp_obstack
;
2664 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2666 std::unordered_map
<sect_offset
,
2667 dwarf2_per_cu_data
*,
2668 gdb::hash_enum
<sect_offset
>>
2669 debug_info_offset_to_per_cu
;
2670 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2672 const auto insertpair
2673 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2674 if (!insertpair
.second
)
2676 warning (_("Section .debug_aranges in %s has duplicate "
2677 "debug_info_offset %s, ignoring .debug_aranges."),
2678 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2683 section
->read (objfile
);
2685 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2687 const gdb_byte
*addr
= section
->buffer
;
2689 while (addr
< section
->buffer
+ section
->size
)
2691 const gdb_byte
*const entry_addr
= addr
;
2692 unsigned int bytes_read
;
2694 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2698 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2699 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2700 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2701 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2703 warning (_("Section .debug_aranges in %s entry at offset %s "
2704 "length %s exceeds section length %s, "
2705 "ignoring .debug_aranges."),
2706 objfile_name (objfile
),
2707 plongest (entry_addr
- section
->buffer
),
2708 plongest (bytes_read
+ entry_length
),
2709 pulongest (section
->size
));
2713 /* The version number. */
2714 const uint16_t version
= read_2_bytes (abfd
, addr
);
2718 warning (_("Section .debug_aranges in %s entry at offset %s "
2719 "has unsupported version %d, ignoring .debug_aranges."),
2720 objfile_name (objfile
),
2721 plongest (entry_addr
- section
->buffer
), version
);
2725 const uint64_t debug_info_offset
2726 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2727 addr
+= offset_size
;
2728 const auto per_cu_it
2729 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2730 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2732 warning (_("Section .debug_aranges in %s entry at offset %s "
2733 "debug_info_offset %s does not exists, "
2734 "ignoring .debug_aranges."),
2735 objfile_name (objfile
),
2736 plongest (entry_addr
- section
->buffer
),
2737 pulongest (debug_info_offset
));
2740 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2742 const uint8_t address_size
= *addr
++;
2743 if (address_size
< 1 || address_size
> 8)
2745 warning (_("Section .debug_aranges in %s entry at offset %s "
2746 "address_size %u is invalid, ignoring .debug_aranges."),
2747 objfile_name (objfile
),
2748 plongest (entry_addr
- section
->buffer
), address_size
);
2752 const uint8_t segment_selector_size
= *addr
++;
2753 if (segment_selector_size
!= 0)
2755 warning (_("Section .debug_aranges in %s entry at offset %s "
2756 "segment_selector_size %u is not supported, "
2757 "ignoring .debug_aranges."),
2758 objfile_name (objfile
),
2759 plongest (entry_addr
- section
->buffer
),
2760 segment_selector_size
);
2764 /* Must pad to an alignment boundary that is twice the address
2765 size. It is undocumented by the DWARF standard but GCC does
2767 for (size_t padding
= ((-(addr
- section
->buffer
))
2768 & (2 * address_size
- 1));
2769 padding
> 0; padding
--)
2772 warning (_("Section .debug_aranges in %s entry at offset %s "
2773 "padding is not zero, ignoring .debug_aranges."),
2774 objfile_name (objfile
),
2775 plongest (entry_addr
- section
->buffer
));
2781 if (addr
+ 2 * address_size
> entry_end
)
2783 warning (_("Section .debug_aranges in %s entry at offset %s "
2784 "address list is not properly terminated, "
2785 "ignoring .debug_aranges."),
2786 objfile_name (objfile
),
2787 plongest (entry_addr
- section
->buffer
));
2790 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2792 addr
+= address_size
;
2793 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2795 addr
+= address_size
;
2796 if (start
== 0 && length
== 0)
2798 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2800 /* Symbol was eliminated due to a COMDAT group. */
2803 ULONGEST end
= start
+ length
;
2804 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2806 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2808 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2812 objfile
->partial_symtabs
->psymtabs_addrmap
2813 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2816 /* Find a slot in the mapped index INDEX for the object named NAME.
2817 If NAME is found, set *VEC_OUT to point to the CU vector in the
2818 constant pool and return true. If NAME cannot be found, return
2822 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2823 offset_type
**vec_out
)
2826 offset_type slot
, step
;
2827 int (*cmp
) (const char *, const char *);
2829 gdb::unique_xmalloc_ptr
<char> without_params
;
2830 if (current_language
->la_language
== language_cplus
2831 || current_language
->la_language
== language_fortran
2832 || current_language
->la_language
== language_d
)
2834 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2837 if (strchr (name
, '(') != NULL
)
2839 without_params
= cp_remove_params (name
);
2841 if (without_params
!= NULL
)
2842 name
= without_params
.get ();
2846 /* Index version 4 did not support case insensitive searches. But the
2847 indices for case insensitive languages are built in lowercase, therefore
2848 simulate our NAME being searched is also lowercased. */
2849 hash
= mapped_index_string_hash ((index
->version
== 4
2850 && case_sensitivity
== case_sensitive_off
2851 ? 5 : index
->version
),
2854 slot
= hash
& (index
->symbol_table
.size () - 1);
2855 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2856 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2862 const auto &bucket
= index
->symbol_table
[slot
];
2863 if (bucket
.name
== 0 && bucket
.vec
== 0)
2866 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2867 if (!cmp (name
, str
))
2869 *vec_out
= (offset_type
*) (index
->constant_pool
2870 + MAYBE_SWAP (bucket
.vec
));
2874 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2878 /* A helper function that reads the .gdb_index from BUFFER and fills
2879 in MAP. FILENAME is the name of the file containing the data;
2880 it is used for error reporting. DEPRECATED_OK is true if it is
2881 ok to use deprecated sections.
2883 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2884 out parameters that are filled in with information about the CU and
2885 TU lists in the section.
2887 Returns true if all went well, false otherwise. */
2890 read_gdb_index_from_buffer (struct objfile
*objfile
,
2891 const char *filename
,
2893 gdb::array_view
<const gdb_byte
> buffer
,
2894 struct mapped_index
*map
,
2895 const gdb_byte
**cu_list
,
2896 offset_type
*cu_list_elements
,
2897 const gdb_byte
**types_list
,
2898 offset_type
*types_list_elements
)
2900 const gdb_byte
*addr
= &buffer
[0];
2902 /* Version check. */
2903 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2904 /* Versions earlier than 3 emitted every copy of a psymbol. This
2905 causes the index to behave very poorly for certain requests. Version 3
2906 contained incomplete addrmap. So, it seems better to just ignore such
2910 static int warning_printed
= 0;
2911 if (!warning_printed
)
2913 warning (_("Skipping obsolete .gdb_index section in %s."),
2915 warning_printed
= 1;
2919 /* Index version 4 uses a different hash function than index version
2922 Versions earlier than 6 did not emit psymbols for inlined
2923 functions. Using these files will cause GDB not to be able to
2924 set breakpoints on inlined functions by name, so we ignore these
2925 indices unless the user has done
2926 "set use-deprecated-index-sections on". */
2927 if (version
< 6 && !deprecated_ok
)
2929 static int warning_printed
= 0;
2930 if (!warning_printed
)
2933 Skipping deprecated .gdb_index section in %s.\n\
2934 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2935 to use the section anyway."),
2937 warning_printed
= 1;
2941 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2942 of the TU (for symbols coming from TUs),
2943 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2944 Plus gold-generated indices can have duplicate entries for global symbols,
2945 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2946 These are just performance bugs, and we can't distinguish gdb-generated
2947 indices from gold-generated ones, so issue no warning here. */
2949 /* Indexes with higher version than the one supported by GDB may be no
2950 longer backward compatible. */
2954 map
->version
= version
;
2956 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2959 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2960 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2964 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2965 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2966 - MAYBE_SWAP (metadata
[i
]))
2970 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2971 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2973 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2976 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2977 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2979 = gdb::array_view
<mapped_index::symbol_table_slot
>
2980 ((mapped_index::symbol_table_slot
*) symbol_table
,
2981 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2984 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2989 /* Callback types for dwarf2_read_gdb_index. */
2991 typedef gdb::function_view
2992 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2993 get_gdb_index_contents_ftype
;
2994 typedef gdb::function_view
2995 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2996 get_gdb_index_contents_dwz_ftype
;
2998 /* Read .gdb_index. If everything went ok, initialize the "quick"
2999 elements of all the CUs and return 1. Otherwise, return 0. */
3002 dwarf2_read_gdb_index
3003 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3004 get_gdb_index_contents_ftype get_gdb_index_contents
,
3005 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3007 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3008 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3009 struct dwz_file
*dwz
;
3010 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3012 gdb::array_view
<const gdb_byte
> main_index_contents
3013 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3015 if (main_index_contents
.empty ())
3018 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3019 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3020 use_deprecated_index_sections
,
3021 main_index_contents
, map
.get (), &cu_list
,
3022 &cu_list_elements
, &types_list
,
3023 &types_list_elements
))
3026 /* Don't use the index if it's empty. */
3027 if (map
->symbol_table
.empty ())
3030 /* If there is a .dwz file, read it so we can get its CU list as
3032 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3035 struct mapped_index dwz_map
;
3036 const gdb_byte
*dwz_types_ignore
;
3037 offset_type dwz_types_elements_ignore
;
3039 gdb::array_view
<const gdb_byte
> dwz_index_content
3040 = get_gdb_index_contents_dwz (objfile
, dwz
);
3042 if (dwz_index_content
.empty ())
3045 if (!read_gdb_index_from_buffer (objfile
,
3046 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3047 1, dwz_index_content
, &dwz_map
,
3048 &dwz_list
, &dwz_list_elements
,
3050 &dwz_types_elements_ignore
))
3052 warning (_("could not read '.gdb_index' section from %s; skipping"),
3053 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3058 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3059 dwz_list
, dwz_list_elements
);
3061 if (types_list_elements
)
3063 /* We can only handle a single .debug_types when we have an
3065 if (dwarf2_per_objfile
->types
.size () != 1)
3068 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3070 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3071 types_list
, types_list_elements
);
3074 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3076 dwarf2_per_objfile
->index_table
= std::move (map
);
3077 dwarf2_per_objfile
->using_index
= 1;
3078 dwarf2_per_objfile
->quick_file_names_table
=
3079 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3084 /* die_reader_func for dw2_get_file_names. */
3087 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3088 const gdb_byte
*info_ptr
,
3089 struct die_info
*comp_unit_die
)
3091 struct dwarf2_cu
*cu
= reader
->cu
;
3092 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3093 struct dwarf2_per_objfile
*dwarf2_per_objfile
3094 = cu
->per_cu
->dwarf2_per_objfile
;
3095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3096 struct dwarf2_per_cu_data
*lh_cu
;
3097 struct attribute
*attr
;
3099 struct quick_file_names
*qfn
;
3101 gdb_assert (! this_cu
->is_debug_types
);
3103 /* Our callers never want to match partial units -- instead they
3104 will match the enclosing full CU. */
3105 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3107 this_cu
->v
.quick
->no_file_data
= 1;
3115 sect_offset line_offset
{};
3117 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3118 if (attr
!= nullptr)
3120 struct quick_file_names find_entry
;
3122 line_offset
= (sect_offset
) DW_UNSND (attr
);
3124 /* We may have already read in this line header (TU line header sharing).
3125 If we have we're done. */
3126 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3127 find_entry
.hash
.line_sect_off
= line_offset
;
3128 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3129 &find_entry
, INSERT
);
3132 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3136 lh
= dwarf_decode_line_header (line_offset
, cu
);
3140 lh_cu
->v
.quick
->no_file_data
= 1;
3144 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3145 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3146 qfn
->hash
.line_sect_off
= line_offset
;
3147 gdb_assert (slot
!= NULL
);
3150 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3153 if (strcmp (fnd
.name
, "<unknown>") != 0)
3156 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3158 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3160 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3161 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3162 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3163 fnd
.comp_dir
).release ();
3164 qfn
->real_names
= NULL
;
3166 lh_cu
->v
.quick
->file_names
= qfn
;
3169 /* A helper for the "quick" functions which attempts to read the line
3170 table for THIS_CU. */
3172 static struct quick_file_names
*
3173 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3175 /* This should never be called for TUs. */
3176 gdb_assert (! this_cu
->is_debug_types
);
3177 /* Nor type unit groups. */
3178 gdb_assert (! this_cu
->type_unit_group_p ());
3180 if (this_cu
->v
.quick
->file_names
!= NULL
)
3181 return this_cu
->v
.quick
->file_names
;
3182 /* If we know there is no line data, no point in looking again. */
3183 if (this_cu
->v
.quick
->no_file_data
)
3186 cutu_reader
reader (this_cu
);
3187 if (!reader
.dummy_p
)
3188 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3190 if (this_cu
->v
.quick
->no_file_data
)
3192 return this_cu
->v
.quick
->file_names
;
3195 /* A helper for the "quick" functions which computes and caches the
3196 real path for a given file name from the line table. */
3199 dw2_get_real_path (struct objfile
*objfile
,
3200 struct quick_file_names
*qfn
, int index
)
3202 if (qfn
->real_names
== NULL
)
3203 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3204 qfn
->num_file_names
, const char *);
3206 if (qfn
->real_names
[index
] == NULL
)
3207 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3209 return qfn
->real_names
[index
];
3212 static struct symtab
*
3213 dw2_find_last_source_symtab (struct objfile
*objfile
)
3215 struct dwarf2_per_objfile
*dwarf2_per_objfile
3216 = get_dwarf2_per_objfile (objfile
);
3217 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3218 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3223 return compunit_primary_filetab (cust
);
3226 /* Traversal function for dw2_forget_cached_source_info. */
3229 dw2_free_cached_file_names (void **slot
, void *info
)
3231 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3233 if (file_data
->real_names
)
3237 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3239 xfree ((void*) file_data
->real_names
[i
]);
3240 file_data
->real_names
[i
] = NULL
;
3248 dw2_forget_cached_source_info (struct objfile
*objfile
)
3250 struct dwarf2_per_objfile
*dwarf2_per_objfile
3251 = get_dwarf2_per_objfile (objfile
);
3253 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3254 dw2_free_cached_file_names
, NULL
);
3257 /* Helper function for dw2_map_symtabs_matching_filename that expands
3258 the symtabs and calls the iterator. */
3261 dw2_map_expand_apply (struct objfile
*objfile
,
3262 struct dwarf2_per_cu_data
*per_cu
,
3263 const char *name
, const char *real_path
,
3264 gdb::function_view
<bool (symtab
*)> callback
)
3266 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3268 /* Don't visit already-expanded CUs. */
3269 if (per_cu
->v
.quick
->compunit_symtab
)
3272 /* This may expand more than one symtab, and we want to iterate over
3274 dw2_instantiate_symtab (per_cu
, false);
3276 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3277 last_made
, callback
);
3280 /* Implementation of the map_symtabs_matching_filename method. */
3283 dw2_map_symtabs_matching_filename
3284 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3285 gdb::function_view
<bool (symtab
*)> callback
)
3287 const char *name_basename
= lbasename (name
);
3288 struct dwarf2_per_objfile
*dwarf2_per_objfile
3289 = get_dwarf2_per_objfile (objfile
);
3291 /* The rule is CUs specify all the files, including those used by
3292 any TU, so there's no need to scan TUs here. */
3294 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3296 /* We only need to look at symtabs not already expanded. */
3297 if (per_cu
->v
.quick
->compunit_symtab
)
3300 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3301 if (file_data
== NULL
)
3304 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3306 const char *this_name
= file_data
->file_names
[j
];
3307 const char *this_real_name
;
3309 if (compare_filenames_for_search (this_name
, name
))
3311 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3317 /* Before we invoke realpath, which can get expensive when many
3318 files are involved, do a quick comparison of the basenames. */
3319 if (! basenames_may_differ
3320 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3323 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3324 if (compare_filenames_for_search (this_real_name
, name
))
3326 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3332 if (real_path
!= NULL
)
3334 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3335 gdb_assert (IS_ABSOLUTE_PATH (name
));
3336 if (this_real_name
!= NULL
3337 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3339 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3351 /* Struct used to manage iterating over all CUs looking for a symbol. */
3353 struct dw2_symtab_iterator
3355 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3356 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3357 /* If set, only look for symbols that match that block. Valid values are
3358 GLOBAL_BLOCK and STATIC_BLOCK. */
3359 gdb::optional
<block_enum
> block_index
;
3360 /* The kind of symbol we're looking for. */
3362 /* The list of CUs from the index entry of the symbol,
3363 or NULL if not found. */
3365 /* The next element in VEC to look at. */
3367 /* The number of elements in VEC, or zero if there is no match. */
3369 /* Have we seen a global version of the symbol?
3370 If so we can ignore all further global instances.
3371 This is to work around gold/15646, inefficient gold-generated
3376 /* Initialize the index symtab iterator ITER. */
3379 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3380 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3381 gdb::optional
<block_enum
> block_index
,
3385 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3386 iter
->block_index
= block_index
;
3387 iter
->domain
= domain
;
3389 iter
->global_seen
= 0;
3391 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3393 /* index is NULL if OBJF_READNOW. */
3394 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3395 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3403 /* Return the next matching CU or NULL if there are no more. */
3405 static struct dwarf2_per_cu_data
*
3406 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3408 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3410 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3412 offset_type cu_index_and_attrs
=
3413 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3414 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3415 gdb_index_symbol_kind symbol_kind
=
3416 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3417 /* Only check the symbol attributes if they're present.
3418 Indices prior to version 7 don't record them,
3419 and indices >= 7 may elide them for certain symbols
3420 (gold does this). */
3422 (dwarf2_per_objfile
->index_table
->version
>= 7
3423 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3425 /* Don't crash on bad data. */
3426 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3427 + dwarf2_per_objfile
->all_type_units
.size ()))
3429 complaint (_(".gdb_index entry has bad CU index"
3431 objfile_name (dwarf2_per_objfile
->objfile
));
3435 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3437 /* Skip if already read in. */
3438 if (per_cu
->v
.quick
->compunit_symtab
)
3441 /* Check static vs global. */
3444 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3446 if (iter
->block_index
.has_value ())
3448 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3450 if (is_static
!= want_static
)
3454 /* Work around gold/15646. */
3455 if (!is_static
&& iter
->global_seen
)
3458 iter
->global_seen
= 1;
3461 /* Only check the symbol's kind if it has one. */
3464 switch (iter
->domain
)
3467 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3468 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3469 /* Some types are also in VAR_DOMAIN. */
3470 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3474 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3478 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3482 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3497 static struct compunit_symtab
*
3498 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3499 const char *name
, domain_enum domain
)
3501 struct compunit_symtab
*stab_best
= NULL
;
3502 struct dwarf2_per_objfile
*dwarf2_per_objfile
3503 = get_dwarf2_per_objfile (objfile
);
3505 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3507 struct dw2_symtab_iterator iter
;
3508 struct dwarf2_per_cu_data
*per_cu
;
3510 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3512 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3514 struct symbol
*sym
, *with_opaque
= NULL
;
3515 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3516 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3517 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3519 sym
= block_find_symbol (block
, name
, domain
,
3520 block_find_non_opaque_type_preferred
,
3523 /* Some caution must be observed with overloaded functions
3524 and methods, since the index will not contain any overload
3525 information (but NAME might contain it). */
3528 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3530 if (with_opaque
!= NULL
3531 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3534 /* Keep looking through other CUs. */
3541 dw2_print_stats (struct objfile
*objfile
)
3543 struct dwarf2_per_objfile
*dwarf2_per_objfile
3544 = get_dwarf2_per_objfile (objfile
);
3545 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3546 + dwarf2_per_objfile
->all_type_units
.size ());
3549 for (int i
= 0; i
< total
; ++i
)
3551 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3553 if (!per_cu
->v
.quick
->compunit_symtab
)
3556 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3557 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3560 /* This dumps minimal information about the index.
3561 It is called via "mt print objfiles".
3562 One use is to verify .gdb_index has been loaded by the
3563 gdb.dwarf2/gdb-index.exp testcase. */
3566 dw2_dump (struct objfile
*objfile
)
3568 struct dwarf2_per_objfile
*dwarf2_per_objfile
3569 = get_dwarf2_per_objfile (objfile
);
3571 gdb_assert (dwarf2_per_objfile
->using_index
);
3572 printf_filtered (".gdb_index:");
3573 if (dwarf2_per_objfile
->index_table
!= NULL
)
3575 printf_filtered (" version %d\n",
3576 dwarf2_per_objfile
->index_table
->version
);
3579 printf_filtered (" faked for \"readnow\"\n");
3580 printf_filtered ("\n");
3584 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3585 const char *func_name
)
3587 struct dwarf2_per_objfile
*dwarf2_per_objfile
3588 = get_dwarf2_per_objfile (objfile
);
3590 struct dw2_symtab_iterator iter
;
3591 struct dwarf2_per_cu_data
*per_cu
;
3593 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3595 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3596 dw2_instantiate_symtab (per_cu
, false);
3601 dw2_expand_all_symtabs (struct objfile
*objfile
)
3603 struct dwarf2_per_objfile
*dwarf2_per_objfile
3604 = get_dwarf2_per_objfile (objfile
);
3605 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3606 + dwarf2_per_objfile
->all_type_units
.size ());
3608 for (int i
= 0; i
< total_units
; ++i
)
3610 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3612 /* We don't want to directly expand a partial CU, because if we
3613 read it with the wrong language, then assertion failures can
3614 be triggered later on. See PR symtab/23010. So, tell
3615 dw2_instantiate_symtab to skip partial CUs -- any important
3616 partial CU will be read via DW_TAG_imported_unit anyway. */
3617 dw2_instantiate_symtab (per_cu
, true);
3622 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3623 const char *fullname
)
3625 struct dwarf2_per_objfile
*dwarf2_per_objfile
3626 = get_dwarf2_per_objfile (objfile
);
3628 /* We don't need to consider type units here.
3629 This is only called for examining code, e.g. expand_line_sal.
3630 There can be an order of magnitude (or more) more type units
3631 than comp units, and we avoid them if we can. */
3633 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3635 /* We only need to look at symtabs not already expanded. */
3636 if (per_cu
->v
.quick
->compunit_symtab
)
3639 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3640 if (file_data
== NULL
)
3643 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3645 const char *this_fullname
= file_data
->file_names
[j
];
3647 if (filename_cmp (this_fullname
, fullname
) == 0)
3649 dw2_instantiate_symtab (per_cu
, false);
3657 dw2_map_matching_symbols
3658 (struct objfile
*objfile
,
3659 const lookup_name_info
&name
, domain_enum domain
,
3661 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3662 symbol_compare_ftype
*ordered_compare
)
3664 /* Currently unimplemented; used for Ada. The function can be called if the
3665 current language is Ada for a non-Ada objfile using GNU index. As Ada
3666 does not look for non-Ada symbols this function should just return. */
3669 /* Starting from a search name, return the string that finds the upper
3670 bound of all strings that start with SEARCH_NAME in a sorted name
3671 list. Returns the empty string to indicate that the upper bound is
3672 the end of the list. */
3675 make_sort_after_prefix_name (const char *search_name
)
3677 /* When looking to complete "func", we find the upper bound of all
3678 symbols that start with "func" by looking for where we'd insert
3679 the closest string that would follow "func" in lexicographical
3680 order. Usually, that's "func"-with-last-character-incremented,
3681 i.e. "fund". Mind non-ASCII characters, though. Usually those
3682 will be UTF-8 multi-byte sequences, but we can't be certain.
3683 Especially mind the 0xff character, which is a valid character in
3684 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3685 rule out compilers allowing it in identifiers. Note that
3686 conveniently, strcmp/strcasecmp are specified to compare
3687 characters interpreted as unsigned char. So what we do is treat
3688 the whole string as a base 256 number composed of a sequence of
3689 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3690 to 0, and carries 1 to the following more-significant position.
3691 If the very first character in SEARCH_NAME ends up incremented
3692 and carries/overflows, then the upper bound is the end of the
3693 list. The string after the empty string is also the empty
3696 Some examples of this operation:
3698 SEARCH_NAME => "+1" RESULT
3702 "\xff" "a" "\xff" => "\xff" "b"
3707 Then, with these symbols for example:
3713 completing "func" looks for symbols between "func" and
3714 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3715 which finds "func" and "func1", but not "fund".
3719 funcÿ (Latin1 'ÿ' [0xff])
3723 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3724 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3728 ÿÿ (Latin1 'ÿ' [0xff])
3731 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3732 the end of the list.
3734 std::string after
= search_name
;
3735 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3737 if (!after
.empty ())
3738 after
.back () = (unsigned char) after
.back () + 1;
3742 /* See declaration. */
3744 std::pair
<std::vector
<name_component
>::const_iterator
,
3745 std::vector
<name_component
>::const_iterator
>
3746 mapped_index_base::find_name_components_bounds
3747 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3750 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3752 const char *lang_name
3753 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3755 /* Comparison function object for lower_bound that matches against a
3756 given symbol name. */
3757 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3760 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3761 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3762 return name_cmp (elem_name
, name
) < 0;
3765 /* Comparison function object for upper_bound that matches against a
3766 given symbol name. */
3767 auto lookup_compare_upper
= [&] (const char *name
,
3768 const name_component
&elem
)
3770 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3771 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3772 return name_cmp (name
, elem_name
) < 0;
3775 auto begin
= this->name_components
.begin ();
3776 auto end
= this->name_components
.end ();
3778 /* Find the lower bound. */
3781 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3784 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3787 /* Find the upper bound. */
3790 if (lookup_name_without_params
.completion_mode ())
3792 /* In completion mode, we want UPPER to point past all
3793 symbols names that have the same prefix. I.e., with
3794 these symbols, and completing "func":
3796 function << lower bound
3798 other_function << upper bound
3800 We find the upper bound by looking for the insertion
3801 point of "func"-with-last-character-incremented,
3803 std::string after
= make_sort_after_prefix_name (lang_name
);
3806 return std::lower_bound (lower
, end
, after
.c_str (),
3807 lookup_compare_lower
);
3810 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3813 return {lower
, upper
};
3816 /* See declaration. */
3819 mapped_index_base::build_name_components ()
3821 if (!this->name_components
.empty ())
3824 this->name_components_casing
= case_sensitivity
;
3826 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3828 /* The code below only knows how to break apart components of C++
3829 symbol names (and other languages that use '::' as
3830 namespace/module separator) and Ada symbol names. */
3831 auto count
= this->symbol_name_count ();
3832 for (offset_type idx
= 0; idx
< count
; idx
++)
3834 if (this->symbol_name_slot_invalid (idx
))
3837 const char *name
= this->symbol_name_at (idx
);
3839 /* Add each name component to the name component table. */
3840 unsigned int previous_len
= 0;
3842 if (strstr (name
, "::") != nullptr)
3844 for (unsigned int current_len
= cp_find_first_component (name
);
3845 name
[current_len
] != '\0';
3846 current_len
+= cp_find_first_component (name
+ current_len
))
3848 gdb_assert (name
[current_len
] == ':');
3849 this->name_components
.push_back ({previous_len
, idx
});
3850 /* Skip the '::'. */
3852 previous_len
= current_len
;
3857 /* Handle the Ada encoded (aka mangled) form here. */
3858 for (const char *iter
= strstr (name
, "__");
3860 iter
= strstr (iter
, "__"))
3862 this->name_components
.push_back ({previous_len
, idx
});
3864 previous_len
= iter
- name
;
3868 this->name_components
.push_back ({previous_len
, idx
});
3871 /* Sort name_components elements by name. */
3872 auto name_comp_compare
= [&] (const name_component
&left
,
3873 const name_component
&right
)
3875 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3876 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3878 const char *left_name
= left_qualified
+ left
.name_offset
;
3879 const char *right_name
= right_qualified
+ right
.name_offset
;
3881 return name_cmp (left_name
, right_name
) < 0;
3884 std::sort (this->name_components
.begin (),
3885 this->name_components
.end (),
3889 /* Helper for dw2_expand_symtabs_matching that works with a
3890 mapped_index_base instead of the containing objfile. This is split
3891 to a separate function in order to be able to unit test the
3892 name_components matching using a mock mapped_index_base. For each
3893 symbol name that matches, calls MATCH_CALLBACK, passing it the
3894 symbol's index in the mapped_index_base symbol table. */
3897 dw2_expand_symtabs_matching_symbol
3898 (mapped_index_base
&index
,
3899 const lookup_name_info
&lookup_name_in
,
3900 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3901 enum search_domain kind
,
3902 gdb::function_view
<bool (offset_type
)> match_callback
)
3904 lookup_name_info lookup_name_without_params
3905 = lookup_name_in
.make_ignore_params ();
3907 /* Build the symbol name component sorted vector, if we haven't
3909 index
.build_name_components ();
3911 /* The same symbol may appear more than once in the range though.
3912 E.g., if we're looking for symbols that complete "w", and we have
3913 a symbol named "w1::w2", we'll find the two name components for
3914 that same symbol in the range. To be sure we only call the
3915 callback once per symbol, we first collect the symbol name
3916 indexes that matched in a temporary vector and ignore
3918 std::vector
<offset_type
> matches
;
3920 struct name_and_matcher
3922 symbol_name_matcher_ftype
*matcher
;
3923 const std::string
&name
;
3925 bool operator== (const name_and_matcher
&other
) const
3927 return matcher
== other
.matcher
&& name
== other
.name
;
3931 /* A vector holding all the different symbol name matchers, for all
3933 std::vector
<name_and_matcher
> matchers
;
3935 for (int i
= 0; i
< nr_languages
; i
++)
3937 enum language lang_e
= (enum language
) i
;
3939 const language_defn
*lang
= language_def (lang_e
);
3940 symbol_name_matcher_ftype
*name_matcher
3941 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3943 name_and_matcher key
{
3945 lookup_name_without_params
.language_lookup_name (lang_e
)
3948 /* Don't insert the same comparison routine more than once.
3949 Note that we do this linear walk. This is not a problem in
3950 practice because the number of supported languages is
3952 if (std::find (matchers
.begin (), matchers
.end (), key
)
3955 matchers
.push_back (std::move (key
));
3958 = index
.find_name_components_bounds (lookup_name_without_params
,
3961 /* Now for each symbol name in range, check to see if we have a name
3962 match, and if so, call the MATCH_CALLBACK callback. */
3964 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3966 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3968 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3969 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3972 matches
.push_back (bounds
.first
->idx
);
3976 std::sort (matches
.begin (), matches
.end ());
3978 /* Finally call the callback, once per match. */
3980 for (offset_type idx
: matches
)
3984 if (!match_callback (idx
))
3990 /* Above we use a type wider than idx's for 'prev', since 0 and
3991 (offset_type)-1 are both possible values. */
3992 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3997 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3999 /* A mock .gdb_index/.debug_names-like name index table, enough to
4000 exercise dw2_expand_symtabs_matching_symbol, which works with the
4001 mapped_index_base interface. Builds an index from the symbol list
4002 passed as parameter to the constructor. */
4003 class mock_mapped_index
: public mapped_index_base
4006 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4007 : m_symbol_table (symbols
)
4010 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4012 /* Return the number of names in the symbol table. */
4013 size_t symbol_name_count () const override
4015 return m_symbol_table
.size ();
4018 /* Get the name of the symbol at IDX in the symbol table. */
4019 const char *symbol_name_at (offset_type idx
) const override
4021 return m_symbol_table
[idx
];
4025 gdb::array_view
<const char *> m_symbol_table
;
4028 /* Convenience function that converts a NULL pointer to a "<null>"
4029 string, to pass to print routines. */
4032 string_or_null (const char *str
)
4034 return str
!= NULL
? str
: "<null>";
4037 /* Check if a lookup_name_info built from
4038 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4039 index. EXPECTED_LIST is the list of expected matches, in expected
4040 matching order. If no match expected, then an empty list is
4041 specified. Returns true on success. On failure prints a warning
4042 indicating the file:line that failed, and returns false. */
4045 check_match (const char *file
, int line
,
4046 mock_mapped_index
&mock_index
,
4047 const char *name
, symbol_name_match_type match_type
,
4048 bool completion_mode
,
4049 std::initializer_list
<const char *> expected_list
)
4051 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4053 bool matched
= true;
4055 auto mismatch
= [&] (const char *expected_str
,
4058 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4059 "expected=\"%s\", got=\"%s\"\n"),
4061 (match_type
== symbol_name_match_type::FULL
4063 name
, string_or_null (expected_str
), string_or_null (got
));
4067 auto expected_it
= expected_list
.begin ();
4068 auto expected_end
= expected_list
.end ();
4070 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4072 [&] (offset_type idx
)
4074 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4075 const char *expected_str
4076 = expected_it
== expected_end
? NULL
: *expected_it
++;
4078 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4079 mismatch (expected_str
, matched_name
);
4083 const char *expected_str
4084 = expected_it
== expected_end
? NULL
: *expected_it
++;
4085 if (expected_str
!= NULL
)
4086 mismatch (expected_str
, NULL
);
4091 /* The symbols added to the mock mapped_index for testing (in
4093 static const char *test_symbols
[] = {
4102 "ns2::tmpl<int>::foo2",
4103 "(anonymous namespace)::A::B::C",
4105 /* These are used to check that the increment-last-char in the
4106 matching algorithm for completion doesn't match "t1_fund" when
4107 completing "t1_func". */
4113 /* A UTF-8 name with multi-byte sequences to make sure that
4114 cp-name-parser understands this as a single identifier ("função"
4115 is "function" in PT). */
4118 /* \377 (0xff) is Latin1 'ÿ'. */
4121 /* \377 (0xff) is Latin1 'ÿ'. */
4125 /* A name with all sorts of complications. Starts with "z" to make
4126 it easier for the completion tests below. */
4127 #define Z_SYM_NAME \
4128 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4129 "::tuple<(anonymous namespace)::ui*, " \
4130 "std::default_delete<(anonymous namespace)::ui>, void>"
4135 /* Returns true if the mapped_index_base::find_name_component_bounds
4136 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4137 in completion mode. */
4140 check_find_bounds_finds (mapped_index_base
&index
,
4141 const char *search_name
,
4142 gdb::array_view
<const char *> expected_syms
)
4144 lookup_name_info
lookup_name (search_name
,
4145 symbol_name_match_type::FULL
, true);
4147 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4150 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4151 if (distance
!= expected_syms
.size ())
4154 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4156 auto nc_elem
= bounds
.first
+ exp_elem
;
4157 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4158 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4165 /* Test the lower-level mapped_index::find_name_component_bounds
4169 test_mapped_index_find_name_component_bounds ()
4171 mock_mapped_index
mock_index (test_symbols
);
4173 mock_index
.build_name_components ();
4175 /* Test the lower-level mapped_index::find_name_component_bounds
4176 method in completion mode. */
4178 static const char *expected_syms
[] = {
4183 SELF_CHECK (check_find_bounds_finds (mock_index
,
4184 "t1_func", expected_syms
));
4187 /* Check that the increment-last-char in the name matching algorithm
4188 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4190 static const char *expected_syms1
[] = {
4194 SELF_CHECK (check_find_bounds_finds (mock_index
,
4195 "\377", expected_syms1
));
4197 static const char *expected_syms2
[] = {
4200 SELF_CHECK (check_find_bounds_finds (mock_index
,
4201 "\377\377", expected_syms2
));
4205 /* Test dw2_expand_symtabs_matching_symbol. */
4208 test_dw2_expand_symtabs_matching_symbol ()
4210 mock_mapped_index
mock_index (test_symbols
);
4212 /* We let all tests run until the end even if some fails, for debug
4214 bool any_mismatch
= false;
4216 /* Create the expected symbols list (an initializer_list). Needed
4217 because lists have commas, and we need to pass them to CHECK,
4218 which is a macro. */
4219 #define EXPECT(...) { __VA_ARGS__ }
4221 /* Wrapper for check_match that passes down the current
4222 __FILE__/__LINE__. */
4223 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4224 any_mismatch |= !check_match (__FILE__, __LINE__, \
4226 NAME, MATCH_TYPE, COMPLETION_MODE, \
4229 /* Identity checks. */
4230 for (const char *sym
: test_symbols
)
4232 /* Should be able to match all existing symbols. */
4233 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4236 /* Should be able to match all existing symbols with
4238 std::string with_params
= std::string (sym
) + "(int)";
4239 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4242 /* Should be able to match all existing symbols with
4243 parameters and qualifiers. */
4244 with_params
= std::string (sym
) + " ( int ) const";
4245 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4248 /* This should really find sym, but cp-name-parser.y doesn't
4249 know about lvalue/rvalue qualifiers yet. */
4250 with_params
= std::string (sym
) + " ( int ) &&";
4251 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4255 /* Check that the name matching algorithm for completion doesn't get
4256 confused with Latin1 'ÿ' / 0xff. */
4258 static const char str
[] = "\377";
4259 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4260 EXPECT ("\377", "\377\377123"));
4263 /* Check that the increment-last-char in the matching algorithm for
4264 completion doesn't match "t1_fund" when completing "t1_func". */
4266 static const char str
[] = "t1_func";
4267 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4268 EXPECT ("t1_func", "t1_func1"));
4271 /* Check that completion mode works at each prefix of the expected
4274 static const char str
[] = "function(int)";
4275 size_t len
= strlen (str
);
4278 for (size_t i
= 1; i
< len
; i
++)
4280 lookup
.assign (str
, i
);
4281 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4282 EXPECT ("function"));
4286 /* While "w" is a prefix of both components, the match function
4287 should still only be called once. */
4289 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4291 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4295 /* Same, with a "complicated" symbol. */
4297 static const char str
[] = Z_SYM_NAME
;
4298 size_t len
= strlen (str
);
4301 for (size_t i
= 1; i
< len
; i
++)
4303 lookup
.assign (str
, i
);
4304 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4305 EXPECT (Z_SYM_NAME
));
4309 /* In FULL mode, an incomplete symbol doesn't match. */
4311 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4315 /* A complete symbol with parameters matches any overload, since the
4316 index has no overload info. */
4318 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4319 EXPECT ("std::zfunction", "std::zfunction2"));
4320 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4321 EXPECT ("std::zfunction", "std::zfunction2"));
4322 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4323 EXPECT ("std::zfunction", "std::zfunction2"));
4326 /* Check that whitespace is ignored appropriately. A symbol with a
4327 template argument list. */
4329 static const char expected
[] = "ns::foo<int>";
4330 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4332 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4336 /* Check that whitespace is ignored appropriately. A symbol with a
4337 template argument list that includes a pointer. */
4339 static const char expected
[] = "ns::foo<char*>";
4340 /* Try both completion and non-completion modes. */
4341 static const bool completion_mode
[2] = {false, true};
4342 for (size_t i
= 0; i
< 2; i
++)
4344 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4345 completion_mode
[i
], EXPECT (expected
));
4346 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4347 completion_mode
[i
], EXPECT (expected
));
4349 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4350 completion_mode
[i
], EXPECT (expected
));
4351 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4352 completion_mode
[i
], EXPECT (expected
));
4357 /* Check method qualifiers are ignored. */
4358 static const char expected
[] = "ns::foo<char*>";
4359 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4360 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4361 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4362 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4363 CHECK_MATCH ("foo < char * > ( int ) const",
4364 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4365 CHECK_MATCH ("foo < char * > ( int ) &&",
4366 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4369 /* Test lookup names that don't match anything. */
4371 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4374 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4378 /* Some wild matching tests, exercising "(anonymous namespace)",
4379 which should not be confused with a parameter list. */
4381 static const char *syms
[] = {
4385 "A :: B :: C ( int )",
4390 for (const char *s
: syms
)
4392 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4393 EXPECT ("(anonymous namespace)::A::B::C"));
4398 static const char expected
[] = "ns2::tmpl<int>::foo2";
4399 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4401 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4405 SELF_CHECK (!any_mismatch
);
4414 test_mapped_index_find_name_component_bounds ();
4415 test_dw2_expand_symtabs_matching_symbol ();
4418 }} // namespace selftests::dw2_expand_symtabs_matching
4420 #endif /* GDB_SELF_TEST */
4422 /* If FILE_MATCHER is NULL or if PER_CU has
4423 dwarf2_per_cu_quick_data::MARK set (see
4424 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4425 EXPANSION_NOTIFY on it. */
4428 dw2_expand_symtabs_matching_one
4429 (struct dwarf2_per_cu_data
*per_cu
,
4430 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4431 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4433 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4435 bool symtab_was_null
4436 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4438 dw2_instantiate_symtab (per_cu
, false);
4440 if (expansion_notify
!= NULL
4442 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4443 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4447 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4448 matched, to expand corresponding CUs that were marked. IDX is the
4449 index of the symbol name that matched. */
4452 dw2_expand_marked_cus
4453 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4454 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4455 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4458 offset_type
*vec
, vec_len
, vec_idx
;
4459 bool global_seen
= false;
4460 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4462 vec
= (offset_type
*) (index
.constant_pool
4463 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4464 vec_len
= MAYBE_SWAP (vec
[0]);
4465 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4467 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4468 /* This value is only valid for index versions >= 7. */
4469 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4470 gdb_index_symbol_kind symbol_kind
=
4471 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4472 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4473 /* Only check the symbol attributes if they're present.
4474 Indices prior to version 7 don't record them,
4475 and indices >= 7 may elide them for certain symbols
4476 (gold does this). */
4479 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4481 /* Work around gold/15646. */
4484 if (!is_static
&& global_seen
)
4490 /* Only check the symbol's kind if it has one. */
4495 case VARIABLES_DOMAIN
:
4496 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4499 case FUNCTIONS_DOMAIN
:
4500 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4504 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4507 case MODULES_DOMAIN
:
4508 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4516 /* Don't crash on bad data. */
4517 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4518 + dwarf2_per_objfile
->all_type_units
.size ()))
4520 complaint (_(".gdb_index entry has bad CU index"
4522 objfile_name (dwarf2_per_objfile
->objfile
));
4526 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4527 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4532 /* If FILE_MATCHER is non-NULL, set all the
4533 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4534 that match FILE_MATCHER. */
4537 dw_expand_symtabs_matching_file_matcher
4538 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4539 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4541 if (file_matcher
== NULL
)
4544 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4546 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4548 NULL
, xcalloc
, xfree
));
4549 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4551 NULL
, xcalloc
, xfree
));
4553 /* The rule is CUs specify all the files, including those used by
4554 any TU, so there's no need to scan TUs here. */
4556 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4560 per_cu
->v
.quick
->mark
= 0;
4562 /* We only need to look at symtabs not already expanded. */
4563 if (per_cu
->v
.quick
->compunit_symtab
)
4566 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4567 if (file_data
== NULL
)
4570 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4572 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4574 per_cu
->v
.quick
->mark
= 1;
4578 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4580 const char *this_real_name
;
4582 if (file_matcher (file_data
->file_names
[j
], false))
4584 per_cu
->v
.quick
->mark
= 1;
4588 /* Before we invoke realpath, which can get expensive when many
4589 files are involved, do a quick comparison of the basenames. */
4590 if (!basenames_may_differ
4591 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4595 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4596 if (file_matcher (this_real_name
, false))
4598 per_cu
->v
.quick
->mark
= 1;
4603 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4604 ? visited_found
.get ()
4605 : visited_not_found
.get (),
4612 dw2_expand_symtabs_matching
4613 (struct objfile
*objfile
,
4614 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4615 const lookup_name_info
&lookup_name
,
4616 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4617 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4618 enum search_domain kind
)
4620 struct dwarf2_per_objfile
*dwarf2_per_objfile
4621 = get_dwarf2_per_objfile (objfile
);
4623 /* index_table is NULL if OBJF_READNOW. */
4624 if (!dwarf2_per_objfile
->index_table
)
4627 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4629 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4631 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4633 kind
, [&] (offset_type idx
)
4635 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4636 expansion_notify
, kind
);
4641 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4644 static struct compunit_symtab
*
4645 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4650 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4651 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4654 if (cust
->includes
== NULL
)
4657 for (i
= 0; cust
->includes
[i
]; ++i
)
4659 struct compunit_symtab
*s
= cust
->includes
[i
];
4661 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4669 static struct compunit_symtab
*
4670 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4671 struct bound_minimal_symbol msymbol
,
4673 struct obj_section
*section
,
4676 struct dwarf2_per_cu_data
*data
;
4677 struct compunit_symtab
*result
;
4679 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4682 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4683 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4684 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4688 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4689 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4690 paddress (get_objfile_arch (objfile
), pc
));
4693 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4696 gdb_assert (result
!= NULL
);
4701 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4702 void *data
, int need_fullname
)
4704 struct dwarf2_per_objfile
*dwarf2_per_objfile
4705 = get_dwarf2_per_objfile (objfile
);
4707 if (!dwarf2_per_objfile
->filenames_cache
)
4709 dwarf2_per_objfile
->filenames_cache
.emplace ();
4711 htab_up
visited (htab_create_alloc (10,
4712 htab_hash_pointer
, htab_eq_pointer
,
4713 NULL
, xcalloc
, xfree
));
4715 /* The rule is CUs specify all the files, including those used
4716 by any TU, so there's no need to scan TUs here. We can
4717 ignore file names coming from already-expanded CUs. */
4719 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4721 if (per_cu
->v
.quick
->compunit_symtab
)
4723 void **slot
= htab_find_slot (visited
.get (),
4724 per_cu
->v
.quick
->file_names
,
4727 *slot
= per_cu
->v
.quick
->file_names
;
4731 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4733 /* We only need to look at symtabs not already expanded. */
4734 if (per_cu
->v
.quick
->compunit_symtab
)
4737 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4738 if (file_data
== NULL
)
4741 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4744 /* Already visited. */
4749 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4751 const char *filename
= file_data
->file_names
[j
];
4752 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4757 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4759 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4762 this_real_name
= gdb_realpath (filename
);
4763 (*fun
) (filename
, this_real_name
.get (), data
);
4768 dw2_has_symbols (struct objfile
*objfile
)
4773 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4776 dw2_find_last_source_symtab
,
4777 dw2_forget_cached_source_info
,
4778 dw2_map_symtabs_matching_filename
,
4782 dw2_expand_symtabs_for_function
,
4783 dw2_expand_all_symtabs
,
4784 dw2_expand_symtabs_with_fullname
,
4785 dw2_map_matching_symbols
,
4786 dw2_expand_symtabs_matching
,
4787 dw2_find_pc_sect_compunit_symtab
,
4789 dw2_map_symbol_filenames
4792 /* DWARF-5 debug_names reader. */
4794 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4795 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4797 /* A helper function that reads the .debug_names section in SECTION
4798 and fills in MAP. FILENAME is the name of the file containing the
4799 section; it is used for error reporting.
4801 Returns true if all went well, false otherwise. */
4804 read_debug_names_from_section (struct objfile
*objfile
,
4805 const char *filename
,
4806 struct dwarf2_section_info
*section
,
4807 mapped_debug_names
&map
)
4809 if (section
->empty ())
4812 /* Older elfutils strip versions could keep the section in the main
4813 executable while splitting it for the separate debug info file. */
4814 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4817 section
->read (objfile
);
4819 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4821 const gdb_byte
*addr
= section
->buffer
;
4823 bfd
*const abfd
= section
->get_bfd_owner ();
4825 unsigned int bytes_read
;
4826 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4829 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4830 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4831 if (bytes_read
+ length
!= section
->size
)
4833 /* There may be multiple per-CU indices. */
4834 warning (_("Section .debug_names in %s length %s does not match "
4835 "section length %s, ignoring .debug_names."),
4836 filename
, plongest (bytes_read
+ length
),
4837 pulongest (section
->size
));
4841 /* The version number. */
4842 uint16_t version
= read_2_bytes (abfd
, addr
);
4846 warning (_("Section .debug_names in %s has unsupported version %d, "
4847 "ignoring .debug_names."),
4853 uint16_t padding
= read_2_bytes (abfd
, addr
);
4857 warning (_("Section .debug_names in %s has unsupported padding %d, "
4858 "ignoring .debug_names."),
4863 /* comp_unit_count - The number of CUs in the CU list. */
4864 map
.cu_count
= read_4_bytes (abfd
, addr
);
4867 /* local_type_unit_count - The number of TUs in the local TU
4869 map
.tu_count
= read_4_bytes (abfd
, addr
);
4872 /* foreign_type_unit_count - The number of TUs in the foreign TU
4874 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4876 if (foreign_tu_count
!= 0)
4878 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4879 "ignoring .debug_names."),
4880 filename
, static_cast<unsigned long> (foreign_tu_count
));
4884 /* bucket_count - The number of hash buckets in the hash lookup
4886 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4889 /* name_count - The number of unique names in the index. */
4890 map
.name_count
= read_4_bytes (abfd
, addr
);
4893 /* abbrev_table_size - The size in bytes of the abbreviations
4895 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4898 /* augmentation_string_size - The size in bytes of the augmentation
4899 string. This value is rounded up to a multiple of 4. */
4900 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4902 map
.augmentation_is_gdb
= ((augmentation_string_size
4903 == sizeof (dwarf5_augmentation
))
4904 && memcmp (addr
, dwarf5_augmentation
,
4905 sizeof (dwarf5_augmentation
)) == 0);
4906 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4907 addr
+= augmentation_string_size
;
4910 map
.cu_table_reordered
= addr
;
4911 addr
+= map
.cu_count
* map
.offset_size
;
4913 /* List of Local TUs */
4914 map
.tu_table_reordered
= addr
;
4915 addr
+= map
.tu_count
* map
.offset_size
;
4917 /* Hash Lookup Table */
4918 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4919 addr
+= map
.bucket_count
* 4;
4920 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4921 addr
+= map
.name_count
* 4;
4924 map
.name_table_string_offs_reordered
= addr
;
4925 addr
+= map
.name_count
* map
.offset_size
;
4926 map
.name_table_entry_offs_reordered
= addr
;
4927 addr
+= map
.name_count
* map
.offset_size
;
4929 const gdb_byte
*abbrev_table_start
= addr
;
4932 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4937 const auto insertpair
4938 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4939 if (!insertpair
.second
)
4941 warning (_("Section .debug_names in %s has duplicate index %s, "
4942 "ignoring .debug_names."),
4943 filename
, pulongest (index_num
));
4946 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4947 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4952 mapped_debug_names::index_val::attr attr
;
4953 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4955 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4957 if (attr
.form
== DW_FORM_implicit_const
)
4959 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4963 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4965 indexval
.attr_vec
.push_back (std::move (attr
));
4968 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4970 warning (_("Section .debug_names in %s has abbreviation_table "
4971 "of size %s vs. written as %u, ignoring .debug_names."),
4972 filename
, plongest (addr
- abbrev_table_start
),
4976 map
.entry_pool
= addr
;
4981 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4985 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4986 const mapped_debug_names
&map
,
4987 dwarf2_section_info
§ion
,
4990 sect_offset sect_off_prev
;
4991 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4993 sect_offset sect_off_next
;
4994 if (i
< map
.cu_count
)
4997 = (sect_offset
) (extract_unsigned_integer
4998 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5000 map
.dwarf5_byte_order
));
5003 sect_off_next
= (sect_offset
) section
.size
;
5006 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5007 dwarf2_per_cu_data
*per_cu
5008 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5009 sect_off_prev
, length
);
5010 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5012 sect_off_prev
= sect_off_next
;
5016 /* Read the CU list from the mapped index, and use it to create all
5017 the CU objects for this dwarf2_per_objfile. */
5020 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5021 const mapped_debug_names
&map
,
5022 const mapped_debug_names
&dwz_map
)
5024 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5025 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5027 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5028 dwarf2_per_objfile
->info
,
5029 false /* is_dwz */);
5031 if (dwz_map
.cu_count
== 0)
5034 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5035 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5039 /* Read .debug_names. If everything went ok, initialize the "quick"
5040 elements of all the CUs and return true. Otherwise, return false. */
5043 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5045 std::unique_ptr
<mapped_debug_names
> map
5046 (new mapped_debug_names (dwarf2_per_objfile
));
5047 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5048 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5050 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5051 &dwarf2_per_objfile
->debug_names
,
5055 /* Don't use the index if it's empty. */
5056 if (map
->name_count
== 0)
5059 /* If there is a .dwz file, read it so we can get its CU list as
5061 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5064 if (!read_debug_names_from_section (objfile
,
5065 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5066 &dwz
->debug_names
, dwz_map
))
5068 warning (_("could not read '.debug_names' section from %s; skipping"),
5069 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5074 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5076 if (map
->tu_count
!= 0)
5078 /* We can only handle a single .debug_types when we have an
5080 if (dwarf2_per_objfile
->types
.size () != 1)
5083 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5085 create_signatured_type_table_from_debug_names
5086 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5089 create_addrmap_from_aranges (dwarf2_per_objfile
,
5090 &dwarf2_per_objfile
->debug_aranges
);
5092 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5093 dwarf2_per_objfile
->using_index
= 1;
5094 dwarf2_per_objfile
->quick_file_names_table
=
5095 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5100 /* Type used to manage iterating over all CUs looking for a symbol for
5103 class dw2_debug_names_iterator
5106 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5107 gdb::optional
<block_enum
> block_index
,
5110 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5111 m_addr (find_vec_in_debug_names (map
, name
))
5114 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5115 search_domain search
, uint32_t namei
)
5118 m_addr (find_vec_in_debug_names (map
, namei
))
5121 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5122 block_enum block_index
, domain_enum domain
,
5124 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5125 m_addr (find_vec_in_debug_names (map
, namei
))
5128 /* Return the next matching CU or NULL if there are no more. */
5129 dwarf2_per_cu_data
*next ();
5132 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5134 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5137 /* The internalized form of .debug_names. */
5138 const mapped_debug_names
&m_map
;
5140 /* If set, only look for symbols that match that block. Valid values are
5141 GLOBAL_BLOCK and STATIC_BLOCK. */
5142 const gdb::optional
<block_enum
> m_block_index
;
5144 /* The kind of symbol we're looking for. */
5145 const domain_enum m_domain
= UNDEF_DOMAIN
;
5146 const search_domain m_search
= ALL_DOMAIN
;
5148 /* The list of CUs from the index entry of the symbol, or NULL if
5150 const gdb_byte
*m_addr
;
5154 mapped_debug_names::namei_to_name (uint32_t namei
) const
5156 const ULONGEST namei_string_offs
5157 = extract_unsigned_integer ((name_table_string_offs_reordered
5158 + namei
* offset_size
),
5161 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5165 /* Find a slot in .debug_names for the object named NAME. If NAME is
5166 found, return pointer to its pool data. If NAME cannot be found,
5170 dw2_debug_names_iterator::find_vec_in_debug_names
5171 (const mapped_debug_names
&map
, const char *name
)
5173 int (*cmp
) (const char *, const char *);
5175 gdb::unique_xmalloc_ptr
<char> without_params
;
5176 if (current_language
->la_language
== language_cplus
5177 || current_language
->la_language
== language_fortran
5178 || current_language
->la_language
== language_d
)
5180 /* NAME is already canonical. Drop any qualifiers as
5181 .debug_names does not contain any. */
5183 if (strchr (name
, '(') != NULL
)
5185 without_params
= cp_remove_params (name
);
5186 if (without_params
!= NULL
)
5187 name
= without_params
.get ();
5191 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5193 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5195 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5196 (map
.bucket_table_reordered
5197 + (full_hash
% map
.bucket_count
)), 4,
5198 map
.dwarf5_byte_order
);
5202 if (namei
>= map
.name_count
)
5204 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5206 namei
, map
.name_count
,
5207 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5213 const uint32_t namei_full_hash
5214 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5215 (map
.hash_table_reordered
+ namei
), 4,
5216 map
.dwarf5_byte_order
);
5217 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5220 if (full_hash
== namei_full_hash
)
5222 const char *const namei_string
= map
.namei_to_name (namei
);
5224 #if 0 /* An expensive sanity check. */
5225 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5227 complaint (_("Wrong .debug_names hash for string at index %u "
5229 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5234 if (cmp (namei_string
, name
) == 0)
5236 const ULONGEST namei_entry_offs
5237 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5238 + namei
* map
.offset_size
),
5239 map
.offset_size
, map
.dwarf5_byte_order
);
5240 return map
.entry_pool
+ namei_entry_offs
;
5245 if (namei
>= map
.name_count
)
5251 dw2_debug_names_iterator::find_vec_in_debug_names
5252 (const mapped_debug_names
&map
, uint32_t namei
)
5254 if (namei
>= map
.name_count
)
5256 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5258 namei
, map
.name_count
,
5259 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5263 const ULONGEST namei_entry_offs
5264 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5265 + namei
* map
.offset_size
),
5266 map
.offset_size
, map
.dwarf5_byte_order
);
5267 return map
.entry_pool
+ namei_entry_offs
;
5270 /* See dw2_debug_names_iterator. */
5272 dwarf2_per_cu_data
*
5273 dw2_debug_names_iterator::next ()
5278 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5279 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5280 bfd
*const abfd
= objfile
->obfd
;
5284 unsigned int bytes_read
;
5285 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5286 m_addr
+= bytes_read
;
5290 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5291 if (indexval_it
== m_map
.abbrev_map
.cend ())
5293 complaint (_("Wrong .debug_names undefined abbrev code %s "
5295 pulongest (abbrev
), objfile_name (objfile
));
5298 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5299 enum class symbol_linkage
{
5303 } symbol_linkage_
= symbol_linkage::unknown
;
5304 dwarf2_per_cu_data
*per_cu
= NULL
;
5305 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5310 case DW_FORM_implicit_const
:
5311 ull
= attr
.implicit_const
;
5313 case DW_FORM_flag_present
:
5317 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5318 m_addr
+= bytes_read
;
5321 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5322 dwarf_form_name (attr
.form
),
5323 objfile_name (objfile
));
5326 switch (attr
.dw_idx
)
5328 case DW_IDX_compile_unit
:
5329 /* Don't crash on bad data. */
5330 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5332 complaint (_(".debug_names entry has bad CU index %s"
5335 objfile_name (dwarf2_per_objfile
->objfile
));
5338 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5340 case DW_IDX_type_unit
:
5341 /* Don't crash on bad data. */
5342 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5344 complaint (_(".debug_names entry has bad TU index %s"
5347 objfile_name (dwarf2_per_objfile
->objfile
));
5350 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5352 case DW_IDX_GNU_internal
:
5353 if (!m_map
.augmentation_is_gdb
)
5355 symbol_linkage_
= symbol_linkage::static_
;
5357 case DW_IDX_GNU_external
:
5358 if (!m_map
.augmentation_is_gdb
)
5360 symbol_linkage_
= symbol_linkage::extern_
;
5365 /* Skip if already read in. */
5366 if (per_cu
->v
.quick
->compunit_symtab
)
5369 /* Check static vs global. */
5370 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5372 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5373 const bool symbol_is_static
=
5374 symbol_linkage_
== symbol_linkage::static_
;
5375 if (want_static
!= symbol_is_static
)
5379 /* Match dw2_symtab_iter_next, symbol_kind
5380 and debug_names::psymbol_tag. */
5384 switch (indexval
.dwarf_tag
)
5386 case DW_TAG_variable
:
5387 case DW_TAG_subprogram
:
5388 /* Some types are also in VAR_DOMAIN. */
5389 case DW_TAG_typedef
:
5390 case DW_TAG_structure_type
:
5397 switch (indexval
.dwarf_tag
)
5399 case DW_TAG_typedef
:
5400 case DW_TAG_structure_type
:
5407 switch (indexval
.dwarf_tag
)
5410 case DW_TAG_variable
:
5417 switch (indexval
.dwarf_tag
)
5429 /* Match dw2_expand_symtabs_matching, symbol_kind and
5430 debug_names::psymbol_tag. */
5433 case VARIABLES_DOMAIN
:
5434 switch (indexval
.dwarf_tag
)
5436 case DW_TAG_variable
:
5442 case FUNCTIONS_DOMAIN
:
5443 switch (indexval
.dwarf_tag
)
5445 case DW_TAG_subprogram
:
5452 switch (indexval
.dwarf_tag
)
5454 case DW_TAG_typedef
:
5455 case DW_TAG_structure_type
:
5461 case MODULES_DOMAIN
:
5462 switch (indexval
.dwarf_tag
)
5476 static struct compunit_symtab
*
5477 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5478 const char *name
, domain_enum domain
)
5480 struct dwarf2_per_objfile
*dwarf2_per_objfile
5481 = get_dwarf2_per_objfile (objfile
);
5483 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5486 /* index is NULL if OBJF_READNOW. */
5489 const auto &map
= *mapp
;
5491 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5493 struct compunit_symtab
*stab_best
= NULL
;
5494 struct dwarf2_per_cu_data
*per_cu
;
5495 while ((per_cu
= iter
.next ()) != NULL
)
5497 struct symbol
*sym
, *with_opaque
= NULL
;
5498 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5499 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5500 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5502 sym
= block_find_symbol (block
, name
, domain
,
5503 block_find_non_opaque_type_preferred
,
5506 /* Some caution must be observed with overloaded functions and
5507 methods, since the index will not contain any overload
5508 information (but NAME might contain it). */
5511 && strcmp_iw (sym
->search_name (), name
) == 0)
5513 if (with_opaque
!= NULL
5514 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5517 /* Keep looking through other CUs. */
5523 /* This dumps minimal information about .debug_names. It is called
5524 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5525 uses this to verify that .debug_names has been loaded. */
5528 dw2_debug_names_dump (struct objfile
*objfile
)
5530 struct dwarf2_per_objfile
*dwarf2_per_objfile
5531 = get_dwarf2_per_objfile (objfile
);
5533 gdb_assert (dwarf2_per_objfile
->using_index
);
5534 printf_filtered (".debug_names:");
5535 if (dwarf2_per_objfile
->debug_names_table
)
5536 printf_filtered (" exists\n");
5538 printf_filtered (" faked for \"readnow\"\n");
5539 printf_filtered ("\n");
5543 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5544 const char *func_name
)
5546 struct dwarf2_per_objfile
*dwarf2_per_objfile
5547 = get_dwarf2_per_objfile (objfile
);
5549 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5550 if (dwarf2_per_objfile
->debug_names_table
)
5552 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5554 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5556 struct dwarf2_per_cu_data
*per_cu
;
5557 while ((per_cu
= iter
.next ()) != NULL
)
5558 dw2_instantiate_symtab (per_cu
, false);
5563 dw2_debug_names_map_matching_symbols
5564 (struct objfile
*objfile
,
5565 const lookup_name_info
&name
, domain_enum domain
,
5567 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5568 symbol_compare_ftype
*ordered_compare
)
5570 struct dwarf2_per_objfile
*dwarf2_per_objfile
5571 = get_dwarf2_per_objfile (objfile
);
5573 /* debug_names_table is NULL if OBJF_READNOW. */
5574 if (!dwarf2_per_objfile
->debug_names_table
)
5577 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5578 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5580 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5581 auto matcher
= [&] (const char *symname
)
5583 if (ordered_compare
== nullptr)
5585 return ordered_compare (symname
, match_name
) == 0;
5588 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5589 [&] (offset_type namei
)
5591 /* The name was matched, now expand corresponding CUs that were
5593 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5595 struct dwarf2_per_cu_data
*per_cu
;
5596 while ((per_cu
= iter
.next ()) != NULL
)
5597 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5601 /* It's a shame we couldn't do this inside the
5602 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5603 that have already been expanded. Instead, this loop matches what
5604 the psymtab code does. */
5605 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5607 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5608 if (cust
!= nullptr)
5610 const struct block
*block
5611 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5612 if (!iterate_over_symbols_terminated (block
, name
,
5620 dw2_debug_names_expand_symtabs_matching
5621 (struct objfile
*objfile
,
5622 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5623 const lookup_name_info
&lookup_name
,
5624 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5625 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5626 enum search_domain kind
)
5628 struct dwarf2_per_objfile
*dwarf2_per_objfile
5629 = get_dwarf2_per_objfile (objfile
);
5631 /* debug_names_table is NULL if OBJF_READNOW. */
5632 if (!dwarf2_per_objfile
->debug_names_table
)
5635 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5637 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5639 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5641 kind
, [&] (offset_type namei
)
5643 /* The name was matched, now expand corresponding CUs that were
5645 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5647 struct dwarf2_per_cu_data
*per_cu
;
5648 while ((per_cu
= iter
.next ()) != NULL
)
5649 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5655 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5658 dw2_find_last_source_symtab
,
5659 dw2_forget_cached_source_info
,
5660 dw2_map_symtabs_matching_filename
,
5661 dw2_debug_names_lookup_symbol
,
5663 dw2_debug_names_dump
,
5664 dw2_debug_names_expand_symtabs_for_function
,
5665 dw2_expand_all_symtabs
,
5666 dw2_expand_symtabs_with_fullname
,
5667 dw2_debug_names_map_matching_symbols
,
5668 dw2_debug_names_expand_symtabs_matching
,
5669 dw2_find_pc_sect_compunit_symtab
,
5671 dw2_map_symbol_filenames
5674 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5675 to either a dwarf2_per_objfile or dwz_file object. */
5677 template <typename T
>
5678 static gdb::array_view
<const gdb_byte
>
5679 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5681 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5683 if (section
->empty ())
5686 /* Older elfutils strip versions could keep the section in the main
5687 executable while splitting it for the separate debug info file. */
5688 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5691 section
->read (obj
);
5693 /* dwarf2_section_info::size is a bfd_size_type, while
5694 gdb::array_view works with size_t. On 32-bit hosts, with
5695 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5696 is 32-bit. So we need an explicit narrowing conversion here.
5697 This is fine, because it's impossible to allocate or mmap an
5698 array/buffer larger than what size_t can represent. */
5699 return gdb::make_array_view (section
->buffer
, section
->size
);
5702 /* Lookup the index cache for the contents of the index associated to
5705 static gdb::array_view
<const gdb_byte
>
5706 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5708 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5709 if (build_id
== nullptr)
5712 return global_index_cache
.lookup_gdb_index (build_id
,
5713 &dwarf2_obj
->index_cache_res
);
5716 /* Same as the above, but for DWZ. */
5718 static gdb::array_view
<const gdb_byte
>
5719 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5721 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5722 if (build_id
== nullptr)
5725 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5728 /* See symfile.h. */
5731 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5733 struct dwarf2_per_objfile
*dwarf2_per_objfile
5734 = get_dwarf2_per_objfile (objfile
);
5736 /* If we're about to read full symbols, don't bother with the
5737 indices. In this case we also don't care if some other debug
5738 format is making psymtabs, because they are all about to be
5740 if ((objfile
->flags
& OBJF_READNOW
))
5742 dwarf2_per_objfile
->using_index
= 1;
5743 create_all_comp_units (dwarf2_per_objfile
);
5744 create_all_type_units (dwarf2_per_objfile
);
5745 dwarf2_per_objfile
->quick_file_names_table
5746 = create_quick_file_names_table
5747 (dwarf2_per_objfile
->all_comp_units
.size ());
5749 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5750 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5752 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5754 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5755 struct dwarf2_per_cu_quick_data
);
5758 /* Return 1 so that gdb sees the "quick" functions. However,
5759 these functions will be no-ops because we will have expanded
5761 *index_kind
= dw_index_kind::GDB_INDEX
;
5765 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5767 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5771 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5772 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5773 get_gdb_index_contents_from_section
<dwz_file
>))
5775 *index_kind
= dw_index_kind::GDB_INDEX
;
5779 /* ... otherwise, try to find the index in the index cache. */
5780 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5781 get_gdb_index_contents_from_cache
,
5782 get_gdb_index_contents_from_cache_dwz
))
5784 global_index_cache
.hit ();
5785 *index_kind
= dw_index_kind::GDB_INDEX
;
5789 global_index_cache
.miss ();
5795 /* Build a partial symbol table. */
5798 dwarf2_build_psymtabs (struct objfile
*objfile
)
5800 struct dwarf2_per_objfile
*dwarf2_per_objfile
5801 = get_dwarf2_per_objfile (objfile
);
5803 init_psymbol_list (objfile
, 1024);
5807 /* This isn't really ideal: all the data we allocate on the
5808 objfile's obstack is still uselessly kept around. However,
5809 freeing it seems unsafe. */
5810 psymtab_discarder
psymtabs (objfile
);
5811 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5814 /* (maybe) store an index in the cache. */
5815 global_index_cache
.store (dwarf2_per_objfile
);
5817 catch (const gdb_exception_error
&except
)
5819 exception_print (gdb_stderr
, except
);
5823 /* Find the base address of the compilation unit for range lists and
5824 location lists. It will normally be specified by DW_AT_low_pc.
5825 In DWARF-3 draft 4, the base address could be overridden by
5826 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5827 compilation units with discontinuous ranges. */
5830 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5832 struct attribute
*attr
;
5835 cu
->base_address
= 0;
5837 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5838 if (attr
!= nullptr)
5840 cu
->base_address
= attr
->value_as_address ();
5845 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5846 if (attr
!= nullptr)
5848 cu
->base_address
= attr
->value_as_address ();
5854 /* Helper function that returns the proper abbrev section for
5857 static struct dwarf2_section_info
*
5858 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5860 struct dwarf2_section_info
*abbrev
;
5861 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5863 if (this_cu
->is_dwz
)
5864 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5866 abbrev
= &dwarf2_per_objfile
->abbrev
;
5871 /* Fetch the abbreviation table offset from a comp or type unit header. */
5874 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5875 struct dwarf2_section_info
*section
,
5876 sect_offset sect_off
)
5878 bfd
*abfd
= section
->get_bfd_owner ();
5879 const gdb_byte
*info_ptr
;
5880 unsigned int initial_length_size
, offset_size
;
5883 section
->read (dwarf2_per_objfile
->objfile
);
5884 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5885 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5886 offset_size
= initial_length_size
== 4 ? 4 : 8;
5887 info_ptr
+= initial_length_size
;
5889 version
= read_2_bytes (abfd
, info_ptr
);
5893 /* Skip unit type and address size. */
5897 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5900 /* A partial symtab that is used only for include files. */
5901 struct dwarf2_include_psymtab
: public partial_symtab
5903 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5904 : partial_symtab (filename
, objfile
)
5908 void read_symtab (struct objfile
*objfile
) override
5910 expand_psymtab (objfile
);
5913 void expand_psymtab (struct objfile
*objfile
) override
5917 /* It's an include file, no symbols to read for it.
5918 Everything is in the parent symtab. */
5919 read_dependencies (objfile
);
5923 bool readin_p () const override
5928 struct compunit_symtab
*get_compunit_symtab () const override
5935 bool m_readin
= false;
5938 /* Allocate a new partial symtab for file named NAME and mark this new
5939 partial symtab as being an include of PST. */
5942 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5943 struct objfile
*objfile
)
5945 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5947 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5949 /* It shares objfile->objfile_obstack. */
5950 subpst
->dirname
= pst
->dirname
;
5953 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5954 subpst
->dependencies
[0] = pst
;
5955 subpst
->number_of_dependencies
= 1;
5958 /* Read the Line Number Program data and extract the list of files
5959 included by the source file represented by PST. Build an include
5960 partial symtab for each of these included files. */
5963 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5964 struct die_info
*die
,
5965 dwarf2_psymtab
*pst
)
5968 struct attribute
*attr
;
5970 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5971 if (attr
!= nullptr)
5972 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5974 return; /* No linetable, so no includes. */
5976 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5977 that we pass in the raw text_low here; that is ok because we're
5978 only decoding the line table to make include partial symtabs, and
5979 so the addresses aren't really used. */
5980 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5981 pst
->raw_text_low (), 1);
5985 hash_signatured_type (const void *item
)
5987 const struct signatured_type
*sig_type
5988 = (const struct signatured_type
*) item
;
5990 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5991 return sig_type
->signature
;
5995 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5997 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5998 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6000 return lhs
->signature
== rhs
->signature
;
6003 /* Allocate a hash table for signatured types. */
6006 allocate_signatured_type_table ()
6008 return htab_up (htab_create_alloc (41,
6009 hash_signatured_type
,
6011 NULL
, xcalloc
, xfree
));
6014 /* A helper function to add a signatured type CU to a table. */
6017 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6019 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6020 std::vector
<signatured_type
*> *all_type_units
6021 = (std::vector
<signatured_type
*> *) datum
;
6023 all_type_units
->push_back (sigt
);
6028 /* A helper for create_debug_types_hash_table. Read types from SECTION
6029 and fill them into TYPES_HTAB. It will process only type units,
6030 therefore DW_UT_type. */
6033 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6034 struct dwo_file
*dwo_file
,
6035 dwarf2_section_info
*section
, htab_up
&types_htab
,
6036 rcuh_kind section_kind
)
6038 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6039 struct dwarf2_section_info
*abbrev_section
;
6041 const gdb_byte
*info_ptr
, *end_ptr
;
6043 abbrev_section
= (dwo_file
!= NULL
6044 ? &dwo_file
->sections
.abbrev
6045 : &dwarf2_per_objfile
->abbrev
);
6047 if (dwarf_read_debug
)
6048 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6049 section
->get_name (),
6050 abbrev_section
->get_file_name ());
6052 section
->read (objfile
);
6053 info_ptr
= section
->buffer
;
6055 if (info_ptr
== NULL
)
6058 /* We can't set abfd until now because the section may be empty or
6059 not present, in which case the bfd is unknown. */
6060 abfd
= section
->get_bfd_owner ();
6062 /* We don't use cutu_reader here because we don't need to read
6063 any dies: the signature is in the header. */
6065 end_ptr
= info_ptr
+ section
->size
;
6066 while (info_ptr
< end_ptr
)
6068 struct signatured_type
*sig_type
;
6069 struct dwo_unit
*dwo_tu
;
6071 const gdb_byte
*ptr
= info_ptr
;
6072 struct comp_unit_head header
;
6073 unsigned int length
;
6075 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6077 /* Initialize it due to a false compiler warning. */
6078 header
.signature
= -1;
6079 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6081 /* We need to read the type's signature in order to build the hash
6082 table, but we don't need anything else just yet. */
6084 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6085 abbrev_section
, ptr
, section_kind
);
6087 length
= header
.get_length ();
6089 /* Skip dummy type units. */
6090 if (ptr
>= info_ptr
+ length
6091 || peek_abbrev_code (abfd
, ptr
) == 0
6092 || header
.unit_type
!= DW_UT_type
)
6098 if (types_htab
== NULL
)
6101 types_htab
= allocate_dwo_unit_table ();
6103 types_htab
= allocate_signatured_type_table ();
6109 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6111 dwo_tu
->dwo_file
= dwo_file
;
6112 dwo_tu
->signature
= header
.signature
;
6113 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6114 dwo_tu
->section
= section
;
6115 dwo_tu
->sect_off
= sect_off
;
6116 dwo_tu
->length
= length
;
6120 /* N.B.: type_offset is not usable if this type uses a DWO file.
6121 The real type_offset is in the DWO file. */
6123 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6124 struct signatured_type
);
6125 sig_type
->signature
= header
.signature
;
6126 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6127 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6128 sig_type
->per_cu
.is_debug_types
= 1;
6129 sig_type
->per_cu
.section
= section
;
6130 sig_type
->per_cu
.sect_off
= sect_off
;
6131 sig_type
->per_cu
.length
= length
;
6134 slot
= htab_find_slot (types_htab
.get (),
6135 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6137 gdb_assert (slot
!= NULL
);
6140 sect_offset dup_sect_off
;
6144 const struct dwo_unit
*dup_tu
6145 = (const struct dwo_unit
*) *slot
;
6147 dup_sect_off
= dup_tu
->sect_off
;
6151 const struct signatured_type
*dup_tu
6152 = (const struct signatured_type
*) *slot
;
6154 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6157 complaint (_("debug type entry at offset %s is duplicate to"
6158 " the entry at offset %s, signature %s"),
6159 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6160 hex_string (header
.signature
));
6162 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6164 if (dwarf_read_debug
> 1)
6165 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6166 sect_offset_str (sect_off
),
6167 hex_string (header
.signature
));
6173 /* Create the hash table of all entries in the .debug_types
6174 (or .debug_types.dwo) section(s).
6175 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6176 otherwise it is NULL.
6178 The result is a pointer to the hash table or NULL if there are no types.
6180 Note: This function processes DWO files only, not DWP files. */
6183 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6184 struct dwo_file
*dwo_file
,
6185 gdb::array_view
<dwarf2_section_info
> type_sections
,
6186 htab_up
&types_htab
)
6188 for (dwarf2_section_info
§ion
: type_sections
)
6189 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6190 types_htab
, rcuh_kind::TYPE
);
6193 /* Create the hash table of all entries in the .debug_types section,
6194 and initialize all_type_units.
6195 The result is zero if there is an error (e.g. missing .debug_types section),
6196 otherwise non-zero. */
6199 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6203 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6204 &dwarf2_per_objfile
->info
, types_htab
,
6205 rcuh_kind::COMPILE
);
6206 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6207 dwarf2_per_objfile
->types
, types_htab
);
6208 if (types_htab
== NULL
)
6210 dwarf2_per_objfile
->signatured_types
= NULL
;
6214 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6216 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6217 dwarf2_per_objfile
->all_type_units
.reserve
6218 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6220 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6221 add_signatured_type_cu_to_table
,
6222 &dwarf2_per_objfile
->all_type_units
);
6227 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6228 If SLOT is non-NULL, it is the entry to use in the hash table.
6229 Otherwise we find one. */
6231 static struct signatured_type
*
6232 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6235 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6237 if (dwarf2_per_objfile
->all_type_units
.size ()
6238 == dwarf2_per_objfile
->all_type_units
.capacity ())
6239 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6241 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6242 struct signatured_type
);
6244 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6245 sig_type
->signature
= sig
;
6246 sig_type
->per_cu
.is_debug_types
= 1;
6247 if (dwarf2_per_objfile
->using_index
)
6249 sig_type
->per_cu
.v
.quick
=
6250 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6251 struct dwarf2_per_cu_quick_data
);
6256 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6259 gdb_assert (*slot
== NULL
);
6261 /* The rest of sig_type must be filled in by the caller. */
6265 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6266 Fill in SIG_ENTRY with DWO_ENTRY. */
6269 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6270 struct signatured_type
*sig_entry
,
6271 struct dwo_unit
*dwo_entry
)
6273 /* Make sure we're not clobbering something we don't expect to. */
6274 gdb_assert (! sig_entry
->per_cu
.queued
);
6275 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6276 if (dwarf2_per_objfile
->using_index
)
6278 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6279 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6282 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6283 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6284 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6285 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6286 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6288 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6289 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6290 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6291 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6292 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6293 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6294 sig_entry
->dwo_unit
= dwo_entry
;
6297 /* Subroutine of lookup_signatured_type.
6298 If we haven't read the TU yet, create the signatured_type data structure
6299 for a TU to be read in directly from a DWO file, bypassing the stub.
6300 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6301 using .gdb_index, then when reading a CU we want to stay in the DWO file
6302 containing that CU. Otherwise we could end up reading several other DWO
6303 files (due to comdat folding) to process the transitive closure of all the
6304 mentioned TUs, and that can be slow. The current DWO file will have every
6305 type signature that it needs.
6306 We only do this for .gdb_index because in the psymtab case we already have
6307 to read all the DWOs to build the type unit groups. */
6309 static struct signatured_type
*
6310 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6312 struct dwarf2_per_objfile
*dwarf2_per_objfile
6313 = cu
->per_cu
->dwarf2_per_objfile
;
6314 struct dwo_file
*dwo_file
;
6315 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6316 struct signatured_type find_sig_entry
, *sig_entry
;
6319 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6321 /* If TU skeletons have been removed then we may not have read in any
6323 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6324 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6326 /* We only ever need to read in one copy of a signatured type.
6327 Use the global signatured_types array to do our own comdat-folding
6328 of types. If this is the first time we're reading this TU, and
6329 the TU has an entry in .gdb_index, replace the recorded data from
6330 .gdb_index with this TU. */
6332 find_sig_entry
.signature
= sig
;
6333 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6334 &find_sig_entry
, INSERT
);
6335 sig_entry
= (struct signatured_type
*) *slot
;
6337 /* We can get here with the TU already read, *or* in the process of being
6338 read. Don't reassign the global entry to point to this DWO if that's
6339 the case. Also note that if the TU is already being read, it may not
6340 have come from a DWO, the program may be a mix of Fission-compiled
6341 code and non-Fission-compiled code. */
6343 /* Have we already tried to read this TU?
6344 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6345 needn't exist in the global table yet). */
6346 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6349 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6350 dwo_unit of the TU itself. */
6351 dwo_file
= cu
->dwo_unit
->dwo_file
;
6353 /* Ok, this is the first time we're reading this TU. */
6354 if (dwo_file
->tus
== NULL
)
6356 find_dwo_entry
.signature
= sig
;
6357 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6359 if (dwo_entry
== NULL
)
6362 /* If the global table doesn't have an entry for this TU, add one. */
6363 if (sig_entry
== NULL
)
6364 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6366 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6367 sig_entry
->per_cu
.tu_read
= 1;
6371 /* Subroutine of lookup_signatured_type.
6372 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6373 then try the DWP file. If the TU stub (skeleton) has been removed then
6374 it won't be in .gdb_index. */
6376 static struct signatured_type
*
6377 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6379 struct dwarf2_per_objfile
*dwarf2_per_objfile
6380 = cu
->per_cu
->dwarf2_per_objfile
;
6381 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6382 struct dwo_unit
*dwo_entry
;
6383 struct signatured_type find_sig_entry
, *sig_entry
;
6386 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6387 gdb_assert (dwp_file
!= NULL
);
6389 /* If TU skeletons have been removed then we may not have read in any
6391 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6392 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6394 find_sig_entry
.signature
= sig
;
6395 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6396 &find_sig_entry
, INSERT
);
6397 sig_entry
= (struct signatured_type
*) *slot
;
6399 /* Have we already tried to read this TU?
6400 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6401 needn't exist in the global table yet). */
6402 if (sig_entry
!= NULL
)
6405 if (dwp_file
->tus
== NULL
)
6407 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6408 sig
, 1 /* is_debug_types */);
6409 if (dwo_entry
== NULL
)
6412 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6413 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6418 /* Lookup a signature based type for DW_FORM_ref_sig8.
6419 Returns NULL if signature SIG is not present in the table.
6420 It is up to the caller to complain about this. */
6422 static struct signatured_type
*
6423 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6425 struct dwarf2_per_objfile
*dwarf2_per_objfile
6426 = cu
->per_cu
->dwarf2_per_objfile
;
6429 && dwarf2_per_objfile
->using_index
)
6431 /* We're in a DWO/DWP file, and we're using .gdb_index.
6432 These cases require special processing. */
6433 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6434 return lookup_dwo_signatured_type (cu
, sig
);
6436 return lookup_dwp_signatured_type (cu
, sig
);
6440 struct signatured_type find_entry
, *entry
;
6442 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6444 find_entry
.signature
= sig
;
6445 entry
= ((struct signatured_type
*)
6446 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6452 /* Return the address base of the compile unit, which, if exists, is stored
6453 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6454 static gdb::optional
<ULONGEST
>
6455 lookup_addr_base (struct die_info
*comp_unit_die
)
6457 struct attribute
*attr
;
6458 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6459 if (attr
== nullptr)
6460 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6461 if (attr
== nullptr)
6462 return gdb::optional
<ULONGEST
> ();
6463 return DW_UNSND (attr
);
6466 /* Return range lists base of the compile unit, which, if exists, is stored
6467 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6469 lookup_ranges_base (struct die_info
*comp_unit_die
)
6471 struct attribute
*attr
;
6472 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6473 if (attr
== nullptr)
6474 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6475 if (attr
== nullptr)
6477 return DW_UNSND (attr
);
6480 /* Low level DIE reading support. */
6482 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6485 init_cu_die_reader (struct die_reader_specs
*reader
,
6486 struct dwarf2_cu
*cu
,
6487 struct dwarf2_section_info
*section
,
6488 struct dwo_file
*dwo_file
,
6489 struct abbrev_table
*abbrev_table
)
6491 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6492 reader
->abfd
= section
->get_bfd_owner ();
6494 reader
->dwo_file
= dwo_file
;
6495 reader
->die_section
= section
;
6496 reader
->buffer
= section
->buffer
;
6497 reader
->buffer_end
= section
->buffer
+ section
->size
;
6498 reader
->abbrev_table
= abbrev_table
;
6501 /* Subroutine of cutu_reader to simplify it.
6502 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6503 There's just a lot of work to do, and cutu_reader is big enough
6506 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6507 from it to the DIE in the DWO. If NULL we are skipping the stub.
6508 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6509 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6510 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6511 STUB_COMP_DIR may be non-NULL.
6512 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6513 are filled in with the info of the DIE from the DWO file.
6514 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6515 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6516 kept around for at least as long as *RESULT_READER.
6518 The result is non-zero if a valid (non-dummy) DIE was found. */
6521 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6522 struct dwo_unit
*dwo_unit
,
6523 struct die_info
*stub_comp_unit_die
,
6524 const char *stub_comp_dir
,
6525 struct die_reader_specs
*result_reader
,
6526 const gdb_byte
**result_info_ptr
,
6527 struct die_info
**result_comp_unit_die
,
6528 abbrev_table_up
*result_dwo_abbrev_table
)
6530 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6532 struct dwarf2_cu
*cu
= this_cu
->cu
;
6534 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6535 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6536 int i
,num_extra_attrs
;
6537 struct dwarf2_section_info
*dwo_abbrev_section
;
6538 struct die_info
*comp_unit_die
;
6540 /* At most one of these may be provided. */
6541 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6543 /* These attributes aren't processed until later:
6544 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6545 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6546 referenced later. However, these attributes are found in the stub
6547 which we won't have later. In order to not impose this complication
6548 on the rest of the code, we read them here and copy them to the
6557 if (stub_comp_unit_die
!= NULL
)
6559 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6561 if (! this_cu
->is_debug_types
)
6562 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6563 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6564 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6565 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6566 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6568 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6570 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6571 here (if needed). We need the value before we can process
6573 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6575 else if (stub_comp_dir
!= NULL
)
6577 /* Reconstruct the comp_dir attribute to simplify the code below. */
6578 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6579 comp_dir
->name
= DW_AT_comp_dir
;
6580 comp_dir
->form
= DW_FORM_string
;
6581 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6582 DW_STRING (comp_dir
) = stub_comp_dir
;
6585 /* Set up for reading the DWO CU/TU. */
6586 cu
->dwo_unit
= dwo_unit
;
6587 dwarf2_section_info
*section
= dwo_unit
->section
;
6588 section
->read (objfile
);
6589 abfd
= section
->get_bfd_owner ();
6590 begin_info_ptr
= info_ptr
= (section
->buffer
6591 + to_underlying (dwo_unit
->sect_off
));
6592 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6594 if (this_cu
->is_debug_types
)
6596 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6598 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6599 &cu
->header
, section
,
6601 info_ptr
, rcuh_kind::TYPE
);
6602 /* This is not an assert because it can be caused by bad debug info. */
6603 if (sig_type
->signature
!= cu
->header
.signature
)
6605 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6606 " TU at offset %s [in module %s]"),
6607 hex_string (sig_type
->signature
),
6608 hex_string (cu
->header
.signature
),
6609 sect_offset_str (dwo_unit
->sect_off
),
6610 bfd_get_filename (abfd
));
6612 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6613 /* For DWOs coming from DWP files, we don't know the CU length
6614 nor the type's offset in the TU until now. */
6615 dwo_unit
->length
= cu
->header
.get_length ();
6616 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6618 /* Establish the type offset that can be used to lookup the type.
6619 For DWO files, we don't know it until now. */
6620 sig_type
->type_offset_in_section
6621 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6625 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6626 &cu
->header
, section
,
6628 info_ptr
, rcuh_kind::COMPILE
);
6629 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6630 /* For DWOs coming from DWP files, we don't know the CU length
6632 dwo_unit
->length
= cu
->header
.get_length ();
6635 *result_dwo_abbrev_table
6636 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6637 cu
->header
.abbrev_sect_off
);
6638 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6639 result_dwo_abbrev_table
->get ());
6641 /* Read in the die, but leave space to copy over the attributes
6642 from the stub. This has the benefit of simplifying the rest of
6643 the code - all the work to maintain the illusion of a single
6644 DW_TAG_{compile,type}_unit DIE is done here. */
6645 num_extra_attrs
= ((stmt_list
!= NULL
)
6649 + (comp_dir
!= NULL
));
6650 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6653 /* Copy over the attributes from the stub to the DIE we just read in. */
6654 comp_unit_die
= *result_comp_unit_die
;
6655 i
= comp_unit_die
->num_attrs
;
6656 if (stmt_list
!= NULL
)
6657 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6659 comp_unit_die
->attrs
[i
++] = *low_pc
;
6660 if (high_pc
!= NULL
)
6661 comp_unit_die
->attrs
[i
++] = *high_pc
;
6663 comp_unit_die
->attrs
[i
++] = *ranges
;
6664 if (comp_dir
!= NULL
)
6665 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6666 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6668 if (dwarf_die_debug
)
6670 fprintf_unfiltered (gdb_stdlog
,
6671 "Read die from %s@0x%x of %s:\n",
6672 section
->get_name (),
6673 (unsigned) (begin_info_ptr
- section
->buffer
),
6674 bfd_get_filename (abfd
));
6675 dump_die (comp_unit_die
, dwarf_die_debug
);
6678 /* Skip dummy compilation units. */
6679 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6680 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6683 *result_info_ptr
= info_ptr
;
6687 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6688 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6689 signature is part of the header. */
6690 static gdb::optional
<ULONGEST
>
6691 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6693 if (cu
->header
.version
>= 5)
6694 return cu
->header
.signature
;
6695 struct attribute
*attr
;
6696 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6697 if (attr
== nullptr)
6698 return gdb::optional
<ULONGEST
> ();
6699 return DW_UNSND (attr
);
6702 /* Subroutine of cutu_reader to simplify it.
6703 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6704 Returns NULL if the specified DWO unit cannot be found. */
6706 static struct dwo_unit
*
6707 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6708 struct die_info
*comp_unit_die
,
6709 const char *dwo_name
)
6711 struct dwarf2_cu
*cu
= this_cu
->cu
;
6712 struct dwo_unit
*dwo_unit
;
6713 const char *comp_dir
;
6715 gdb_assert (cu
!= NULL
);
6717 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6718 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6719 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6721 if (this_cu
->is_debug_types
)
6723 struct signatured_type
*sig_type
;
6725 /* Since this_cu is the first member of struct signatured_type,
6726 we can go from a pointer to one to a pointer to the other. */
6727 sig_type
= (struct signatured_type
*) this_cu
;
6728 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6732 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6733 if (!signature
.has_value ())
6734 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6736 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6737 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6744 /* Subroutine of cutu_reader to simplify it.
6745 See it for a description of the parameters.
6746 Read a TU directly from a DWO file, bypassing the stub. */
6749 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6750 int use_existing_cu
)
6752 struct signatured_type
*sig_type
;
6754 /* Verify we can do the following downcast, and that we have the
6756 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6757 sig_type
= (struct signatured_type
*) this_cu
;
6758 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6760 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6762 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6763 /* There's no need to do the rereading_dwo_cu handling that
6764 cutu_reader does since we don't read the stub. */
6768 /* If !use_existing_cu, this_cu->cu must be NULL. */
6769 gdb_assert (this_cu
->cu
== NULL
);
6770 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6773 /* A future optimization, if needed, would be to use an existing
6774 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6775 could share abbrev tables. */
6777 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6778 NULL
/* stub_comp_unit_die */,
6779 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6782 &m_dwo_abbrev_table
) == 0)
6789 /* Initialize a CU (or TU) and read its DIEs.
6790 If the CU defers to a DWO file, read the DWO file as well.
6792 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6793 Otherwise the table specified in the comp unit header is read in and used.
6794 This is an optimization for when we already have the abbrev table.
6796 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6797 Otherwise, a new CU is allocated with xmalloc. */
6799 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6800 struct abbrev_table
*abbrev_table
,
6801 int use_existing_cu
,
6803 : die_reader_specs
{},
6806 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6807 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6808 struct dwarf2_section_info
*section
= this_cu
->section
;
6809 bfd
*abfd
= section
->get_bfd_owner ();
6810 struct dwarf2_cu
*cu
;
6811 const gdb_byte
*begin_info_ptr
;
6812 struct signatured_type
*sig_type
= NULL
;
6813 struct dwarf2_section_info
*abbrev_section
;
6814 /* Non-zero if CU currently points to a DWO file and we need to
6815 reread it. When this happens we need to reread the skeleton die
6816 before we can reread the DWO file (this only applies to CUs, not TUs). */
6817 int rereading_dwo_cu
= 0;
6819 if (dwarf_die_debug
)
6820 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6821 this_cu
->is_debug_types
? "type" : "comp",
6822 sect_offset_str (this_cu
->sect_off
));
6824 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6825 file (instead of going through the stub), short-circuit all of this. */
6826 if (this_cu
->reading_dwo_directly
)
6828 /* Narrow down the scope of possibilities to have to understand. */
6829 gdb_assert (this_cu
->is_debug_types
);
6830 gdb_assert (abbrev_table
== NULL
);
6831 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6835 /* This is cheap if the section is already read in. */
6836 section
->read (objfile
);
6838 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6840 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6842 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6845 /* If this CU is from a DWO file we need to start over, we need to
6846 refetch the attributes from the skeleton CU.
6847 This could be optimized by retrieving those attributes from when we
6848 were here the first time: the previous comp_unit_die was stored in
6849 comp_unit_obstack. But there's no data yet that we need this
6851 if (cu
->dwo_unit
!= NULL
)
6852 rereading_dwo_cu
= 1;
6856 /* If !use_existing_cu, this_cu->cu must be NULL. */
6857 gdb_assert (this_cu
->cu
== NULL
);
6858 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6859 cu
= m_new_cu
.get ();
6862 /* Get the header. */
6863 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6865 /* We already have the header, there's no need to read it in again. */
6866 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6870 if (this_cu
->is_debug_types
)
6872 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6873 &cu
->header
, section
,
6874 abbrev_section
, info_ptr
,
6877 /* Since per_cu is the first member of struct signatured_type,
6878 we can go from a pointer to one to a pointer to the other. */
6879 sig_type
= (struct signatured_type
*) this_cu
;
6880 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6881 gdb_assert (sig_type
->type_offset_in_tu
6882 == cu
->header
.type_cu_offset_in_tu
);
6883 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6885 /* LENGTH has not been set yet for type units if we're
6886 using .gdb_index. */
6887 this_cu
->length
= cu
->header
.get_length ();
6889 /* Establish the type offset that can be used to lookup the type. */
6890 sig_type
->type_offset_in_section
=
6891 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6893 this_cu
->dwarf_version
= cu
->header
.version
;
6897 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6898 &cu
->header
, section
,
6901 rcuh_kind::COMPILE
);
6903 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6904 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6905 this_cu
->dwarf_version
= cu
->header
.version
;
6909 /* Skip dummy compilation units. */
6910 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6911 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6917 /* If we don't have them yet, read the abbrevs for this compilation unit.
6918 And if we need to read them now, make sure they're freed when we're
6920 if (abbrev_table
!= NULL
)
6921 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6924 m_abbrev_table_holder
6925 = abbrev_table::read (objfile
, abbrev_section
,
6926 cu
->header
.abbrev_sect_off
);
6927 abbrev_table
= m_abbrev_table_holder
.get ();
6930 /* Read the top level CU/TU die. */
6931 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6932 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6934 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6940 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6941 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6942 table from the DWO file and pass the ownership over to us. It will be
6943 referenced from READER, so we must make sure to free it after we're done
6946 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6947 DWO CU, that this test will fail (the attribute will not be present). */
6948 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6949 if (dwo_name
!= nullptr)
6951 struct dwo_unit
*dwo_unit
;
6952 struct die_info
*dwo_comp_unit_die
;
6954 if (comp_unit_die
->has_children
)
6956 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6957 " has children (offset %s) [in module %s]"),
6958 sect_offset_str (this_cu
->sect_off
),
6959 bfd_get_filename (abfd
));
6961 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6962 if (dwo_unit
!= NULL
)
6964 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6965 comp_unit_die
, NULL
,
6968 &m_dwo_abbrev_table
) == 0)
6974 comp_unit_die
= dwo_comp_unit_die
;
6978 /* Yikes, we couldn't find the rest of the DIE, we only have
6979 the stub. A complaint has already been logged. There's
6980 not much more we can do except pass on the stub DIE to
6981 die_reader_func. We don't want to throw an error on bad
6988 cutu_reader::keep ()
6990 /* Done, clean up. */
6991 gdb_assert (!dummy_p
);
6992 if (m_new_cu
!= NULL
)
6994 struct dwarf2_per_objfile
*dwarf2_per_objfile
6995 = m_this_cu
->dwarf2_per_objfile
;
6996 /* Link this CU into read_in_chain. */
6997 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6998 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6999 /* The chain owns it now. */
7000 m_new_cu
.release ();
7004 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7005 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7006 assumed to have already done the lookup to find the DWO file).
7008 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7009 THIS_CU->is_debug_types, but nothing else.
7011 We fill in THIS_CU->length.
7013 THIS_CU->cu is always freed when done.
7014 This is done in order to not leave THIS_CU->cu in a state where we have
7015 to care whether it refers to the "main" CU or the DWO CU.
7017 When parent_cu is passed, it is used to provide a default value for
7018 str_offsets_base and addr_base from the parent. */
7020 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7021 struct dwarf2_cu
*parent_cu
,
7022 struct dwo_file
*dwo_file
)
7023 : die_reader_specs
{},
7026 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7027 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7028 struct dwarf2_section_info
*section
= this_cu
->section
;
7029 bfd
*abfd
= section
->get_bfd_owner ();
7030 struct dwarf2_section_info
*abbrev_section
;
7031 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7033 if (dwarf_die_debug
)
7034 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7035 this_cu
->is_debug_types
? "type" : "comp",
7036 sect_offset_str (this_cu
->sect_off
));
7038 gdb_assert (this_cu
->cu
== NULL
);
7040 abbrev_section
= (dwo_file
!= NULL
7041 ? &dwo_file
->sections
.abbrev
7042 : get_abbrev_section_for_cu (this_cu
));
7044 /* This is cheap if the section is already read in. */
7045 section
->read (objfile
);
7047 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7049 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7050 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7051 &m_new_cu
->header
, section
,
7052 abbrev_section
, info_ptr
,
7053 (this_cu
->is_debug_types
7055 : rcuh_kind::COMPILE
));
7057 if (parent_cu
!= nullptr)
7059 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7060 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7062 this_cu
->length
= m_new_cu
->header
.get_length ();
7064 /* Skip dummy compilation units. */
7065 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7066 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7072 m_abbrev_table_holder
7073 = abbrev_table::read (objfile
, abbrev_section
,
7074 m_new_cu
->header
.abbrev_sect_off
);
7076 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7077 m_abbrev_table_holder
.get ());
7078 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7082 /* Type Unit Groups.
7084 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7085 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7086 so that all types coming from the same compilation (.o file) are grouped
7087 together. A future step could be to put the types in the same symtab as
7088 the CU the types ultimately came from. */
7091 hash_type_unit_group (const void *item
)
7093 const struct type_unit_group
*tu_group
7094 = (const struct type_unit_group
*) item
;
7096 return hash_stmt_list_entry (&tu_group
->hash
);
7100 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7102 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7103 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7105 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7108 /* Allocate a hash table for type unit groups. */
7111 allocate_type_unit_groups_table ()
7113 return htab_up (htab_create_alloc (3,
7114 hash_type_unit_group
,
7116 NULL
, xcalloc
, xfree
));
7119 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7120 partial symtabs. We combine several TUs per psymtab to not let the size
7121 of any one psymtab grow too big. */
7122 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7123 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7125 /* Helper routine for get_type_unit_group.
7126 Create the type_unit_group object used to hold one or more TUs. */
7128 static struct type_unit_group
*
7129 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7131 struct dwarf2_per_objfile
*dwarf2_per_objfile
7132 = cu
->per_cu
->dwarf2_per_objfile
;
7133 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7134 struct dwarf2_per_cu_data
*per_cu
;
7135 struct type_unit_group
*tu_group
;
7137 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7138 struct type_unit_group
);
7139 per_cu
= &tu_group
->per_cu
;
7140 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7142 if (dwarf2_per_objfile
->using_index
)
7144 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7145 struct dwarf2_per_cu_quick_data
);
7149 unsigned int line_offset
= to_underlying (line_offset_struct
);
7150 dwarf2_psymtab
*pst
;
7153 /* Give the symtab a useful name for debug purposes. */
7154 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7155 name
= string_printf ("<type_units_%d>",
7156 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7158 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7160 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7161 pst
->anonymous
= true;
7164 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7165 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7170 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7171 STMT_LIST is a DW_AT_stmt_list attribute. */
7173 static struct type_unit_group
*
7174 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7176 struct dwarf2_per_objfile
*dwarf2_per_objfile
7177 = cu
->per_cu
->dwarf2_per_objfile
;
7178 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7179 struct type_unit_group
*tu_group
;
7181 unsigned int line_offset
;
7182 struct type_unit_group type_unit_group_for_lookup
;
7184 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7185 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7187 /* Do we need to create a new group, or can we use an existing one? */
7191 line_offset
= DW_UNSND (stmt_list
);
7192 ++tu_stats
->nr_symtab_sharers
;
7196 /* Ugh, no stmt_list. Rare, but we have to handle it.
7197 We can do various things here like create one group per TU or
7198 spread them over multiple groups to split up the expansion work.
7199 To avoid worst case scenarios (too many groups or too large groups)
7200 we, umm, group them in bunches. */
7201 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7202 | (tu_stats
->nr_stmt_less_type_units
7203 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7204 ++tu_stats
->nr_stmt_less_type_units
;
7207 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7208 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7209 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7210 &type_unit_group_for_lookup
, INSERT
);
7213 tu_group
= (struct type_unit_group
*) *slot
;
7214 gdb_assert (tu_group
!= NULL
);
7218 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7219 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7221 ++tu_stats
->nr_symtabs
;
7227 /* Partial symbol tables. */
7229 /* Create a psymtab named NAME and assign it to PER_CU.
7231 The caller must fill in the following details:
7232 dirname, textlow, texthigh. */
7234 static dwarf2_psymtab
*
7235 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7237 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7238 dwarf2_psymtab
*pst
;
7240 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7242 pst
->psymtabs_addrmap_supported
= true;
7244 /* This is the glue that links PST into GDB's symbol API. */
7245 pst
->per_cu_data
= per_cu
;
7246 per_cu
->v
.psymtab
= pst
;
7251 /* DIE reader function for process_psymtab_comp_unit. */
7254 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7255 const gdb_byte
*info_ptr
,
7256 struct die_info
*comp_unit_die
,
7257 enum language pretend_language
)
7259 struct dwarf2_cu
*cu
= reader
->cu
;
7260 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7261 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7262 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7264 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7265 dwarf2_psymtab
*pst
;
7266 enum pc_bounds_kind cu_bounds_kind
;
7267 const char *filename
;
7269 gdb_assert (! per_cu
->is_debug_types
);
7271 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7273 /* Allocate a new partial symbol table structure. */
7274 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7275 static const char artificial
[] = "<artificial>";
7276 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7277 if (filename
== NULL
)
7279 else if (strcmp (filename
, artificial
) == 0)
7281 debug_filename
.reset (concat (artificial
, "@",
7282 sect_offset_str (per_cu
->sect_off
),
7284 filename
= debug_filename
.get ();
7287 pst
= create_partial_symtab (per_cu
, filename
);
7289 /* This must be done before calling dwarf2_build_include_psymtabs. */
7290 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7292 baseaddr
= objfile
->text_section_offset ();
7294 dwarf2_find_base_address (comp_unit_die
, cu
);
7296 /* Possibly set the default values of LOWPC and HIGHPC from
7298 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7299 &best_highpc
, cu
, pst
);
7300 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7303 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7306 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7308 /* Store the contiguous range if it is not empty; it can be
7309 empty for CUs with no code. */
7310 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7314 /* Check if comp unit has_children.
7315 If so, read the rest of the partial symbols from this comp unit.
7316 If not, there's no more debug_info for this comp unit. */
7317 if (comp_unit_die
->has_children
)
7319 struct partial_die_info
*first_die
;
7320 CORE_ADDR lowpc
, highpc
;
7322 lowpc
= ((CORE_ADDR
) -1);
7323 highpc
= ((CORE_ADDR
) 0);
7325 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7327 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7328 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7330 /* If we didn't find a lowpc, set it to highpc to avoid
7331 complaints from `maint check'. */
7332 if (lowpc
== ((CORE_ADDR
) -1))
7335 /* If the compilation unit didn't have an explicit address range,
7336 then use the information extracted from its child dies. */
7337 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7340 best_highpc
= highpc
;
7343 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7344 best_lowpc
+ baseaddr
)
7346 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7347 best_highpc
+ baseaddr
)
7350 end_psymtab_common (objfile
, pst
);
7352 if (!cu
->per_cu
->imported_symtabs_empty ())
7355 int len
= cu
->per_cu
->imported_symtabs_size ();
7357 /* Fill in 'dependencies' here; we fill in 'users' in a
7359 pst
->number_of_dependencies
= len
;
7361 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7362 for (i
= 0; i
< len
; ++i
)
7364 pst
->dependencies
[i
]
7365 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7368 cu
->per_cu
->imported_symtabs_free ();
7371 /* Get the list of files included in the current compilation unit,
7372 and build a psymtab for each of them. */
7373 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7375 if (dwarf_read_debug
)
7376 fprintf_unfiltered (gdb_stdlog
,
7377 "Psymtab for %s unit @%s: %s - %s"
7378 ", %d global, %d static syms\n",
7379 per_cu
->is_debug_types
? "type" : "comp",
7380 sect_offset_str (per_cu
->sect_off
),
7381 paddress (gdbarch
, pst
->text_low (objfile
)),
7382 paddress (gdbarch
, pst
->text_high (objfile
)),
7383 pst
->n_global_syms
, pst
->n_static_syms
);
7386 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7387 Process compilation unit THIS_CU for a psymtab. */
7390 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7391 bool want_partial_unit
,
7392 enum language pretend_language
)
7394 /* If this compilation unit was already read in, free the
7395 cached copy in order to read it in again. This is
7396 necessary because we skipped some symbols when we first
7397 read in the compilation unit (see load_partial_dies).
7398 This problem could be avoided, but the benefit is unclear. */
7399 if (this_cu
->cu
!= NULL
)
7400 free_one_cached_comp_unit (this_cu
);
7402 cutu_reader
reader (this_cu
, NULL
, 0, false);
7404 switch (reader
.comp_unit_die
->tag
)
7406 case DW_TAG_compile_unit
:
7407 this_cu
->unit_type
= DW_UT_compile
;
7409 case DW_TAG_partial_unit
:
7410 this_cu
->unit_type
= DW_UT_partial
;
7420 else if (this_cu
->is_debug_types
)
7421 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7422 reader
.comp_unit_die
);
7423 else if (want_partial_unit
7424 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7425 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7426 reader
.comp_unit_die
,
7429 this_cu
->lang
= this_cu
->cu
->language
;
7431 /* Age out any secondary CUs. */
7432 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7435 /* Reader function for build_type_psymtabs. */
7438 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7439 const gdb_byte
*info_ptr
,
7440 struct die_info
*type_unit_die
)
7442 struct dwarf2_per_objfile
*dwarf2_per_objfile
7443 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7444 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7445 struct dwarf2_cu
*cu
= reader
->cu
;
7446 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7447 struct signatured_type
*sig_type
;
7448 struct type_unit_group
*tu_group
;
7449 struct attribute
*attr
;
7450 struct partial_die_info
*first_die
;
7451 CORE_ADDR lowpc
, highpc
;
7452 dwarf2_psymtab
*pst
;
7454 gdb_assert (per_cu
->is_debug_types
);
7455 sig_type
= (struct signatured_type
*) per_cu
;
7457 if (! type_unit_die
->has_children
)
7460 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7461 tu_group
= get_type_unit_group (cu
, attr
);
7463 if (tu_group
->tus
== nullptr)
7464 tu_group
->tus
= new std::vector
<signatured_type
*>;
7465 tu_group
->tus
->push_back (sig_type
);
7467 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7468 pst
= create_partial_symtab (per_cu
, "");
7469 pst
->anonymous
= true;
7471 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7473 lowpc
= (CORE_ADDR
) -1;
7474 highpc
= (CORE_ADDR
) 0;
7475 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7477 end_psymtab_common (objfile
, pst
);
7480 /* Struct used to sort TUs by their abbreviation table offset. */
7482 struct tu_abbrev_offset
7484 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7485 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7488 signatured_type
*sig_type
;
7489 sect_offset abbrev_offset
;
7492 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7495 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7496 const struct tu_abbrev_offset
&b
)
7498 return a
.abbrev_offset
< b
.abbrev_offset
;
7501 /* Efficiently read all the type units.
7502 This does the bulk of the work for build_type_psymtabs.
7504 The efficiency is because we sort TUs by the abbrev table they use and
7505 only read each abbrev table once. In one program there are 200K TUs
7506 sharing 8K abbrev tables.
7508 The main purpose of this function is to support building the
7509 dwarf2_per_objfile->type_unit_groups table.
7510 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7511 can collapse the search space by grouping them by stmt_list.
7512 The savings can be significant, in the same program from above the 200K TUs
7513 share 8K stmt_list tables.
7515 FUNC is expected to call get_type_unit_group, which will create the
7516 struct type_unit_group if necessary and add it to
7517 dwarf2_per_objfile->type_unit_groups. */
7520 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7522 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7523 abbrev_table_up abbrev_table
;
7524 sect_offset abbrev_offset
;
7526 /* It's up to the caller to not call us multiple times. */
7527 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7529 if (dwarf2_per_objfile
->all_type_units
.empty ())
7532 /* TUs typically share abbrev tables, and there can be way more TUs than
7533 abbrev tables. Sort by abbrev table to reduce the number of times we
7534 read each abbrev table in.
7535 Alternatives are to punt or to maintain a cache of abbrev tables.
7536 This is simpler and efficient enough for now.
7538 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7539 symtab to use). Typically TUs with the same abbrev offset have the same
7540 stmt_list value too so in practice this should work well.
7542 The basic algorithm here is:
7544 sort TUs by abbrev table
7545 for each TU with same abbrev table:
7546 read abbrev table if first user
7547 read TU top level DIE
7548 [IWBN if DWO skeletons had DW_AT_stmt_list]
7551 if (dwarf_read_debug
)
7552 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7554 /* Sort in a separate table to maintain the order of all_type_units
7555 for .gdb_index: TU indices directly index all_type_units. */
7556 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7557 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7559 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7560 sorted_by_abbrev
.emplace_back
7561 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7562 sig_type
->per_cu
.section
,
7563 sig_type
->per_cu
.sect_off
));
7565 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7566 sort_tu_by_abbrev_offset
);
7568 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7570 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7572 /* Switch to the next abbrev table if necessary. */
7573 if (abbrev_table
== NULL
7574 || tu
.abbrev_offset
!= abbrev_offset
)
7576 abbrev_offset
= tu
.abbrev_offset
;
7578 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7579 &dwarf2_per_objfile
->abbrev
,
7581 ++tu_stats
->nr_uniq_abbrev_tables
;
7584 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7586 if (!reader
.dummy_p
)
7587 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7588 reader
.comp_unit_die
);
7592 /* Print collected type unit statistics. */
7595 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7597 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7599 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7600 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7601 dwarf2_per_objfile
->all_type_units
.size ());
7602 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7603 tu_stats
->nr_uniq_abbrev_tables
);
7604 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7605 tu_stats
->nr_symtabs
);
7606 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7607 tu_stats
->nr_symtab_sharers
);
7608 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7609 tu_stats
->nr_stmt_less_type_units
);
7610 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7611 tu_stats
->nr_all_type_units_reallocs
);
7614 /* Traversal function for build_type_psymtabs. */
7617 build_type_psymtab_dependencies (void **slot
, void *info
)
7619 struct dwarf2_per_objfile
*dwarf2_per_objfile
7620 = (struct dwarf2_per_objfile
*) info
;
7621 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7622 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7623 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7624 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7625 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7628 gdb_assert (len
> 0);
7629 gdb_assert (per_cu
->type_unit_group_p ());
7631 pst
->number_of_dependencies
= len
;
7632 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7633 for (i
= 0; i
< len
; ++i
)
7635 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7636 gdb_assert (iter
->per_cu
.is_debug_types
);
7637 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7638 iter
->type_unit_group
= tu_group
;
7641 delete tu_group
->tus
;
7642 tu_group
->tus
= nullptr;
7647 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7648 Build partial symbol tables for the .debug_types comp-units. */
7651 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7653 if (! create_all_type_units (dwarf2_per_objfile
))
7656 build_type_psymtabs_1 (dwarf2_per_objfile
);
7659 /* Traversal function for process_skeletonless_type_unit.
7660 Read a TU in a DWO file and build partial symbols for it. */
7663 process_skeletonless_type_unit (void **slot
, void *info
)
7665 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7666 struct dwarf2_per_objfile
*dwarf2_per_objfile
7667 = (struct dwarf2_per_objfile
*) info
;
7668 struct signatured_type find_entry
, *entry
;
7670 /* If this TU doesn't exist in the global table, add it and read it in. */
7672 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7673 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7675 find_entry
.signature
= dwo_unit
->signature
;
7676 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7677 &find_entry
, INSERT
);
7678 /* If we've already seen this type there's nothing to do. What's happening
7679 is we're doing our own version of comdat-folding here. */
7683 /* This does the job that create_all_type_units would have done for
7685 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7686 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7689 /* This does the job that build_type_psymtabs_1 would have done. */
7690 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7691 if (!reader
.dummy_p
)
7692 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7693 reader
.comp_unit_die
);
7698 /* Traversal function for process_skeletonless_type_units. */
7701 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7703 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7705 if (dwo_file
->tus
!= NULL
)
7706 htab_traverse_noresize (dwo_file
->tus
.get (),
7707 process_skeletonless_type_unit
, info
);
7712 /* Scan all TUs of DWO files, verifying we've processed them.
7713 This is needed in case a TU was emitted without its skeleton.
7714 Note: This can't be done until we know what all the DWO files are. */
7717 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7719 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7720 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7721 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7723 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7724 process_dwo_file_for_skeletonless_type_units
,
7725 dwarf2_per_objfile
);
7729 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7732 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7734 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7736 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7741 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7743 /* Set the 'user' field only if it is not already set. */
7744 if (pst
->dependencies
[j
]->user
== NULL
)
7745 pst
->dependencies
[j
]->user
= pst
;
7750 /* Build the partial symbol table by doing a quick pass through the
7751 .debug_info and .debug_abbrev sections. */
7754 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7756 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7758 if (dwarf_read_debug
)
7760 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7761 objfile_name (objfile
));
7764 scoped_restore restore_reading_psyms
7765 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7768 dwarf2_per_objfile
->info
.read (objfile
);
7770 /* Any cached compilation units will be linked by the per-objfile
7771 read_in_chain. Make sure to free them when we're done. */
7772 free_cached_comp_units
freer (dwarf2_per_objfile
);
7774 build_type_psymtabs (dwarf2_per_objfile
);
7776 create_all_comp_units (dwarf2_per_objfile
);
7778 /* Create a temporary address map on a temporary obstack. We later
7779 copy this to the final obstack. */
7780 auto_obstack temp_obstack
;
7782 scoped_restore save_psymtabs_addrmap
7783 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7784 addrmap_create_mutable (&temp_obstack
));
7786 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7787 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7789 /* This has to wait until we read the CUs, we need the list of DWOs. */
7790 process_skeletonless_type_units (dwarf2_per_objfile
);
7792 /* Now that all TUs have been processed we can fill in the dependencies. */
7793 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7795 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7796 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7799 if (dwarf_read_debug
)
7800 print_tu_stats (dwarf2_per_objfile
);
7802 set_partial_user (dwarf2_per_objfile
);
7804 objfile
->partial_symtabs
->psymtabs_addrmap
7805 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7806 objfile
->partial_symtabs
->obstack ());
7807 /* At this point we want to keep the address map. */
7808 save_psymtabs_addrmap
.release ();
7810 if (dwarf_read_debug
)
7811 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7812 objfile_name (objfile
));
7815 /* Load the partial DIEs for a secondary CU into memory.
7816 This is also used when rereading a primary CU with load_all_dies. */
7819 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7821 cutu_reader
reader (this_cu
, NULL
, 1, false);
7823 if (!reader
.dummy_p
)
7825 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7828 /* Check if comp unit has_children.
7829 If so, read the rest of the partial symbols from this comp unit.
7830 If not, there's no more debug_info for this comp unit. */
7831 if (reader
.comp_unit_die
->has_children
)
7832 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7839 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7840 struct dwarf2_section_info
*section
,
7841 struct dwarf2_section_info
*abbrev_section
,
7842 unsigned int is_dwz
)
7844 const gdb_byte
*info_ptr
;
7845 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7847 if (dwarf_read_debug
)
7848 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7849 section
->get_name (),
7850 section
->get_file_name ());
7852 section
->read (objfile
);
7854 info_ptr
= section
->buffer
;
7856 while (info_ptr
< section
->buffer
+ section
->size
)
7858 struct dwarf2_per_cu_data
*this_cu
;
7860 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7862 comp_unit_head cu_header
;
7863 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7864 abbrev_section
, info_ptr
,
7865 rcuh_kind::COMPILE
);
7867 /* Save the compilation unit for later lookup. */
7868 if (cu_header
.unit_type
!= DW_UT_type
)
7870 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7871 struct dwarf2_per_cu_data
);
7872 memset (this_cu
, 0, sizeof (*this_cu
));
7876 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7877 struct signatured_type
);
7878 memset (sig_type
, 0, sizeof (*sig_type
));
7879 sig_type
->signature
= cu_header
.signature
;
7880 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7881 this_cu
= &sig_type
->per_cu
;
7883 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7884 this_cu
->sect_off
= sect_off
;
7885 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7886 this_cu
->is_dwz
= is_dwz
;
7887 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7888 this_cu
->section
= section
;
7890 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7892 info_ptr
= info_ptr
+ this_cu
->length
;
7896 /* Create a list of all compilation units in OBJFILE.
7897 This is only done for -readnow and building partial symtabs. */
7900 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7902 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7903 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7904 &dwarf2_per_objfile
->abbrev
, 0);
7906 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7908 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7912 /* Process all loaded DIEs for compilation unit CU, starting at
7913 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7914 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7915 DW_AT_ranges). See the comments of add_partial_subprogram on how
7916 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7919 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7920 CORE_ADDR
*highpc
, int set_addrmap
,
7921 struct dwarf2_cu
*cu
)
7923 struct partial_die_info
*pdi
;
7925 /* Now, march along the PDI's, descending into ones which have
7926 interesting children but skipping the children of the other ones,
7927 until we reach the end of the compilation unit. */
7935 /* Anonymous namespaces or modules have no name but have interesting
7936 children, so we need to look at them. Ditto for anonymous
7939 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7940 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7941 || pdi
->tag
== DW_TAG_imported_unit
7942 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7946 case DW_TAG_subprogram
:
7947 case DW_TAG_inlined_subroutine
:
7948 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7950 case DW_TAG_constant
:
7951 case DW_TAG_variable
:
7952 case DW_TAG_typedef
:
7953 case DW_TAG_union_type
:
7954 if (!pdi
->is_declaration
)
7956 add_partial_symbol (pdi
, cu
);
7959 case DW_TAG_class_type
:
7960 case DW_TAG_interface_type
:
7961 case DW_TAG_structure_type
:
7962 if (!pdi
->is_declaration
)
7964 add_partial_symbol (pdi
, cu
);
7966 if ((cu
->language
== language_rust
7967 || cu
->language
== language_cplus
) && pdi
->has_children
)
7968 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7971 case DW_TAG_enumeration_type
:
7972 if (!pdi
->is_declaration
)
7973 add_partial_enumeration (pdi
, cu
);
7975 case DW_TAG_base_type
:
7976 case DW_TAG_subrange_type
:
7977 /* File scope base type definitions are added to the partial
7979 add_partial_symbol (pdi
, cu
);
7981 case DW_TAG_namespace
:
7982 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7985 if (!pdi
->is_declaration
)
7986 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7988 case DW_TAG_imported_unit
:
7990 struct dwarf2_per_cu_data
*per_cu
;
7992 /* For now we don't handle imported units in type units. */
7993 if (cu
->per_cu
->is_debug_types
)
7995 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7996 " supported in type units [in module %s]"),
7997 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8000 per_cu
= dwarf2_find_containing_comp_unit
8001 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8002 cu
->per_cu
->dwarf2_per_objfile
);
8004 /* Go read the partial unit, if needed. */
8005 if (per_cu
->v
.psymtab
== NULL
)
8006 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8008 cu
->per_cu
->imported_symtabs_push (per_cu
);
8011 case DW_TAG_imported_declaration
:
8012 add_partial_symbol (pdi
, cu
);
8019 /* If the die has a sibling, skip to the sibling. */
8021 pdi
= pdi
->die_sibling
;
8025 /* Functions used to compute the fully scoped name of a partial DIE.
8027 Normally, this is simple. For C++, the parent DIE's fully scoped
8028 name is concatenated with "::" and the partial DIE's name.
8029 Enumerators are an exception; they use the scope of their parent
8030 enumeration type, i.e. the name of the enumeration type is not
8031 prepended to the enumerator.
8033 There are two complexities. One is DW_AT_specification; in this
8034 case "parent" means the parent of the target of the specification,
8035 instead of the direct parent of the DIE. The other is compilers
8036 which do not emit DW_TAG_namespace; in this case we try to guess
8037 the fully qualified name of structure types from their members'
8038 linkage names. This must be done using the DIE's children rather
8039 than the children of any DW_AT_specification target. We only need
8040 to do this for structures at the top level, i.e. if the target of
8041 any DW_AT_specification (if any; otherwise the DIE itself) does not
8044 /* Compute the scope prefix associated with PDI's parent, in
8045 compilation unit CU. The result will be allocated on CU's
8046 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8047 field. NULL is returned if no prefix is necessary. */
8049 partial_die_parent_scope (struct partial_die_info
*pdi
,
8050 struct dwarf2_cu
*cu
)
8052 const char *grandparent_scope
;
8053 struct partial_die_info
*parent
, *real_pdi
;
8055 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8056 then this means the parent of the specification DIE. */
8059 while (real_pdi
->has_specification
)
8061 auto res
= find_partial_die (real_pdi
->spec_offset
,
8062 real_pdi
->spec_is_dwz
, cu
);
8067 parent
= real_pdi
->die_parent
;
8071 if (parent
->scope_set
)
8072 return parent
->scope
;
8076 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8078 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8079 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8080 Work around this problem here. */
8081 if (cu
->language
== language_cplus
8082 && parent
->tag
== DW_TAG_namespace
8083 && strcmp (parent
->name
, "::") == 0
8084 && grandparent_scope
== NULL
)
8086 parent
->scope
= NULL
;
8087 parent
->scope_set
= 1;
8091 /* Nested subroutines in Fortran get a prefix. */
8092 if (pdi
->tag
== DW_TAG_enumerator
)
8093 /* Enumerators should not get the name of the enumeration as a prefix. */
8094 parent
->scope
= grandparent_scope
;
8095 else if (parent
->tag
== DW_TAG_namespace
8096 || parent
->tag
== DW_TAG_module
8097 || parent
->tag
== DW_TAG_structure_type
8098 || parent
->tag
== DW_TAG_class_type
8099 || parent
->tag
== DW_TAG_interface_type
8100 || parent
->tag
== DW_TAG_union_type
8101 || parent
->tag
== DW_TAG_enumeration_type
8102 || (cu
->language
== language_fortran
8103 && parent
->tag
== DW_TAG_subprogram
8104 && pdi
->tag
== DW_TAG_subprogram
))
8106 if (grandparent_scope
== NULL
)
8107 parent
->scope
= parent
->name
;
8109 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8111 parent
->name
, 0, cu
);
8115 /* FIXME drow/2004-04-01: What should we be doing with
8116 function-local names? For partial symbols, we should probably be
8118 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8119 dwarf_tag_name (parent
->tag
),
8120 sect_offset_str (pdi
->sect_off
));
8121 parent
->scope
= grandparent_scope
;
8124 parent
->scope_set
= 1;
8125 return parent
->scope
;
8128 /* Return the fully scoped name associated with PDI, from compilation unit
8129 CU. The result will be allocated with malloc. */
8131 static gdb::unique_xmalloc_ptr
<char>
8132 partial_die_full_name (struct partial_die_info
*pdi
,
8133 struct dwarf2_cu
*cu
)
8135 const char *parent_scope
;
8137 /* If this is a template instantiation, we can not work out the
8138 template arguments from partial DIEs. So, unfortunately, we have
8139 to go through the full DIEs. At least any work we do building
8140 types here will be reused if full symbols are loaded later. */
8141 if (pdi
->has_template_arguments
)
8145 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8147 struct die_info
*die
;
8148 struct attribute attr
;
8149 struct dwarf2_cu
*ref_cu
= cu
;
8151 /* DW_FORM_ref_addr is using section offset. */
8152 attr
.name
= (enum dwarf_attribute
) 0;
8153 attr
.form
= DW_FORM_ref_addr
;
8154 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8155 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8157 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8161 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8162 if (parent_scope
== NULL
)
8165 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8170 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8172 struct dwarf2_per_objfile
*dwarf2_per_objfile
8173 = cu
->per_cu
->dwarf2_per_objfile
;
8174 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8175 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8177 const char *actual_name
= NULL
;
8180 baseaddr
= objfile
->text_section_offset ();
8182 gdb::unique_xmalloc_ptr
<char> built_actual_name
8183 = partial_die_full_name (pdi
, cu
);
8184 if (built_actual_name
!= NULL
)
8185 actual_name
= built_actual_name
.get ();
8187 if (actual_name
== NULL
)
8188 actual_name
= pdi
->name
;
8192 case DW_TAG_inlined_subroutine
:
8193 case DW_TAG_subprogram
:
8194 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8196 if (pdi
->is_external
8197 || cu
->language
== language_ada
8198 || (cu
->language
== language_fortran
8199 && pdi
->die_parent
!= NULL
8200 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8202 /* Normally, only "external" DIEs are part of the global scope.
8203 But in Ada and Fortran, we want to be able to access nested
8204 procedures globally. So all Ada and Fortran subprograms are
8205 stored in the global scope. */
8206 add_psymbol_to_list (actual_name
,
8207 built_actual_name
!= NULL
,
8208 VAR_DOMAIN
, LOC_BLOCK
,
8209 SECT_OFF_TEXT (objfile
),
8210 psymbol_placement::GLOBAL
,
8212 cu
->language
, objfile
);
8216 add_psymbol_to_list (actual_name
,
8217 built_actual_name
!= NULL
,
8218 VAR_DOMAIN
, LOC_BLOCK
,
8219 SECT_OFF_TEXT (objfile
),
8220 psymbol_placement::STATIC
,
8221 addr
, cu
->language
, objfile
);
8224 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8225 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8227 case DW_TAG_constant
:
8228 add_psymbol_to_list (actual_name
,
8229 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8230 -1, (pdi
->is_external
8231 ? psymbol_placement::GLOBAL
8232 : psymbol_placement::STATIC
),
8233 0, cu
->language
, objfile
);
8235 case DW_TAG_variable
:
8237 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8241 && !dwarf2_per_objfile
->has_section_at_zero
)
8243 /* A global or static variable may also have been stripped
8244 out by the linker if unused, in which case its address
8245 will be nullified; do not add such variables into partial
8246 symbol table then. */
8248 else if (pdi
->is_external
)
8251 Don't enter into the minimal symbol tables as there is
8252 a minimal symbol table entry from the ELF symbols already.
8253 Enter into partial symbol table if it has a location
8254 descriptor or a type.
8255 If the location descriptor is missing, new_symbol will create
8256 a LOC_UNRESOLVED symbol, the address of the variable will then
8257 be determined from the minimal symbol table whenever the variable
8259 The address for the partial symbol table entry is not
8260 used by GDB, but it comes in handy for debugging partial symbol
8263 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8264 add_psymbol_to_list (actual_name
,
8265 built_actual_name
!= NULL
,
8266 VAR_DOMAIN
, LOC_STATIC
,
8267 SECT_OFF_TEXT (objfile
),
8268 psymbol_placement::GLOBAL
,
8269 addr
, cu
->language
, objfile
);
8273 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8275 /* Static Variable. Skip symbols whose value we cannot know (those
8276 without location descriptors or constant values). */
8277 if (!has_loc
&& !pdi
->has_const_value
)
8280 add_psymbol_to_list (actual_name
,
8281 built_actual_name
!= NULL
,
8282 VAR_DOMAIN
, LOC_STATIC
,
8283 SECT_OFF_TEXT (objfile
),
8284 psymbol_placement::STATIC
,
8286 cu
->language
, objfile
);
8289 case DW_TAG_typedef
:
8290 case DW_TAG_base_type
:
8291 case DW_TAG_subrange_type
:
8292 add_psymbol_to_list (actual_name
,
8293 built_actual_name
!= NULL
,
8294 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8295 psymbol_placement::STATIC
,
8296 0, cu
->language
, objfile
);
8298 case DW_TAG_imported_declaration
:
8299 case DW_TAG_namespace
:
8300 add_psymbol_to_list (actual_name
,
8301 built_actual_name
!= NULL
,
8302 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8303 psymbol_placement::GLOBAL
,
8304 0, cu
->language
, objfile
);
8307 /* With Fortran 77 there might be a "BLOCK DATA" module
8308 available without any name. If so, we skip the module as it
8309 doesn't bring any value. */
8310 if (actual_name
!= nullptr)
8311 add_psymbol_to_list (actual_name
,
8312 built_actual_name
!= NULL
,
8313 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8314 psymbol_placement::GLOBAL
,
8315 0, cu
->language
, objfile
);
8317 case DW_TAG_class_type
:
8318 case DW_TAG_interface_type
:
8319 case DW_TAG_structure_type
:
8320 case DW_TAG_union_type
:
8321 case DW_TAG_enumeration_type
:
8322 /* Skip external references. The DWARF standard says in the section
8323 about "Structure, Union, and Class Type Entries": "An incomplete
8324 structure, union or class type is represented by a structure,
8325 union or class entry that does not have a byte size attribute
8326 and that has a DW_AT_declaration attribute." */
8327 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8330 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8331 static vs. global. */
8332 add_psymbol_to_list (actual_name
,
8333 built_actual_name
!= NULL
,
8334 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8335 cu
->language
== language_cplus
8336 ? psymbol_placement::GLOBAL
8337 : psymbol_placement::STATIC
,
8338 0, cu
->language
, objfile
);
8341 case DW_TAG_enumerator
:
8342 add_psymbol_to_list (actual_name
,
8343 built_actual_name
!= NULL
,
8344 VAR_DOMAIN
, LOC_CONST
, -1,
8345 cu
->language
== language_cplus
8346 ? psymbol_placement::GLOBAL
8347 : psymbol_placement::STATIC
,
8348 0, cu
->language
, objfile
);
8355 /* Read a partial die corresponding to a namespace; also, add a symbol
8356 corresponding to that namespace to the symbol table. NAMESPACE is
8357 the name of the enclosing namespace. */
8360 add_partial_namespace (struct partial_die_info
*pdi
,
8361 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8362 int set_addrmap
, struct dwarf2_cu
*cu
)
8364 /* Add a symbol for the namespace. */
8366 add_partial_symbol (pdi
, cu
);
8368 /* Now scan partial symbols in that namespace. */
8370 if (pdi
->has_children
)
8371 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8374 /* Read a partial die corresponding to a Fortran module. */
8377 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8378 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8380 /* Add a symbol for the namespace. */
8382 add_partial_symbol (pdi
, cu
);
8384 /* Now scan partial symbols in that module. */
8386 if (pdi
->has_children
)
8387 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8390 /* Read a partial die corresponding to a subprogram or an inlined
8391 subprogram and create a partial symbol for that subprogram.
8392 When the CU language allows it, this routine also defines a partial
8393 symbol for each nested subprogram that this subprogram contains.
8394 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8395 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8397 PDI may also be a lexical block, in which case we simply search
8398 recursively for subprograms defined inside that lexical block.
8399 Again, this is only performed when the CU language allows this
8400 type of definitions. */
8403 add_partial_subprogram (struct partial_die_info
*pdi
,
8404 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8405 int set_addrmap
, struct dwarf2_cu
*cu
)
8407 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8409 if (pdi
->has_pc_info
)
8411 if (pdi
->lowpc
< *lowpc
)
8412 *lowpc
= pdi
->lowpc
;
8413 if (pdi
->highpc
> *highpc
)
8414 *highpc
= pdi
->highpc
;
8417 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8418 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8420 CORE_ADDR this_highpc
;
8421 CORE_ADDR this_lowpc
;
8423 baseaddr
= objfile
->text_section_offset ();
8425 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8426 pdi
->lowpc
+ baseaddr
)
8429 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8430 pdi
->highpc
+ baseaddr
)
8432 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8433 this_lowpc
, this_highpc
- 1,
8434 cu
->per_cu
->v
.psymtab
);
8438 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8440 if (!pdi
->is_declaration
)
8441 /* Ignore subprogram DIEs that do not have a name, they are
8442 illegal. Do not emit a complaint at this point, we will
8443 do so when we convert this psymtab into a symtab. */
8445 add_partial_symbol (pdi
, cu
);
8449 if (! pdi
->has_children
)
8452 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8454 pdi
= pdi
->die_child
;
8458 if (pdi
->tag
== DW_TAG_subprogram
8459 || pdi
->tag
== DW_TAG_inlined_subroutine
8460 || pdi
->tag
== DW_TAG_lexical_block
)
8461 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8462 pdi
= pdi
->die_sibling
;
8467 /* Read a partial die corresponding to an enumeration type. */
8470 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8471 struct dwarf2_cu
*cu
)
8473 struct partial_die_info
*pdi
;
8475 if (enum_pdi
->name
!= NULL
)
8476 add_partial_symbol (enum_pdi
, cu
);
8478 pdi
= enum_pdi
->die_child
;
8481 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8482 complaint (_("malformed enumerator DIE ignored"));
8484 add_partial_symbol (pdi
, cu
);
8485 pdi
= pdi
->die_sibling
;
8489 /* Return the initial uleb128 in the die at INFO_PTR. */
8492 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8494 unsigned int bytes_read
;
8496 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8499 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8500 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8502 Return the corresponding abbrev, or NULL if the number is zero (indicating
8503 an empty DIE). In either case *BYTES_READ will be set to the length of
8504 the initial number. */
8506 static struct abbrev_info
*
8507 peek_die_abbrev (const die_reader_specs
&reader
,
8508 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8510 dwarf2_cu
*cu
= reader
.cu
;
8511 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8512 unsigned int abbrev_number
8513 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8515 if (abbrev_number
== 0)
8518 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8521 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8522 " at offset %s [in module %s]"),
8523 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8524 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8530 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8531 Returns a pointer to the end of a series of DIEs, terminated by an empty
8532 DIE. Any children of the skipped DIEs will also be skipped. */
8534 static const gdb_byte
*
8535 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8539 unsigned int bytes_read
;
8540 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8543 return info_ptr
+ bytes_read
;
8545 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8549 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8550 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8551 abbrev corresponding to that skipped uleb128 should be passed in
8552 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8555 static const gdb_byte
*
8556 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8557 struct abbrev_info
*abbrev
)
8559 unsigned int bytes_read
;
8560 struct attribute attr
;
8561 bfd
*abfd
= reader
->abfd
;
8562 struct dwarf2_cu
*cu
= reader
->cu
;
8563 const gdb_byte
*buffer
= reader
->buffer
;
8564 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8565 unsigned int form
, i
;
8567 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8569 /* The only abbrev we care about is DW_AT_sibling. */
8570 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8573 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8575 if (attr
.form
== DW_FORM_ref_addr
)
8576 complaint (_("ignoring absolute DW_AT_sibling"));
8579 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8580 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8582 if (sibling_ptr
< info_ptr
)
8583 complaint (_("DW_AT_sibling points backwards"));
8584 else if (sibling_ptr
> reader
->buffer_end
)
8585 reader
->die_section
->overflow_complaint ();
8591 /* If it isn't DW_AT_sibling, skip this attribute. */
8592 form
= abbrev
->attrs
[i
].form
;
8596 case DW_FORM_ref_addr
:
8597 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8598 and later it is offset sized. */
8599 if (cu
->header
.version
== 2)
8600 info_ptr
+= cu
->header
.addr_size
;
8602 info_ptr
+= cu
->header
.offset_size
;
8604 case DW_FORM_GNU_ref_alt
:
8605 info_ptr
+= cu
->header
.offset_size
;
8608 info_ptr
+= cu
->header
.addr_size
;
8616 case DW_FORM_flag_present
:
8617 case DW_FORM_implicit_const
:
8634 case DW_FORM_ref_sig8
:
8637 case DW_FORM_data16
:
8640 case DW_FORM_string
:
8641 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8642 info_ptr
+= bytes_read
;
8644 case DW_FORM_sec_offset
:
8646 case DW_FORM_GNU_strp_alt
:
8647 info_ptr
+= cu
->header
.offset_size
;
8649 case DW_FORM_exprloc
:
8651 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8652 info_ptr
+= bytes_read
;
8654 case DW_FORM_block1
:
8655 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8657 case DW_FORM_block2
:
8658 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8660 case DW_FORM_block4
:
8661 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8667 case DW_FORM_ref_udata
:
8668 case DW_FORM_GNU_addr_index
:
8669 case DW_FORM_GNU_str_index
:
8670 case DW_FORM_rnglistx
:
8671 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8673 case DW_FORM_indirect
:
8674 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8675 info_ptr
+= bytes_read
;
8676 /* We need to continue parsing from here, so just go back to
8678 goto skip_attribute
;
8681 error (_("Dwarf Error: Cannot handle %s "
8682 "in DWARF reader [in module %s]"),
8683 dwarf_form_name (form
),
8684 bfd_get_filename (abfd
));
8688 if (abbrev
->has_children
)
8689 return skip_children (reader
, info_ptr
);
8694 /* Locate ORIG_PDI's sibling.
8695 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8697 static const gdb_byte
*
8698 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8699 struct partial_die_info
*orig_pdi
,
8700 const gdb_byte
*info_ptr
)
8702 /* Do we know the sibling already? */
8704 if (orig_pdi
->sibling
)
8705 return orig_pdi
->sibling
;
8707 /* Are there any children to deal with? */
8709 if (!orig_pdi
->has_children
)
8712 /* Skip the children the long way. */
8714 return skip_children (reader
, info_ptr
);
8717 /* Expand this partial symbol table into a full symbol table. SELF is
8721 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8723 struct dwarf2_per_objfile
*dwarf2_per_objfile
8724 = get_dwarf2_per_objfile (objfile
);
8726 gdb_assert (!readin
);
8727 /* If this psymtab is constructed from a debug-only objfile, the
8728 has_section_at_zero flag will not necessarily be correct. We
8729 can get the correct value for this flag by looking at the data
8730 associated with the (presumably stripped) associated objfile. */
8731 if (objfile
->separate_debug_objfile_backlink
)
8733 struct dwarf2_per_objfile
*dpo_backlink
8734 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8736 dwarf2_per_objfile
->has_section_at_zero
8737 = dpo_backlink
->has_section_at_zero
;
8740 expand_psymtab (objfile
);
8742 process_cu_includes (dwarf2_per_objfile
);
8745 /* Reading in full CUs. */
8747 /* Add PER_CU to the queue. */
8750 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8751 enum language pretend_language
)
8754 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8757 /* If PER_CU is not yet queued, add it to the queue.
8758 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8760 The result is non-zero if PER_CU was queued, otherwise the result is zero
8761 meaning either PER_CU is already queued or it is already loaded.
8763 N.B. There is an invariant here that if a CU is queued then it is loaded.
8764 The caller is required to load PER_CU if we return non-zero. */
8767 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8768 struct dwarf2_per_cu_data
*per_cu
,
8769 enum language pretend_language
)
8771 /* We may arrive here during partial symbol reading, if we need full
8772 DIEs to process an unusual case (e.g. template arguments). Do
8773 not queue PER_CU, just tell our caller to load its DIEs. */
8774 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8776 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8781 /* Mark the dependence relation so that we don't flush PER_CU
8783 if (dependent_cu
!= NULL
)
8784 dwarf2_add_dependence (dependent_cu
, per_cu
);
8786 /* If it's already on the queue, we have nothing to do. */
8790 /* If the compilation unit is already loaded, just mark it as
8792 if (per_cu
->cu
!= NULL
)
8794 per_cu
->cu
->last_used
= 0;
8798 /* Add it to the queue. */
8799 queue_comp_unit (per_cu
, pretend_language
);
8804 /* Process the queue. */
8807 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8809 if (dwarf_read_debug
)
8811 fprintf_unfiltered (gdb_stdlog
,
8812 "Expanding one or more symtabs of objfile %s ...\n",
8813 objfile_name (dwarf2_per_objfile
->objfile
));
8816 /* The queue starts out with one item, but following a DIE reference
8817 may load a new CU, adding it to the end of the queue. */
8818 while (!dwarf2_per_objfile
->queue
.empty ())
8820 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8822 if ((dwarf2_per_objfile
->using_index
8823 ? !item
.per_cu
->v
.quick
->compunit_symtab
8824 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8825 /* Skip dummy CUs. */
8826 && item
.per_cu
->cu
!= NULL
)
8828 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8829 unsigned int debug_print_threshold
;
8832 if (per_cu
->is_debug_types
)
8834 struct signatured_type
*sig_type
=
8835 (struct signatured_type
*) per_cu
;
8837 sprintf (buf
, "TU %s at offset %s",
8838 hex_string (sig_type
->signature
),
8839 sect_offset_str (per_cu
->sect_off
));
8840 /* There can be 100s of TUs.
8841 Only print them in verbose mode. */
8842 debug_print_threshold
= 2;
8846 sprintf (buf
, "CU at offset %s",
8847 sect_offset_str (per_cu
->sect_off
));
8848 debug_print_threshold
= 1;
8851 if (dwarf_read_debug
>= debug_print_threshold
)
8852 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8854 if (per_cu
->is_debug_types
)
8855 process_full_type_unit (per_cu
, item
.pretend_language
);
8857 process_full_comp_unit (per_cu
, item
.pretend_language
);
8859 if (dwarf_read_debug
>= debug_print_threshold
)
8860 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8863 item
.per_cu
->queued
= 0;
8864 dwarf2_per_objfile
->queue
.pop ();
8867 if (dwarf_read_debug
)
8869 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8870 objfile_name (dwarf2_per_objfile
->objfile
));
8874 /* Read in full symbols for PST, and anything it depends on. */
8877 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8882 read_dependencies (objfile
);
8884 dw2_do_instantiate_symtab (per_cu_data
, false);
8885 gdb_assert (get_compunit_symtab () != nullptr);
8888 /* Trivial hash function for die_info: the hash value of a DIE
8889 is its offset in .debug_info for this objfile. */
8892 die_hash (const void *item
)
8894 const struct die_info
*die
= (const struct die_info
*) item
;
8896 return to_underlying (die
->sect_off
);
8899 /* Trivial comparison function for die_info structures: two DIEs
8900 are equal if they have the same offset. */
8903 die_eq (const void *item_lhs
, const void *item_rhs
)
8905 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8906 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8908 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8911 /* Load the DIEs associated with PER_CU into memory. */
8914 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8916 enum language pretend_language
)
8918 gdb_assert (! this_cu
->is_debug_types
);
8920 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8924 struct dwarf2_cu
*cu
= reader
.cu
;
8925 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8927 gdb_assert (cu
->die_hash
== NULL
);
8929 htab_create_alloc_ex (cu
->header
.length
/ 12,
8933 &cu
->comp_unit_obstack
,
8934 hashtab_obstack_allocate
,
8935 dummy_obstack_deallocate
);
8937 if (reader
.comp_unit_die
->has_children
)
8938 reader
.comp_unit_die
->child
8939 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8940 &info_ptr
, reader
.comp_unit_die
);
8941 cu
->dies
= reader
.comp_unit_die
;
8942 /* comp_unit_die is not stored in die_hash, no need. */
8944 /* We try not to read any attributes in this function, because not
8945 all CUs needed for references have been loaded yet, and symbol
8946 table processing isn't initialized. But we have to set the CU language,
8947 or we won't be able to build types correctly.
8948 Similarly, if we do not read the producer, we can not apply
8949 producer-specific interpretation. */
8950 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8955 /* Add a DIE to the delayed physname list. */
8958 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8959 const char *name
, struct die_info
*die
,
8960 struct dwarf2_cu
*cu
)
8962 struct delayed_method_info mi
;
8964 mi
.fnfield_index
= fnfield_index
;
8968 cu
->method_list
.push_back (mi
);
8971 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8972 "const" / "volatile". If so, decrements LEN by the length of the
8973 modifier and return true. Otherwise return false. */
8977 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8979 size_t mod_len
= sizeof (mod
) - 1;
8980 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8988 /* Compute the physnames of any methods on the CU's method list.
8990 The computation of method physnames is delayed in order to avoid the
8991 (bad) condition that one of the method's formal parameters is of an as yet
8995 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8997 /* Only C++ delays computing physnames. */
8998 if (cu
->method_list
.empty ())
9000 gdb_assert (cu
->language
== language_cplus
);
9002 for (const delayed_method_info
&mi
: cu
->method_list
)
9004 const char *physname
;
9005 struct fn_fieldlist
*fn_flp
9006 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9007 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9008 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9009 = physname
? physname
: "";
9011 /* Since there's no tag to indicate whether a method is a
9012 const/volatile overload, extract that information out of the
9014 if (physname
!= NULL
)
9016 size_t len
= strlen (physname
);
9020 if (physname
[len
] == ')') /* shortcut */
9022 else if (check_modifier (physname
, len
, " const"))
9023 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9024 else if (check_modifier (physname
, len
, " volatile"))
9025 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9032 /* The list is no longer needed. */
9033 cu
->method_list
.clear ();
9036 /* Go objects should be embedded in a DW_TAG_module DIE,
9037 and it's not clear if/how imported objects will appear.
9038 To keep Go support simple until that's worked out,
9039 go back through what we've read and create something usable.
9040 We could do this while processing each DIE, and feels kinda cleaner,
9041 but that way is more invasive.
9042 This is to, for example, allow the user to type "p var" or "b main"
9043 without having to specify the package name, and allow lookups
9044 of module.object to work in contexts that use the expression
9048 fixup_go_packaging (struct dwarf2_cu
*cu
)
9050 gdb::unique_xmalloc_ptr
<char> package_name
;
9051 struct pending
*list
;
9054 for (list
= *cu
->get_builder ()->get_global_symbols ();
9058 for (i
= 0; i
< list
->nsyms
; ++i
)
9060 struct symbol
*sym
= list
->symbol
[i
];
9062 if (sym
->language () == language_go
9063 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9065 gdb::unique_xmalloc_ptr
<char> this_package_name
9066 (go_symbol_package_name (sym
));
9068 if (this_package_name
== NULL
)
9070 if (package_name
== NULL
)
9071 package_name
= std::move (this_package_name
);
9074 struct objfile
*objfile
9075 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9076 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9077 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9078 (symbol_symtab (sym
) != NULL
9079 ? symtab_to_filename_for_display
9080 (symbol_symtab (sym
))
9081 : objfile_name (objfile
)),
9082 this_package_name
.get (), package_name
.get ());
9088 if (package_name
!= NULL
)
9090 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9091 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9092 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9093 saved_package_name
);
9096 sym
= allocate_symbol (objfile
);
9097 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9098 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9099 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9100 e.g., "main" finds the "main" module and not C's main(). */
9101 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9102 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9103 SYMBOL_TYPE (sym
) = type
;
9105 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9109 /* Allocate a fully-qualified name consisting of the two parts on the
9113 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9115 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9118 /* A helper that allocates a struct discriminant_info to attach to a
9121 static struct discriminant_info
*
9122 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9125 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9126 gdb_assert (discriminant_index
== -1
9127 || (discriminant_index
>= 0
9128 && discriminant_index
< TYPE_NFIELDS (type
)));
9129 gdb_assert (default_index
== -1
9130 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9132 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9134 struct discriminant_info
*disc
9135 = ((struct discriminant_info
*)
9137 offsetof (struct discriminant_info
, discriminants
)
9138 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9139 disc
->default_index
= default_index
;
9140 disc
->discriminant_index
= discriminant_index
;
9142 struct dynamic_prop prop
;
9143 prop
.kind
= PROP_UNDEFINED
;
9144 prop
.data
.baton
= disc
;
9146 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9151 /* Some versions of rustc emitted enums in an unusual way.
9153 Ordinary enums were emitted as unions. The first element of each
9154 structure in the union was named "RUST$ENUM$DISR". This element
9155 held the discriminant.
9157 These versions of Rust also implemented the "non-zero"
9158 optimization. When the enum had two values, and one is empty and
9159 the other holds a pointer that cannot be zero, the pointer is used
9160 as the discriminant, with a zero value meaning the empty variant.
9161 Here, the union's first member is of the form
9162 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9163 where the fieldnos are the indices of the fields that should be
9164 traversed in order to find the field (which may be several fields deep)
9165 and the variantname is the name of the variant of the case when the
9168 This function recognizes whether TYPE is of one of these forms,
9169 and, if so, smashes it to be a variant type. */
9172 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9174 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9176 /* We don't need to deal with empty enums. */
9177 if (TYPE_NFIELDS (type
) == 0)
9180 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9181 if (TYPE_NFIELDS (type
) == 1
9182 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9184 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9186 /* Decode the field name to find the offset of the
9188 ULONGEST bit_offset
= 0;
9189 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9190 while (name
[0] >= '0' && name
[0] <= '9')
9193 unsigned long index
= strtoul (name
, &tail
, 10);
9196 || index
>= TYPE_NFIELDS (field_type
)
9197 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9198 != FIELD_LOC_KIND_BITPOS
))
9200 complaint (_("Could not parse Rust enum encoding string \"%s\""
9202 TYPE_FIELD_NAME (type
, 0),
9203 objfile_name (objfile
));
9208 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9209 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9212 /* Make a union to hold the variants. */
9213 struct type
*union_type
= alloc_type (objfile
);
9214 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9215 TYPE_NFIELDS (union_type
) = 3;
9216 TYPE_FIELDS (union_type
)
9217 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9218 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9219 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9221 /* Put the discriminant must at index 0. */
9222 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9223 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9224 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9225 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9227 /* The order of fields doesn't really matter, so put the real
9228 field at index 1 and the data-less field at index 2. */
9229 struct discriminant_info
*disc
9230 = alloc_discriminant_info (union_type
, 0, 1);
9231 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9232 TYPE_FIELD_NAME (union_type
, 1)
9233 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9234 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9235 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9236 TYPE_FIELD_NAME (union_type
, 1));
9238 const char *dataless_name
9239 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9241 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9243 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9244 /* NAME points into the original discriminant name, which
9245 already has the correct lifetime. */
9246 TYPE_FIELD_NAME (union_type
, 2) = name
;
9247 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9248 disc
->discriminants
[2] = 0;
9250 /* Smash this type to be a structure type. We have to do this
9251 because the type has already been recorded. */
9252 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9253 TYPE_NFIELDS (type
) = 1;
9255 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9257 /* Install the variant part. */
9258 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9259 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9260 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9262 /* A union with a single anonymous field is probably an old-style
9264 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9266 /* Smash this type to be a structure type. We have to do this
9267 because the type has already been recorded. */
9268 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9270 /* Make a union to hold the variants. */
9271 struct type
*union_type
= alloc_type (objfile
);
9272 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9273 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9274 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9275 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9276 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9278 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9279 const char *variant_name
9280 = rust_last_path_segment (TYPE_NAME (field_type
));
9281 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9282 TYPE_NAME (field_type
)
9283 = rust_fully_qualify (&objfile
->objfile_obstack
,
9284 TYPE_NAME (type
), variant_name
);
9286 /* Install the union in the outer struct type. */
9287 TYPE_NFIELDS (type
) = 1;
9289 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9290 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9291 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9292 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9294 alloc_discriminant_info (union_type
, -1, 0);
9298 struct type
*disr_type
= nullptr;
9299 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9301 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9303 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9305 /* All fields of a true enum will be structs. */
9308 else if (TYPE_NFIELDS (disr_type
) == 0)
9310 /* Could be data-less variant, so keep going. */
9311 disr_type
= nullptr;
9313 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9314 "RUST$ENUM$DISR") != 0)
9316 /* Not a Rust enum. */
9326 /* If we got here without a discriminant, then it's probably
9328 if (disr_type
== nullptr)
9331 /* Smash this type to be a structure type. We have to do this
9332 because the type has already been recorded. */
9333 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9335 /* Make a union to hold the variants. */
9336 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9337 struct type
*union_type
= alloc_type (objfile
);
9338 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9339 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9340 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9341 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9342 TYPE_FIELDS (union_type
)
9343 = (struct field
*) TYPE_ZALLOC (union_type
,
9344 (TYPE_NFIELDS (union_type
)
9345 * sizeof (struct field
)));
9347 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9348 TYPE_NFIELDS (type
) * sizeof (struct field
));
9350 /* Install the discriminant at index 0 in the union. */
9351 TYPE_FIELD (union_type
, 0) = *disr_field
;
9352 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9353 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9355 /* Install the union in the outer struct type. */
9356 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9357 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9358 TYPE_NFIELDS (type
) = 1;
9360 /* Set the size and offset of the union type. */
9361 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9363 /* We need a way to find the correct discriminant given a
9364 variant name. For convenience we build a map here. */
9365 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9366 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9367 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9369 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9372 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9373 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9377 int n_fields
= TYPE_NFIELDS (union_type
);
9378 struct discriminant_info
*disc
9379 = alloc_discriminant_info (union_type
, 0, -1);
9380 /* Skip the discriminant here. */
9381 for (int i
= 1; i
< n_fields
; ++i
)
9383 /* Find the final word in the name of this variant's type.
9384 That name can be used to look up the correct
9386 const char *variant_name
9387 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9390 auto iter
= discriminant_map
.find (variant_name
);
9391 if (iter
!= discriminant_map
.end ())
9392 disc
->discriminants
[i
] = iter
->second
;
9394 /* Remove the discriminant field, if it exists. */
9395 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9396 if (TYPE_NFIELDS (sub_type
) > 0)
9398 --TYPE_NFIELDS (sub_type
);
9399 ++TYPE_FIELDS (sub_type
);
9401 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9402 TYPE_NAME (sub_type
)
9403 = rust_fully_qualify (&objfile
->objfile_obstack
,
9404 TYPE_NAME (type
), variant_name
);
9409 /* Rewrite some Rust unions to be structures with variants parts. */
9412 rust_union_quirks (struct dwarf2_cu
*cu
)
9414 gdb_assert (cu
->language
== language_rust
);
9415 for (type
*type_
: cu
->rust_unions
)
9416 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9417 /* We don't need this any more. */
9418 cu
->rust_unions
.clear ();
9421 /* Return the symtab for PER_CU. This works properly regardless of
9422 whether we're using the index or psymtabs. */
9424 static struct compunit_symtab
*
9425 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9427 return (per_cu
->dwarf2_per_objfile
->using_index
9428 ? per_cu
->v
.quick
->compunit_symtab
9429 : per_cu
->v
.psymtab
->compunit_symtab
);
9432 /* A helper function for computing the list of all symbol tables
9433 included by PER_CU. */
9436 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9437 htab_t all_children
, htab_t all_type_symtabs
,
9438 struct dwarf2_per_cu_data
*per_cu
,
9439 struct compunit_symtab
*immediate_parent
)
9442 struct compunit_symtab
*cust
;
9444 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9447 /* This inclusion and its children have been processed. */
9452 /* Only add a CU if it has a symbol table. */
9453 cust
= get_compunit_symtab (per_cu
);
9456 /* If this is a type unit only add its symbol table if we haven't
9457 seen it yet (type unit per_cu's can share symtabs). */
9458 if (per_cu
->is_debug_types
)
9460 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9464 result
->push_back (cust
);
9465 if (cust
->user
== NULL
)
9466 cust
->user
= immediate_parent
;
9471 result
->push_back (cust
);
9472 if (cust
->user
== NULL
)
9473 cust
->user
= immediate_parent
;
9477 if (!per_cu
->imported_symtabs_empty ())
9478 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9480 recursively_compute_inclusions (result
, all_children
,
9481 all_type_symtabs
, ptr
, cust
);
9485 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9489 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9491 gdb_assert (! per_cu
->is_debug_types
);
9493 if (!per_cu
->imported_symtabs_empty ())
9496 std::vector
<compunit_symtab
*> result_symtabs
;
9497 htab_t all_children
, all_type_symtabs
;
9498 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9500 /* If we don't have a symtab, we can just skip this case. */
9504 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9505 NULL
, xcalloc
, xfree
);
9506 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9507 NULL
, xcalloc
, xfree
);
9509 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9511 recursively_compute_inclusions (&result_symtabs
, all_children
,
9512 all_type_symtabs
, ptr
, cust
);
9515 /* Now we have a transitive closure of all the included symtabs. */
9516 len
= result_symtabs
.size ();
9518 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9519 struct compunit_symtab
*, len
+ 1);
9520 memcpy (cust
->includes
, result_symtabs
.data (),
9521 len
* sizeof (compunit_symtab
*));
9522 cust
->includes
[len
] = NULL
;
9524 htab_delete (all_children
);
9525 htab_delete (all_type_symtabs
);
9529 /* Compute the 'includes' field for the symtabs of all the CUs we just
9533 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9535 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9537 if (! iter
->is_debug_types
)
9538 compute_compunit_symtab_includes (iter
);
9541 dwarf2_per_objfile
->just_read_cus
.clear ();
9544 /* Generate full symbol information for PER_CU, whose DIEs have
9545 already been loaded into memory. */
9548 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9549 enum language pretend_language
)
9551 struct dwarf2_cu
*cu
= per_cu
->cu
;
9552 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9553 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9554 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9555 CORE_ADDR lowpc
, highpc
;
9556 struct compunit_symtab
*cust
;
9558 struct block
*static_block
;
9561 baseaddr
= objfile
->text_section_offset ();
9563 /* Clear the list here in case something was left over. */
9564 cu
->method_list
.clear ();
9566 cu
->language
= pretend_language
;
9567 cu
->language_defn
= language_def (cu
->language
);
9569 /* Do line number decoding in read_file_scope () */
9570 process_die (cu
->dies
, cu
);
9572 /* For now fudge the Go package. */
9573 if (cu
->language
== language_go
)
9574 fixup_go_packaging (cu
);
9576 /* Now that we have processed all the DIEs in the CU, all the types
9577 should be complete, and it should now be safe to compute all of the
9579 compute_delayed_physnames (cu
);
9581 if (cu
->language
== language_rust
)
9582 rust_union_quirks (cu
);
9584 /* Some compilers don't define a DW_AT_high_pc attribute for the
9585 compilation unit. If the DW_AT_high_pc is missing, synthesize
9586 it, by scanning the DIE's below the compilation unit. */
9587 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9589 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9590 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9592 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9593 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9594 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9595 addrmap to help ensure it has an accurate map of pc values belonging to
9597 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9599 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9600 SECT_OFF_TEXT (objfile
),
9605 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9607 /* Set symtab language to language from DW_AT_language. If the
9608 compilation is from a C file generated by language preprocessors, do
9609 not set the language if it was already deduced by start_subfile. */
9610 if (!(cu
->language
== language_c
9611 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9612 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9614 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9615 produce DW_AT_location with location lists but it can be possibly
9616 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9617 there were bugs in prologue debug info, fixed later in GCC-4.5
9618 by "unwind info for epilogues" patch (which is not directly related).
9620 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9621 needed, it would be wrong due to missing DW_AT_producer there.
9623 Still one can confuse GDB by using non-standard GCC compilation
9624 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9626 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9627 cust
->locations_valid
= 1;
9629 if (gcc_4_minor
>= 5)
9630 cust
->epilogue_unwind_valid
= 1;
9632 cust
->call_site_htab
= cu
->call_site_htab
;
9635 if (dwarf2_per_objfile
->using_index
)
9636 per_cu
->v
.quick
->compunit_symtab
= cust
;
9639 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9640 pst
->compunit_symtab
= cust
;
9644 /* Push it for inclusion processing later. */
9645 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9647 /* Not needed any more. */
9648 cu
->reset_builder ();
9651 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9652 already been loaded into memory. */
9655 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9656 enum language pretend_language
)
9658 struct dwarf2_cu
*cu
= per_cu
->cu
;
9659 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9661 struct compunit_symtab
*cust
;
9662 struct signatured_type
*sig_type
;
9664 gdb_assert (per_cu
->is_debug_types
);
9665 sig_type
= (struct signatured_type
*) per_cu
;
9667 /* Clear the list here in case something was left over. */
9668 cu
->method_list
.clear ();
9670 cu
->language
= pretend_language
;
9671 cu
->language_defn
= language_def (cu
->language
);
9673 /* The symbol tables are set up in read_type_unit_scope. */
9674 process_die (cu
->dies
, cu
);
9676 /* For now fudge the Go package. */
9677 if (cu
->language
== language_go
)
9678 fixup_go_packaging (cu
);
9680 /* Now that we have processed all the DIEs in the CU, all the types
9681 should be complete, and it should now be safe to compute all of the
9683 compute_delayed_physnames (cu
);
9685 if (cu
->language
== language_rust
)
9686 rust_union_quirks (cu
);
9688 /* TUs share symbol tables.
9689 If this is the first TU to use this symtab, complete the construction
9690 of it with end_expandable_symtab. Otherwise, complete the addition of
9691 this TU's symbols to the existing symtab. */
9692 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9694 buildsym_compunit
*builder
= cu
->get_builder ();
9695 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9696 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9700 /* Set symtab language to language from DW_AT_language. If the
9701 compilation is from a C file generated by language preprocessors,
9702 do not set the language if it was already deduced by
9704 if (!(cu
->language
== language_c
9705 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9706 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9711 cu
->get_builder ()->augment_type_symtab ();
9712 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9715 if (dwarf2_per_objfile
->using_index
)
9716 per_cu
->v
.quick
->compunit_symtab
= cust
;
9719 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9720 pst
->compunit_symtab
= cust
;
9724 /* Not needed any more. */
9725 cu
->reset_builder ();
9728 /* Process an imported unit DIE. */
9731 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9733 struct attribute
*attr
;
9735 /* For now we don't handle imported units in type units. */
9736 if (cu
->per_cu
->is_debug_types
)
9738 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9739 " supported in type units [in module %s]"),
9740 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9743 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9746 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9747 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9748 dwarf2_per_cu_data
*per_cu
9749 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9750 cu
->per_cu
->dwarf2_per_objfile
);
9752 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9753 into another compilation unit, at root level. Regard this as a hint,
9755 if (die
->parent
&& die
->parent
->parent
== NULL
9756 && per_cu
->unit_type
== DW_UT_compile
9757 && per_cu
->lang
== language_cplus
)
9760 /* If necessary, add it to the queue and load its DIEs. */
9761 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9762 load_full_comp_unit (per_cu
, false, cu
->language
);
9764 cu
->per_cu
->imported_symtabs_push (per_cu
);
9768 /* RAII object that represents a process_die scope: i.e.,
9769 starts/finishes processing a DIE. */
9770 class process_die_scope
9773 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9774 : m_die (die
), m_cu (cu
)
9776 /* We should only be processing DIEs not already in process. */
9777 gdb_assert (!m_die
->in_process
);
9778 m_die
->in_process
= true;
9781 ~process_die_scope ()
9783 m_die
->in_process
= false;
9785 /* If we're done processing the DIE for the CU that owns the line
9786 header, we don't need the line header anymore. */
9787 if (m_cu
->line_header_die_owner
== m_die
)
9789 delete m_cu
->line_header
;
9790 m_cu
->line_header
= NULL
;
9791 m_cu
->line_header_die_owner
= NULL
;
9800 /* Process a die and its children. */
9803 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9805 process_die_scope
scope (die
, cu
);
9809 case DW_TAG_padding
:
9811 case DW_TAG_compile_unit
:
9812 case DW_TAG_partial_unit
:
9813 read_file_scope (die
, cu
);
9815 case DW_TAG_type_unit
:
9816 read_type_unit_scope (die
, cu
);
9818 case DW_TAG_subprogram
:
9819 /* Nested subprograms in Fortran get a prefix. */
9820 if (cu
->language
== language_fortran
9821 && die
->parent
!= NULL
9822 && die
->parent
->tag
== DW_TAG_subprogram
)
9823 cu
->processing_has_namespace_info
= true;
9825 case DW_TAG_inlined_subroutine
:
9826 read_func_scope (die
, cu
);
9828 case DW_TAG_lexical_block
:
9829 case DW_TAG_try_block
:
9830 case DW_TAG_catch_block
:
9831 read_lexical_block_scope (die
, cu
);
9833 case DW_TAG_call_site
:
9834 case DW_TAG_GNU_call_site
:
9835 read_call_site_scope (die
, cu
);
9837 case DW_TAG_class_type
:
9838 case DW_TAG_interface_type
:
9839 case DW_TAG_structure_type
:
9840 case DW_TAG_union_type
:
9841 process_structure_scope (die
, cu
);
9843 case DW_TAG_enumeration_type
:
9844 process_enumeration_scope (die
, cu
);
9847 /* These dies have a type, but processing them does not create
9848 a symbol or recurse to process the children. Therefore we can
9849 read them on-demand through read_type_die. */
9850 case DW_TAG_subroutine_type
:
9851 case DW_TAG_set_type
:
9852 case DW_TAG_array_type
:
9853 case DW_TAG_pointer_type
:
9854 case DW_TAG_ptr_to_member_type
:
9855 case DW_TAG_reference_type
:
9856 case DW_TAG_rvalue_reference_type
:
9857 case DW_TAG_string_type
:
9860 case DW_TAG_base_type
:
9861 case DW_TAG_subrange_type
:
9862 case DW_TAG_typedef
:
9863 /* Add a typedef symbol for the type definition, if it has a
9865 new_symbol (die
, read_type_die (die
, cu
), cu
);
9867 case DW_TAG_common_block
:
9868 read_common_block (die
, cu
);
9870 case DW_TAG_common_inclusion
:
9872 case DW_TAG_namespace
:
9873 cu
->processing_has_namespace_info
= true;
9874 read_namespace (die
, cu
);
9877 cu
->processing_has_namespace_info
= true;
9878 read_module (die
, cu
);
9880 case DW_TAG_imported_declaration
:
9881 cu
->processing_has_namespace_info
= true;
9882 if (read_namespace_alias (die
, cu
))
9884 /* The declaration is not a global namespace alias. */
9886 case DW_TAG_imported_module
:
9887 cu
->processing_has_namespace_info
= true;
9888 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9889 || cu
->language
!= language_fortran
))
9890 complaint (_("Tag '%s' has unexpected children"),
9891 dwarf_tag_name (die
->tag
));
9892 read_import_statement (die
, cu
);
9895 case DW_TAG_imported_unit
:
9896 process_imported_unit_die (die
, cu
);
9899 case DW_TAG_variable
:
9900 read_variable (die
, cu
);
9904 new_symbol (die
, NULL
, cu
);
9909 /* DWARF name computation. */
9911 /* A helper function for dwarf2_compute_name which determines whether DIE
9912 needs to have the name of the scope prepended to the name listed in the
9916 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9918 struct attribute
*attr
;
9922 case DW_TAG_namespace
:
9923 case DW_TAG_typedef
:
9924 case DW_TAG_class_type
:
9925 case DW_TAG_interface_type
:
9926 case DW_TAG_structure_type
:
9927 case DW_TAG_union_type
:
9928 case DW_TAG_enumeration_type
:
9929 case DW_TAG_enumerator
:
9930 case DW_TAG_subprogram
:
9931 case DW_TAG_inlined_subroutine
:
9933 case DW_TAG_imported_declaration
:
9936 case DW_TAG_variable
:
9937 case DW_TAG_constant
:
9938 /* We only need to prefix "globally" visible variables. These include
9939 any variable marked with DW_AT_external or any variable that
9940 lives in a namespace. [Variables in anonymous namespaces
9941 require prefixing, but they are not DW_AT_external.] */
9943 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9945 struct dwarf2_cu
*spec_cu
= cu
;
9947 return die_needs_namespace (die_specification (die
, &spec_cu
),
9951 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9952 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9953 && die
->parent
->tag
!= DW_TAG_module
)
9955 /* A variable in a lexical block of some kind does not need a
9956 namespace, even though in C++ such variables may be external
9957 and have a mangled name. */
9958 if (die
->parent
->tag
== DW_TAG_lexical_block
9959 || die
->parent
->tag
== DW_TAG_try_block
9960 || die
->parent
->tag
== DW_TAG_catch_block
9961 || die
->parent
->tag
== DW_TAG_subprogram
)
9970 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9971 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9972 defined for the given DIE. */
9974 static struct attribute
*
9975 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9977 struct attribute
*attr
;
9979 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9981 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9986 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9987 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9988 defined for the given DIE. */
9991 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9993 const char *linkage_name
;
9995 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9996 if (linkage_name
== NULL
)
9997 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9999 return linkage_name
;
10002 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10003 compute the physname for the object, which include a method's:
10004 - formal parameters (C++),
10005 - receiver type (Go),
10007 The term "physname" is a bit confusing.
10008 For C++, for example, it is the demangled name.
10009 For Go, for example, it's the mangled name.
10011 For Ada, return the DIE's linkage name rather than the fully qualified
10012 name. PHYSNAME is ignored..
10014 The result is allocated on the objfile_obstack and canonicalized. */
10016 static const char *
10017 dwarf2_compute_name (const char *name
,
10018 struct die_info
*die
, struct dwarf2_cu
*cu
,
10021 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10024 name
= dwarf2_name (die
, cu
);
10026 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10027 but otherwise compute it by typename_concat inside GDB.
10028 FIXME: Actually this is not really true, or at least not always true.
10029 It's all very confusing. compute_and_set_names doesn't try to demangle
10030 Fortran names because there is no mangling standard. So new_symbol
10031 will set the demangled name to the result of dwarf2_full_name, and it is
10032 the demangled name that GDB uses if it exists. */
10033 if (cu
->language
== language_ada
10034 || (cu
->language
== language_fortran
&& physname
))
10036 /* For Ada unit, we prefer the linkage name over the name, as
10037 the former contains the exported name, which the user expects
10038 to be able to reference. Ideally, we want the user to be able
10039 to reference this entity using either natural or linkage name,
10040 but we haven't started looking at this enhancement yet. */
10041 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10043 if (linkage_name
!= NULL
)
10044 return linkage_name
;
10047 /* These are the only languages we know how to qualify names in. */
10049 && (cu
->language
== language_cplus
10050 || cu
->language
== language_fortran
|| cu
->language
== language_d
10051 || cu
->language
== language_rust
))
10053 if (die_needs_namespace (die
, cu
))
10055 const char *prefix
;
10056 const char *canonical_name
= NULL
;
10060 prefix
= determine_prefix (die
, cu
);
10061 if (*prefix
!= '\0')
10063 gdb::unique_xmalloc_ptr
<char> prefixed_name
10064 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10066 buf
.puts (prefixed_name
.get ());
10071 /* Template parameters may be specified in the DIE's DW_AT_name, or
10072 as children with DW_TAG_template_type_param or
10073 DW_TAG_value_type_param. If the latter, add them to the name
10074 here. If the name already has template parameters, then
10075 skip this step; some versions of GCC emit both, and
10076 it is more efficient to use the pre-computed name.
10078 Something to keep in mind about this process: it is very
10079 unlikely, or in some cases downright impossible, to produce
10080 something that will match the mangled name of a function.
10081 If the definition of the function has the same debug info,
10082 we should be able to match up with it anyway. But fallbacks
10083 using the minimal symbol, for instance to find a method
10084 implemented in a stripped copy of libstdc++, will not work.
10085 If we do not have debug info for the definition, we will have to
10086 match them up some other way.
10088 When we do name matching there is a related problem with function
10089 templates; two instantiated function templates are allowed to
10090 differ only by their return types, which we do not add here. */
10092 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10094 struct attribute
*attr
;
10095 struct die_info
*child
;
10098 die
->building_fullname
= 1;
10100 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10104 const gdb_byte
*bytes
;
10105 struct dwarf2_locexpr_baton
*baton
;
10108 if (child
->tag
!= DW_TAG_template_type_param
10109 && child
->tag
!= DW_TAG_template_value_param
)
10120 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10123 complaint (_("template parameter missing DW_AT_type"));
10124 buf
.puts ("UNKNOWN_TYPE");
10127 type
= die_type (child
, cu
);
10129 if (child
->tag
== DW_TAG_template_type_param
)
10131 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10132 &type_print_raw_options
);
10136 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10139 complaint (_("template parameter missing "
10140 "DW_AT_const_value"));
10141 buf
.puts ("UNKNOWN_VALUE");
10145 dwarf2_const_value_attr (attr
, type
, name
,
10146 &cu
->comp_unit_obstack
, cu
,
10147 &value
, &bytes
, &baton
);
10149 if (TYPE_NOSIGN (type
))
10150 /* GDB prints characters as NUMBER 'CHAR'. If that's
10151 changed, this can use value_print instead. */
10152 c_printchar (value
, type
, &buf
);
10155 struct value_print_options opts
;
10158 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10162 else if (bytes
!= NULL
)
10164 v
= allocate_value (type
);
10165 memcpy (value_contents_writeable (v
), bytes
,
10166 TYPE_LENGTH (type
));
10169 v
= value_from_longest (type
, value
);
10171 /* Specify decimal so that we do not depend on
10173 get_formatted_print_options (&opts
, 'd');
10175 value_print (v
, &buf
, &opts
);
10180 die
->building_fullname
= 0;
10184 /* Close the argument list, with a space if necessary
10185 (nested templates). */
10186 if (!buf
.empty () && buf
.string ().back () == '>')
10193 /* For C++ methods, append formal parameter type
10194 information, if PHYSNAME. */
10196 if (physname
&& die
->tag
== DW_TAG_subprogram
10197 && cu
->language
== language_cplus
)
10199 struct type
*type
= read_type_die (die
, cu
);
10201 c_type_print_args (type
, &buf
, 1, cu
->language
,
10202 &type_print_raw_options
);
10204 if (cu
->language
== language_cplus
)
10206 /* Assume that an artificial first parameter is
10207 "this", but do not crash if it is not. RealView
10208 marks unnamed (and thus unused) parameters as
10209 artificial; there is no way to differentiate
10211 if (TYPE_NFIELDS (type
) > 0
10212 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10213 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10214 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10216 buf
.puts (" const");
10220 const std::string
&intermediate_name
= buf
.string ();
10222 if (cu
->language
== language_cplus
)
10224 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10227 /* If we only computed INTERMEDIATE_NAME, or if
10228 INTERMEDIATE_NAME is already canonical, then we need to
10230 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10231 name
= objfile
->intern (intermediate_name
);
10233 name
= canonical_name
;
10240 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10241 If scope qualifiers are appropriate they will be added. The result
10242 will be allocated on the storage_obstack, or NULL if the DIE does
10243 not have a name. NAME may either be from a previous call to
10244 dwarf2_name or NULL.
10246 The output string will be canonicalized (if C++). */
10248 static const char *
10249 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10251 return dwarf2_compute_name (name
, die
, cu
, 0);
10254 /* Construct a physname for the given DIE in CU. NAME may either be
10255 from a previous call to dwarf2_name or NULL. The result will be
10256 allocated on the objfile_objstack or NULL if the DIE does not have a
10259 The output string will be canonicalized (if C++). */
10261 static const char *
10262 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10264 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10265 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10268 /* In this case dwarf2_compute_name is just a shortcut not building anything
10270 if (!die_needs_namespace (die
, cu
))
10271 return dwarf2_compute_name (name
, die
, cu
, 1);
10273 mangled
= dw2_linkage_name (die
, cu
);
10275 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10276 See https://github.com/rust-lang/rust/issues/32925. */
10277 if (cu
->language
== language_rust
&& mangled
!= NULL
10278 && strchr (mangled
, '{') != NULL
)
10281 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10283 gdb::unique_xmalloc_ptr
<char> demangled
;
10284 if (mangled
!= NULL
)
10287 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10289 /* Do nothing (do not demangle the symbol name). */
10291 else if (cu
->language
== language_go
)
10293 /* This is a lie, but we already lie to the caller new_symbol.
10294 new_symbol assumes we return the mangled name.
10295 This just undoes that lie until things are cleaned up. */
10299 /* Use DMGL_RET_DROP for C++ template functions to suppress
10300 their return type. It is easier for GDB users to search
10301 for such functions as `name(params)' than `long name(params)'.
10302 In such case the minimal symbol names do not match the full
10303 symbol names but for template functions there is never a need
10304 to look up their definition from their declaration so
10305 the only disadvantage remains the minimal symbol variant
10306 `long name(params)' does not have the proper inferior type. */
10307 demangled
.reset (gdb_demangle (mangled
,
10308 (DMGL_PARAMS
| DMGL_ANSI
10309 | DMGL_RET_DROP
)));
10312 canon
= demangled
.get ();
10320 if (canon
== NULL
|| check_physname
)
10322 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10324 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10326 /* It may not mean a bug in GDB. The compiler could also
10327 compute DW_AT_linkage_name incorrectly. But in such case
10328 GDB would need to be bug-to-bug compatible. */
10330 complaint (_("Computed physname <%s> does not match demangled <%s> "
10331 "(from linkage <%s>) - DIE at %s [in module %s]"),
10332 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10333 objfile_name (objfile
));
10335 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10336 is available here - over computed PHYSNAME. It is safer
10337 against both buggy GDB and buggy compilers. */
10351 retval
= objfile
->intern (retval
);
10356 /* Inspect DIE in CU for a namespace alias. If one exists, record
10357 a new symbol for it.
10359 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10362 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10364 struct attribute
*attr
;
10366 /* If the die does not have a name, this is not a namespace
10368 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10372 struct die_info
*d
= die
;
10373 struct dwarf2_cu
*imported_cu
= cu
;
10375 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10376 keep inspecting DIEs until we hit the underlying import. */
10377 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10378 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10380 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10384 d
= follow_die_ref (d
, attr
, &imported_cu
);
10385 if (d
->tag
!= DW_TAG_imported_declaration
)
10389 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10391 complaint (_("DIE at %s has too many recursively imported "
10392 "declarations"), sect_offset_str (d
->sect_off
));
10399 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10401 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10402 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10404 /* This declaration is a global namespace alias. Add
10405 a symbol for it whose type is the aliased namespace. */
10406 new_symbol (die
, type
, cu
);
10415 /* Return the using directives repository (global or local?) to use in the
10416 current context for CU.
10418 For Ada, imported declarations can materialize renamings, which *may* be
10419 global. However it is impossible (for now?) in DWARF to distinguish
10420 "external" imported declarations and "static" ones. As all imported
10421 declarations seem to be static in all other languages, make them all CU-wide
10422 global only in Ada. */
10424 static struct using_direct
**
10425 using_directives (struct dwarf2_cu
*cu
)
10427 if (cu
->language
== language_ada
10428 && cu
->get_builder ()->outermost_context_p ())
10429 return cu
->get_builder ()->get_global_using_directives ();
10431 return cu
->get_builder ()->get_local_using_directives ();
10434 /* Read the import statement specified by the given die and record it. */
10437 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10439 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10440 struct attribute
*import_attr
;
10441 struct die_info
*imported_die
, *child_die
;
10442 struct dwarf2_cu
*imported_cu
;
10443 const char *imported_name
;
10444 const char *imported_name_prefix
;
10445 const char *canonical_name
;
10446 const char *import_alias
;
10447 const char *imported_declaration
= NULL
;
10448 const char *import_prefix
;
10449 std::vector
<const char *> excludes
;
10451 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10452 if (import_attr
== NULL
)
10454 complaint (_("Tag '%s' has no DW_AT_import"),
10455 dwarf_tag_name (die
->tag
));
10460 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10461 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10462 if (imported_name
== NULL
)
10464 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10466 The import in the following code:
10480 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10481 <52> DW_AT_decl_file : 1
10482 <53> DW_AT_decl_line : 6
10483 <54> DW_AT_import : <0x75>
10484 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10485 <59> DW_AT_name : B
10486 <5b> DW_AT_decl_file : 1
10487 <5c> DW_AT_decl_line : 2
10488 <5d> DW_AT_type : <0x6e>
10490 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10491 <76> DW_AT_byte_size : 4
10492 <77> DW_AT_encoding : 5 (signed)
10494 imports the wrong die ( 0x75 instead of 0x58 ).
10495 This case will be ignored until the gcc bug is fixed. */
10499 /* Figure out the local name after import. */
10500 import_alias
= dwarf2_name (die
, cu
);
10502 /* Figure out where the statement is being imported to. */
10503 import_prefix
= determine_prefix (die
, cu
);
10505 /* Figure out what the scope of the imported die is and prepend it
10506 to the name of the imported die. */
10507 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10509 if (imported_die
->tag
!= DW_TAG_namespace
10510 && imported_die
->tag
!= DW_TAG_module
)
10512 imported_declaration
= imported_name
;
10513 canonical_name
= imported_name_prefix
;
10515 else if (strlen (imported_name_prefix
) > 0)
10516 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10517 imported_name_prefix
,
10518 (cu
->language
== language_d
? "." : "::"),
10519 imported_name
, (char *) NULL
);
10521 canonical_name
= imported_name
;
10523 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10524 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10525 child_die
= sibling_die (child_die
))
10527 /* DWARF-4: A Fortran use statement with a “rename list” may be
10528 represented by an imported module entry with an import attribute
10529 referring to the module and owned entries corresponding to those
10530 entities that are renamed as part of being imported. */
10532 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10534 complaint (_("child DW_TAG_imported_declaration expected "
10535 "- DIE at %s [in module %s]"),
10536 sect_offset_str (child_die
->sect_off
),
10537 objfile_name (objfile
));
10541 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10542 if (import_attr
== NULL
)
10544 complaint (_("Tag '%s' has no DW_AT_import"),
10545 dwarf_tag_name (child_die
->tag
));
10550 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10552 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10553 if (imported_name
== NULL
)
10555 complaint (_("child DW_TAG_imported_declaration has unknown "
10556 "imported name - DIE at %s [in module %s]"),
10557 sect_offset_str (child_die
->sect_off
),
10558 objfile_name (objfile
));
10562 excludes
.push_back (imported_name
);
10564 process_die (child_die
, cu
);
10567 add_using_directive (using_directives (cu
),
10571 imported_declaration
,
10574 &objfile
->objfile_obstack
);
10577 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10578 types, but gives them a size of zero. Starting with version 14,
10579 ICC is compatible with GCC. */
10582 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10584 if (!cu
->checked_producer
)
10585 check_producer (cu
);
10587 return cu
->producer_is_icc_lt_14
;
10590 /* ICC generates a DW_AT_type for C void functions. This was observed on
10591 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10592 which says that void functions should not have a DW_AT_type. */
10595 producer_is_icc (struct dwarf2_cu
*cu
)
10597 if (!cu
->checked_producer
)
10598 check_producer (cu
);
10600 return cu
->producer_is_icc
;
10603 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10604 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10605 this, it was first present in GCC release 4.3.0. */
10608 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10610 if (!cu
->checked_producer
)
10611 check_producer (cu
);
10613 return cu
->producer_is_gcc_lt_4_3
;
10616 static file_and_directory
10617 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10619 file_and_directory res
;
10621 /* Find the filename. Do not use dwarf2_name here, since the filename
10622 is not a source language identifier. */
10623 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10624 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10626 if (res
.comp_dir
== NULL
10627 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10628 && IS_ABSOLUTE_PATH (res
.name
))
10630 res
.comp_dir_storage
= ldirname (res
.name
);
10631 if (!res
.comp_dir_storage
.empty ())
10632 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10634 if (res
.comp_dir
!= NULL
)
10636 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10637 directory, get rid of it. */
10638 const char *cp
= strchr (res
.comp_dir
, ':');
10640 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10641 res
.comp_dir
= cp
+ 1;
10644 if (res
.name
== NULL
)
10645 res
.name
= "<unknown>";
10650 /* Handle DW_AT_stmt_list for a compilation unit.
10651 DIE is the DW_TAG_compile_unit die for CU.
10652 COMP_DIR is the compilation directory. LOWPC is passed to
10653 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10656 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10657 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10659 struct dwarf2_per_objfile
*dwarf2_per_objfile
10660 = cu
->per_cu
->dwarf2_per_objfile
;
10661 struct attribute
*attr
;
10662 struct line_header line_header_local
;
10663 hashval_t line_header_local_hash
;
10665 int decode_mapping
;
10667 gdb_assert (! cu
->per_cu
->is_debug_types
);
10669 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10673 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10675 /* The line header hash table is only created if needed (it exists to
10676 prevent redundant reading of the line table for partial_units).
10677 If we're given a partial_unit, we'll need it. If we're given a
10678 compile_unit, then use the line header hash table if it's already
10679 created, but don't create one just yet. */
10681 if (dwarf2_per_objfile
->line_header_hash
== NULL
10682 && die
->tag
== DW_TAG_partial_unit
)
10684 dwarf2_per_objfile
->line_header_hash
10685 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10686 line_header_eq_voidp
,
10687 free_line_header_voidp
,
10691 line_header_local
.sect_off
= line_offset
;
10692 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10693 line_header_local_hash
= line_header_hash (&line_header_local
);
10694 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10696 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10697 &line_header_local
,
10698 line_header_local_hash
, NO_INSERT
);
10700 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10701 is not present in *SLOT (since if there is something in *SLOT then
10702 it will be for a partial_unit). */
10703 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10705 gdb_assert (*slot
!= NULL
);
10706 cu
->line_header
= (struct line_header
*) *slot
;
10711 /* dwarf_decode_line_header does not yet provide sufficient information.
10712 We always have to call also dwarf_decode_lines for it. */
10713 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10717 cu
->line_header
= lh
.release ();
10718 cu
->line_header_die_owner
= die
;
10720 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10724 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10725 &line_header_local
,
10726 line_header_local_hash
, INSERT
);
10727 gdb_assert (slot
!= NULL
);
10729 if (slot
!= NULL
&& *slot
== NULL
)
10731 /* This newly decoded line number information unit will be owned
10732 by line_header_hash hash table. */
10733 *slot
= cu
->line_header
;
10734 cu
->line_header_die_owner
= NULL
;
10738 /* We cannot free any current entry in (*slot) as that struct line_header
10739 may be already used by multiple CUs. Create only temporary decoded
10740 line_header for this CU - it may happen at most once for each line
10741 number information unit. And if we're not using line_header_hash
10742 then this is what we want as well. */
10743 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10745 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10746 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10751 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10754 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10756 struct dwarf2_per_objfile
*dwarf2_per_objfile
10757 = cu
->per_cu
->dwarf2_per_objfile
;
10758 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10759 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10760 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10761 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10762 struct attribute
*attr
;
10763 struct die_info
*child_die
;
10764 CORE_ADDR baseaddr
;
10766 prepare_one_comp_unit (cu
, die
, cu
->language
);
10767 baseaddr
= objfile
->text_section_offset ();
10769 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10771 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10772 from finish_block. */
10773 if (lowpc
== ((CORE_ADDR
) -1))
10775 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10777 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10779 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10780 standardised yet. As a workaround for the language detection we fall
10781 back to the DW_AT_producer string. */
10782 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10783 cu
->language
= language_opencl
;
10785 /* Similar hack for Go. */
10786 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10787 set_cu_language (DW_LANG_Go
, cu
);
10789 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10791 /* Decode line number information if present. We do this before
10792 processing child DIEs, so that the line header table is available
10793 for DW_AT_decl_file. */
10794 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10796 /* Process all dies in compilation unit. */
10797 if (die
->child
!= NULL
)
10799 child_die
= die
->child
;
10800 while (child_die
&& child_die
->tag
)
10802 process_die (child_die
, cu
);
10803 child_die
= sibling_die (child_die
);
10807 /* Decode macro information, if present. Dwarf 2 macro information
10808 refers to information in the line number info statement program
10809 header, so we can only read it if we've read the header
10811 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10813 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10814 if (attr
&& cu
->line_header
)
10816 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10817 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10819 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10823 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10824 if (attr
&& cu
->line_header
)
10826 unsigned int macro_offset
= DW_UNSND (attr
);
10828 dwarf_decode_macros (cu
, macro_offset
, 0);
10834 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10836 struct type_unit_group
*tu_group
;
10838 struct attribute
*attr
;
10840 struct signatured_type
*sig_type
;
10842 gdb_assert (per_cu
->is_debug_types
);
10843 sig_type
= (struct signatured_type
*) per_cu
;
10845 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10847 /* If we're using .gdb_index (includes -readnow) then
10848 per_cu->type_unit_group may not have been set up yet. */
10849 if (sig_type
->type_unit_group
== NULL
)
10850 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10851 tu_group
= sig_type
->type_unit_group
;
10853 /* If we've already processed this stmt_list there's no real need to
10854 do it again, we could fake it and just recreate the part we need
10855 (file name,index -> symtab mapping). If data shows this optimization
10856 is useful we can do it then. */
10857 first_time
= tu_group
->compunit_symtab
== NULL
;
10859 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10864 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10865 lh
= dwarf_decode_line_header (line_offset
, this);
10870 start_symtab ("", NULL
, 0);
10873 gdb_assert (tu_group
->symtabs
== NULL
);
10874 gdb_assert (m_builder
== nullptr);
10875 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10876 m_builder
.reset (new struct buildsym_compunit
10877 (COMPUNIT_OBJFILE (cust
), "",
10878 COMPUNIT_DIRNAME (cust
),
10879 compunit_language (cust
),
10885 line_header
= lh
.release ();
10886 line_header_die_owner
= die
;
10890 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10892 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10893 still initializing it, and our caller (a few levels up)
10894 process_full_type_unit still needs to know if this is the first
10898 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10899 struct symtab
*, line_header
->file_names_size ());
10901 auto &file_names
= line_header
->file_names ();
10902 for (i
= 0; i
< file_names
.size (); ++i
)
10904 file_entry
&fe
= file_names
[i
];
10905 dwarf2_start_subfile (this, fe
.name
,
10906 fe
.include_dir (line_header
));
10907 buildsym_compunit
*b
= get_builder ();
10908 if (b
->get_current_subfile ()->symtab
== NULL
)
10910 /* NOTE: start_subfile will recognize when it's been
10911 passed a file it has already seen. So we can't
10912 assume there's a simple mapping from
10913 cu->line_header->file_names to subfiles, plus
10914 cu->line_header->file_names may contain dups. */
10915 b
->get_current_subfile ()->symtab
10916 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10919 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10920 tu_group
->symtabs
[i
] = fe
.symtab
;
10925 gdb_assert (m_builder
== nullptr);
10926 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10927 m_builder
.reset (new struct buildsym_compunit
10928 (COMPUNIT_OBJFILE (cust
), "",
10929 COMPUNIT_DIRNAME (cust
),
10930 compunit_language (cust
),
10933 auto &file_names
= line_header
->file_names ();
10934 for (i
= 0; i
< file_names
.size (); ++i
)
10936 file_entry
&fe
= file_names
[i
];
10937 fe
.symtab
= tu_group
->symtabs
[i
];
10941 /* The main symtab is allocated last. Type units don't have DW_AT_name
10942 so they don't have a "real" (so to speak) symtab anyway.
10943 There is later code that will assign the main symtab to all symbols
10944 that don't have one. We need to handle the case of a symbol with a
10945 missing symtab (DW_AT_decl_file) anyway. */
10948 /* Process DW_TAG_type_unit.
10949 For TUs we want to skip the first top level sibling if it's not the
10950 actual type being defined by this TU. In this case the first top
10951 level sibling is there to provide context only. */
10954 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10956 struct die_info
*child_die
;
10958 prepare_one_comp_unit (cu
, die
, language_minimal
);
10960 /* Initialize (or reinitialize) the machinery for building symtabs.
10961 We do this before processing child DIEs, so that the line header table
10962 is available for DW_AT_decl_file. */
10963 cu
->setup_type_unit_groups (die
);
10965 if (die
->child
!= NULL
)
10967 child_die
= die
->child
;
10968 while (child_die
&& child_die
->tag
)
10970 process_die (child_die
, cu
);
10971 child_die
= sibling_die (child_die
);
10978 http://gcc.gnu.org/wiki/DebugFission
10979 http://gcc.gnu.org/wiki/DebugFissionDWP
10981 To simplify handling of both DWO files ("object" files with the DWARF info)
10982 and DWP files (a file with the DWOs packaged up into one file), we treat
10983 DWP files as having a collection of virtual DWO files. */
10986 hash_dwo_file (const void *item
)
10988 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10991 hash
= htab_hash_string (dwo_file
->dwo_name
);
10992 if (dwo_file
->comp_dir
!= NULL
)
10993 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10998 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11000 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11001 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11003 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11005 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11006 return lhs
->comp_dir
== rhs
->comp_dir
;
11007 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11010 /* Allocate a hash table for DWO files. */
11013 allocate_dwo_file_hash_table ()
11015 auto delete_dwo_file
= [] (void *item
)
11017 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11022 return htab_up (htab_create_alloc (41,
11029 /* Lookup DWO file DWO_NAME. */
11032 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11033 const char *dwo_name
,
11034 const char *comp_dir
)
11036 struct dwo_file find_entry
;
11039 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11040 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11042 find_entry
.dwo_name
= dwo_name
;
11043 find_entry
.comp_dir
= comp_dir
;
11044 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11051 hash_dwo_unit (const void *item
)
11053 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11055 /* This drops the top 32 bits of the id, but is ok for a hash. */
11056 return dwo_unit
->signature
;
11060 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11062 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11063 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11065 /* The signature is assumed to be unique within the DWO file.
11066 So while object file CU dwo_id's always have the value zero,
11067 that's OK, assuming each object file DWO file has only one CU,
11068 and that's the rule for now. */
11069 return lhs
->signature
== rhs
->signature
;
11072 /* Allocate a hash table for DWO CUs,TUs.
11073 There is one of these tables for each of CUs,TUs for each DWO file. */
11076 allocate_dwo_unit_table ()
11078 /* Start out with a pretty small number.
11079 Generally DWO files contain only one CU and maybe some TUs. */
11080 return htab_up (htab_create_alloc (3,
11083 NULL
, xcalloc
, xfree
));
11086 /* die_reader_func for create_dwo_cu. */
11089 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11090 const gdb_byte
*info_ptr
,
11091 struct die_info
*comp_unit_die
,
11092 struct dwo_file
*dwo_file
,
11093 struct dwo_unit
*dwo_unit
)
11095 struct dwarf2_cu
*cu
= reader
->cu
;
11096 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11097 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11099 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11100 if (!signature
.has_value ())
11102 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11103 " its dwo_id [in module %s]"),
11104 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11108 dwo_unit
->dwo_file
= dwo_file
;
11109 dwo_unit
->signature
= *signature
;
11110 dwo_unit
->section
= section
;
11111 dwo_unit
->sect_off
= sect_off
;
11112 dwo_unit
->length
= cu
->per_cu
->length
;
11114 if (dwarf_read_debug
)
11115 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11116 sect_offset_str (sect_off
),
11117 hex_string (dwo_unit
->signature
));
11120 /* Create the dwo_units for the CUs in a DWO_FILE.
11121 Note: This function processes DWO files only, not DWP files. */
11124 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11125 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11126 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11129 const gdb_byte
*info_ptr
, *end_ptr
;
11131 section
.read (objfile
);
11132 info_ptr
= section
.buffer
;
11134 if (info_ptr
== NULL
)
11137 if (dwarf_read_debug
)
11139 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11140 section
.get_name (),
11141 section
.get_file_name ());
11144 end_ptr
= info_ptr
+ section
.size
;
11145 while (info_ptr
< end_ptr
)
11147 struct dwarf2_per_cu_data per_cu
;
11148 struct dwo_unit read_unit
{};
11149 struct dwo_unit
*dwo_unit
;
11151 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11153 memset (&per_cu
, 0, sizeof (per_cu
));
11154 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11155 per_cu
.is_debug_types
= 0;
11156 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11157 per_cu
.section
= §ion
;
11159 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11160 if (!reader
.dummy_p
)
11161 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11162 &dwo_file
, &read_unit
);
11163 info_ptr
+= per_cu
.length
;
11165 // If the unit could not be parsed, skip it.
11166 if (read_unit
.dwo_file
== NULL
)
11169 if (cus_htab
== NULL
)
11170 cus_htab
= allocate_dwo_unit_table ();
11172 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11173 *dwo_unit
= read_unit
;
11174 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11175 gdb_assert (slot
!= NULL
);
11178 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11179 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11181 complaint (_("debug cu entry at offset %s is duplicate to"
11182 " the entry at offset %s, signature %s"),
11183 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11184 hex_string (dwo_unit
->signature
));
11186 *slot
= (void *)dwo_unit
;
11190 /* DWP file .debug_{cu,tu}_index section format:
11191 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11195 Both index sections have the same format, and serve to map a 64-bit
11196 signature to a set of section numbers. Each section begins with a header,
11197 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11198 indexes, and a pool of 32-bit section numbers. The index sections will be
11199 aligned at 8-byte boundaries in the file.
11201 The index section header consists of:
11203 V, 32 bit version number
11205 N, 32 bit number of compilation units or type units in the index
11206 M, 32 bit number of slots in the hash table
11208 Numbers are recorded using the byte order of the application binary.
11210 The hash table begins at offset 16 in the section, and consists of an array
11211 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11212 order of the application binary). Unused slots in the hash table are 0.
11213 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11215 The parallel table begins immediately after the hash table
11216 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11217 array of 32-bit indexes (using the byte order of the application binary),
11218 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11219 table contains a 32-bit index into the pool of section numbers. For unused
11220 hash table slots, the corresponding entry in the parallel table will be 0.
11222 The pool of section numbers begins immediately following the hash table
11223 (at offset 16 + 12 * M from the beginning of the section). The pool of
11224 section numbers consists of an array of 32-bit words (using the byte order
11225 of the application binary). Each item in the array is indexed starting
11226 from 0. The hash table entry provides the index of the first section
11227 number in the set. Additional section numbers in the set follow, and the
11228 set is terminated by a 0 entry (section number 0 is not used in ELF).
11230 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11231 section must be the first entry in the set, and the .debug_abbrev.dwo must
11232 be the second entry. Other members of the set may follow in any order.
11238 DWP Version 2 combines all the .debug_info, etc. sections into one,
11239 and the entries in the index tables are now offsets into these sections.
11240 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11243 Index Section Contents:
11245 Hash Table of Signatures dwp_hash_table.hash_table
11246 Parallel Table of Indices dwp_hash_table.unit_table
11247 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11248 Table of Section Sizes dwp_hash_table.v2.sizes
11250 The index section header consists of:
11252 V, 32 bit version number
11253 L, 32 bit number of columns in the table of section offsets
11254 N, 32 bit number of compilation units or type units in the index
11255 M, 32 bit number of slots in the hash table
11257 Numbers are recorded using the byte order of the application binary.
11259 The hash table has the same format as version 1.
11260 The parallel table of indices has the same format as version 1,
11261 except that the entries are origin-1 indices into the table of sections
11262 offsets and the table of section sizes.
11264 The table of offsets begins immediately following the parallel table
11265 (at offset 16 + 12 * M from the beginning of the section). The table is
11266 a two-dimensional array of 32-bit words (using the byte order of the
11267 application binary), with L columns and N+1 rows, in row-major order.
11268 Each row in the array is indexed starting from 0. The first row provides
11269 a key to the remaining rows: each column in this row provides an identifier
11270 for a debug section, and the offsets in the same column of subsequent rows
11271 refer to that section. The section identifiers are:
11273 DW_SECT_INFO 1 .debug_info.dwo
11274 DW_SECT_TYPES 2 .debug_types.dwo
11275 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11276 DW_SECT_LINE 4 .debug_line.dwo
11277 DW_SECT_LOC 5 .debug_loc.dwo
11278 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11279 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11280 DW_SECT_MACRO 8 .debug_macro.dwo
11282 The offsets provided by the CU and TU index sections are the base offsets
11283 for the contributions made by each CU or TU to the corresponding section
11284 in the package file. Each CU and TU header contains an abbrev_offset
11285 field, used to find the abbreviations table for that CU or TU within the
11286 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11287 be interpreted as relative to the base offset given in the index section.
11288 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11289 should be interpreted as relative to the base offset for .debug_line.dwo,
11290 and offsets into other debug sections obtained from DWARF attributes should
11291 also be interpreted as relative to the corresponding base offset.
11293 The table of sizes begins immediately following the table of offsets.
11294 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11295 with L columns and N rows, in row-major order. Each row in the array is
11296 indexed starting from 1 (row 0 is shared by the two tables).
11300 Hash table lookup is handled the same in version 1 and 2:
11302 We assume that N and M will not exceed 2^32 - 1.
11303 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11305 Given a 64-bit compilation unit signature or a type signature S, an entry
11306 in the hash table is located as follows:
11308 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11309 the low-order k bits all set to 1.
11311 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11313 3) If the hash table entry at index H matches the signature, use that
11314 entry. If the hash table entry at index H is unused (all zeroes),
11315 terminate the search: the signature is not present in the table.
11317 4) Let H = (H + H') modulo M. Repeat at Step 3.
11319 Because M > N and H' and M are relatively prime, the search is guaranteed
11320 to stop at an unused slot or find the match. */
11322 /* Create a hash table to map DWO IDs to their CU/TU entry in
11323 .debug_{info,types}.dwo in DWP_FILE.
11324 Returns NULL if there isn't one.
11325 Note: This function processes DWP files only, not DWO files. */
11327 static struct dwp_hash_table
*
11328 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11329 struct dwp_file
*dwp_file
, int is_debug_types
)
11331 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11332 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11333 const gdb_byte
*index_ptr
, *index_end
;
11334 struct dwarf2_section_info
*index
;
11335 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11336 struct dwp_hash_table
*htab
;
11338 if (is_debug_types
)
11339 index
= &dwp_file
->sections
.tu_index
;
11341 index
= &dwp_file
->sections
.cu_index
;
11343 if (index
->empty ())
11345 index
->read (objfile
);
11347 index_ptr
= index
->buffer
;
11348 index_end
= index_ptr
+ index
->size
;
11350 version
= read_4_bytes (dbfd
, index_ptr
);
11353 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11357 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11359 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11362 if (version
!= 1 && version
!= 2)
11364 error (_("Dwarf Error: unsupported DWP file version (%s)"
11365 " [in module %s]"),
11366 pulongest (version
), dwp_file
->name
);
11368 if (nr_slots
!= (nr_slots
& -nr_slots
))
11370 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11371 " is not power of 2 [in module %s]"),
11372 pulongest (nr_slots
), dwp_file
->name
);
11375 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11376 htab
->version
= version
;
11377 htab
->nr_columns
= nr_columns
;
11378 htab
->nr_units
= nr_units
;
11379 htab
->nr_slots
= nr_slots
;
11380 htab
->hash_table
= index_ptr
;
11381 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11383 /* Exit early if the table is empty. */
11384 if (nr_slots
== 0 || nr_units
== 0
11385 || (version
== 2 && nr_columns
== 0))
11387 /* All must be zero. */
11388 if (nr_slots
!= 0 || nr_units
!= 0
11389 || (version
== 2 && nr_columns
!= 0))
11391 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11392 " all zero [in modules %s]"),
11400 htab
->section_pool
.v1
.indices
=
11401 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11402 /* It's harder to decide whether the section is too small in v1.
11403 V1 is deprecated anyway so we punt. */
11407 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11408 int *ids
= htab
->section_pool
.v2
.section_ids
;
11409 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11410 /* Reverse map for error checking. */
11411 int ids_seen
[DW_SECT_MAX
+ 1];
11414 if (nr_columns
< 2)
11416 error (_("Dwarf Error: bad DWP hash table, too few columns"
11417 " in section table [in module %s]"),
11420 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11422 error (_("Dwarf Error: bad DWP hash table, too many columns"
11423 " in section table [in module %s]"),
11426 memset (ids
, 255, sizeof_ids
);
11427 memset (ids_seen
, 255, sizeof (ids_seen
));
11428 for (i
= 0; i
< nr_columns
; ++i
)
11430 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11432 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11434 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11435 " in section table [in module %s]"),
11436 id
, dwp_file
->name
);
11438 if (ids_seen
[id
] != -1)
11440 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11441 " id %d in section table [in module %s]"),
11442 id
, dwp_file
->name
);
11447 /* Must have exactly one info or types section. */
11448 if (((ids_seen
[DW_SECT_INFO
] != -1)
11449 + (ids_seen
[DW_SECT_TYPES
] != -1))
11452 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11453 " DWO info/types section [in module %s]"),
11456 /* Must have an abbrev section. */
11457 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11459 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11460 " section [in module %s]"),
11463 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11464 htab
->section_pool
.v2
.sizes
=
11465 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11466 * nr_units
* nr_columns
);
11467 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11468 * nr_units
* nr_columns
))
11471 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11472 " [in module %s]"),
11480 /* Update SECTIONS with the data from SECTP.
11482 This function is like the other "locate" section routines that are
11483 passed to bfd_map_over_sections, but in this context the sections to
11484 read comes from the DWP V1 hash table, not the full ELF section table.
11486 The result is non-zero for success, or zero if an error was found. */
11489 locate_v1_virtual_dwo_sections (asection
*sectp
,
11490 struct virtual_v1_dwo_sections
*sections
)
11492 const struct dwop_section_names
*names
= &dwop_section_names
;
11494 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11496 /* There can be only one. */
11497 if (sections
->abbrev
.s
.section
!= NULL
)
11499 sections
->abbrev
.s
.section
= sectp
;
11500 sections
->abbrev
.size
= bfd_section_size (sectp
);
11502 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11503 || section_is_p (sectp
->name
, &names
->types_dwo
))
11505 /* There can be only one. */
11506 if (sections
->info_or_types
.s
.section
!= NULL
)
11508 sections
->info_or_types
.s
.section
= sectp
;
11509 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11511 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11513 /* There can be only one. */
11514 if (sections
->line
.s
.section
!= NULL
)
11516 sections
->line
.s
.section
= sectp
;
11517 sections
->line
.size
= bfd_section_size (sectp
);
11519 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11521 /* There can be only one. */
11522 if (sections
->loc
.s
.section
!= NULL
)
11524 sections
->loc
.s
.section
= sectp
;
11525 sections
->loc
.size
= bfd_section_size (sectp
);
11527 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11529 /* There can be only one. */
11530 if (sections
->macinfo
.s
.section
!= NULL
)
11532 sections
->macinfo
.s
.section
= sectp
;
11533 sections
->macinfo
.size
= bfd_section_size (sectp
);
11535 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11537 /* There can be only one. */
11538 if (sections
->macro
.s
.section
!= NULL
)
11540 sections
->macro
.s
.section
= sectp
;
11541 sections
->macro
.size
= bfd_section_size (sectp
);
11543 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11545 /* There can be only one. */
11546 if (sections
->str_offsets
.s
.section
!= NULL
)
11548 sections
->str_offsets
.s
.section
= sectp
;
11549 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11553 /* No other kind of section is valid. */
11560 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11561 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11562 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11563 This is for DWP version 1 files. */
11565 static struct dwo_unit
*
11566 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11567 struct dwp_file
*dwp_file
,
11568 uint32_t unit_index
,
11569 const char *comp_dir
,
11570 ULONGEST signature
, int is_debug_types
)
11572 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11573 const struct dwp_hash_table
*dwp_htab
=
11574 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11575 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11576 const char *kind
= is_debug_types
? "TU" : "CU";
11577 struct dwo_file
*dwo_file
;
11578 struct dwo_unit
*dwo_unit
;
11579 struct virtual_v1_dwo_sections sections
;
11580 void **dwo_file_slot
;
11583 gdb_assert (dwp_file
->version
== 1);
11585 if (dwarf_read_debug
)
11587 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11589 pulongest (unit_index
), hex_string (signature
),
11593 /* Fetch the sections of this DWO unit.
11594 Put a limit on the number of sections we look for so that bad data
11595 doesn't cause us to loop forever. */
11597 #define MAX_NR_V1_DWO_SECTIONS \
11598 (1 /* .debug_info or .debug_types */ \
11599 + 1 /* .debug_abbrev */ \
11600 + 1 /* .debug_line */ \
11601 + 1 /* .debug_loc */ \
11602 + 1 /* .debug_str_offsets */ \
11603 + 1 /* .debug_macro or .debug_macinfo */ \
11604 + 1 /* trailing zero */)
11606 memset (§ions
, 0, sizeof (sections
));
11608 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11611 uint32_t section_nr
=
11612 read_4_bytes (dbfd
,
11613 dwp_htab
->section_pool
.v1
.indices
11614 + (unit_index
+ i
) * sizeof (uint32_t));
11616 if (section_nr
== 0)
11618 if (section_nr
>= dwp_file
->num_sections
)
11620 error (_("Dwarf Error: bad DWP hash table, section number too large"
11621 " [in module %s]"),
11625 sectp
= dwp_file
->elf_sections
[section_nr
];
11626 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11628 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11629 " [in module %s]"),
11635 || sections
.info_or_types
.empty ()
11636 || sections
.abbrev
.empty ())
11638 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11639 " [in module %s]"),
11642 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11644 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11645 " [in module %s]"),
11649 /* It's easier for the rest of the code if we fake a struct dwo_file and
11650 have dwo_unit "live" in that. At least for now.
11652 The DWP file can be made up of a random collection of CUs and TUs.
11653 However, for each CU + set of TUs that came from the same original DWO
11654 file, we can combine them back into a virtual DWO file to save space
11655 (fewer struct dwo_file objects to allocate). Remember that for really
11656 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11658 std::string virtual_dwo_name
=
11659 string_printf ("virtual-dwo/%d-%d-%d-%d",
11660 sections
.abbrev
.get_id (),
11661 sections
.line
.get_id (),
11662 sections
.loc
.get_id (),
11663 sections
.str_offsets
.get_id ());
11664 /* Can we use an existing virtual DWO file? */
11665 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11666 virtual_dwo_name
.c_str (),
11668 /* Create one if necessary. */
11669 if (*dwo_file_slot
== NULL
)
11671 if (dwarf_read_debug
)
11673 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11674 virtual_dwo_name
.c_str ());
11676 dwo_file
= new struct dwo_file
;
11677 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11678 dwo_file
->comp_dir
= comp_dir
;
11679 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11680 dwo_file
->sections
.line
= sections
.line
;
11681 dwo_file
->sections
.loc
= sections
.loc
;
11682 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11683 dwo_file
->sections
.macro
= sections
.macro
;
11684 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11685 /* The "str" section is global to the entire DWP file. */
11686 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11687 /* The info or types section is assigned below to dwo_unit,
11688 there's no need to record it in dwo_file.
11689 Also, we can't simply record type sections in dwo_file because
11690 we record a pointer into the vector in dwo_unit. As we collect more
11691 types we'll grow the vector and eventually have to reallocate space
11692 for it, invalidating all copies of pointers into the previous
11694 *dwo_file_slot
= dwo_file
;
11698 if (dwarf_read_debug
)
11700 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11701 virtual_dwo_name
.c_str ());
11703 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11706 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11707 dwo_unit
->dwo_file
= dwo_file
;
11708 dwo_unit
->signature
= signature
;
11709 dwo_unit
->section
=
11710 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11711 *dwo_unit
->section
= sections
.info_or_types
;
11712 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11717 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11718 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11719 piece within that section used by a TU/CU, return a virtual section
11720 of just that piece. */
11722 static struct dwarf2_section_info
11723 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11724 struct dwarf2_section_info
*section
,
11725 bfd_size_type offset
, bfd_size_type size
)
11727 struct dwarf2_section_info result
;
11730 gdb_assert (section
!= NULL
);
11731 gdb_assert (!section
->is_virtual
);
11733 memset (&result
, 0, sizeof (result
));
11734 result
.s
.containing_section
= section
;
11735 result
.is_virtual
= true;
11740 sectp
= section
->get_bfd_section ();
11742 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11743 bounds of the real section. This is a pretty-rare event, so just
11744 flag an error (easier) instead of a warning and trying to cope. */
11746 || offset
+ size
> bfd_section_size (sectp
))
11748 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11749 " in section %s [in module %s]"),
11750 sectp
? bfd_section_name (sectp
) : "<unknown>",
11751 objfile_name (dwarf2_per_objfile
->objfile
));
11754 result
.virtual_offset
= offset
;
11755 result
.size
= size
;
11759 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11760 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11761 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11762 This is for DWP version 2 files. */
11764 static struct dwo_unit
*
11765 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11766 struct dwp_file
*dwp_file
,
11767 uint32_t unit_index
,
11768 const char *comp_dir
,
11769 ULONGEST signature
, int is_debug_types
)
11771 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11772 const struct dwp_hash_table
*dwp_htab
=
11773 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11774 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11775 const char *kind
= is_debug_types
? "TU" : "CU";
11776 struct dwo_file
*dwo_file
;
11777 struct dwo_unit
*dwo_unit
;
11778 struct virtual_v2_dwo_sections sections
;
11779 void **dwo_file_slot
;
11782 gdb_assert (dwp_file
->version
== 2);
11784 if (dwarf_read_debug
)
11786 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11788 pulongest (unit_index
), hex_string (signature
),
11792 /* Fetch the section offsets of this DWO unit. */
11794 memset (§ions
, 0, sizeof (sections
));
11796 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11798 uint32_t offset
= read_4_bytes (dbfd
,
11799 dwp_htab
->section_pool
.v2
.offsets
11800 + (((unit_index
- 1) * dwp_htab
->nr_columns
11802 * sizeof (uint32_t)));
11803 uint32_t size
= read_4_bytes (dbfd
,
11804 dwp_htab
->section_pool
.v2
.sizes
11805 + (((unit_index
- 1) * dwp_htab
->nr_columns
11807 * sizeof (uint32_t)));
11809 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11812 case DW_SECT_TYPES
:
11813 sections
.info_or_types_offset
= offset
;
11814 sections
.info_or_types_size
= size
;
11816 case DW_SECT_ABBREV
:
11817 sections
.abbrev_offset
= offset
;
11818 sections
.abbrev_size
= size
;
11821 sections
.line_offset
= offset
;
11822 sections
.line_size
= size
;
11825 sections
.loc_offset
= offset
;
11826 sections
.loc_size
= size
;
11828 case DW_SECT_STR_OFFSETS
:
11829 sections
.str_offsets_offset
= offset
;
11830 sections
.str_offsets_size
= size
;
11832 case DW_SECT_MACINFO
:
11833 sections
.macinfo_offset
= offset
;
11834 sections
.macinfo_size
= size
;
11836 case DW_SECT_MACRO
:
11837 sections
.macro_offset
= offset
;
11838 sections
.macro_size
= size
;
11843 /* It's easier for the rest of the code if we fake a struct dwo_file and
11844 have dwo_unit "live" in that. At least for now.
11846 The DWP file can be made up of a random collection of CUs and TUs.
11847 However, for each CU + set of TUs that came from the same original DWO
11848 file, we can combine them back into a virtual DWO file to save space
11849 (fewer struct dwo_file objects to allocate). Remember that for really
11850 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11852 std::string virtual_dwo_name
=
11853 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11854 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11855 (long) (sections
.line_size
? sections
.line_offset
: 0),
11856 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11857 (long) (sections
.str_offsets_size
11858 ? sections
.str_offsets_offset
: 0));
11859 /* Can we use an existing virtual DWO file? */
11860 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11861 virtual_dwo_name
.c_str (),
11863 /* Create one if necessary. */
11864 if (*dwo_file_slot
== NULL
)
11866 if (dwarf_read_debug
)
11868 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11869 virtual_dwo_name
.c_str ());
11871 dwo_file
= new struct dwo_file
;
11872 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11873 dwo_file
->comp_dir
= comp_dir
;
11874 dwo_file
->sections
.abbrev
=
11875 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11876 sections
.abbrev_offset
, sections
.abbrev_size
);
11877 dwo_file
->sections
.line
=
11878 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11879 sections
.line_offset
, sections
.line_size
);
11880 dwo_file
->sections
.loc
=
11881 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11882 sections
.loc_offset
, sections
.loc_size
);
11883 dwo_file
->sections
.macinfo
=
11884 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11885 sections
.macinfo_offset
, sections
.macinfo_size
);
11886 dwo_file
->sections
.macro
=
11887 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11888 sections
.macro_offset
, sections
.macro_size
);
11889 dwo_file
->sections
.str_offsets
=
11890 create_dwp_v2_section (dwarf2_per_objfile
,
11891 &dwp_file
->sections
.str_offsets
,
11892 sections
.str_offsets_offset
,
11893 sections
.str_offsets_size
);
11894 /* The "str" section is global to the entire DWP file. */
11895 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11896 /* The info or types section is assigned below to dwo_unit,
11897 there's no need to record it in dwo_file.
11898 Also, we can't simply record type sections in dwo_file because
11899 we record a pointer into the vector in dwo_unit. As we collect more
11900 types we'll grow the vector and eventually have to reallocate space
11901 for it, invalidating all copies of pointers into the previous
11903 *dwo_file_slot
= dwo_file
;
11907 if (dwarf_read_debug
)
11909 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11910 virtual_dwo_name
.c_str ());
11912 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11915 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11916 dwo_unit
->dwo_file
= dwo_file
;
11917 dwo_unit
->signature
= signature
;
11918 dwo_unit
->section
=
11919 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11920 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11922 ? &dwp_file
->sections
.types
11923 : &dwp_file
->sections
.info
,
11924 sections
.info_or_types_offset
,
11925 sections
.info_or_types_size
);
11926 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11931 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11932 Returns NULL if the signature isn't found. */
11934 static struct dwo_unit
*
11935 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11936 struct dwp_file
*dwp_file
, const char *comp_dir
,
11937 ULONGEST signature
, int is_debug_types
)
11939 const struct dwp_hash_table
*dwp_htab
=
11940 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11941 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11942 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11943 uint32_t hash
= signature
& mask
;
11944 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11947 struct dwo_unit find_dwo_cu
;
11949 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11950 find_dwo_cu
.signature
= signature
;
11951 slot
= htab_find_slot (is_debug_types
11952 ? dwp_file
->loaded_tus
.get ()
11953 : dwp_file
->loaded_cus
.get (),
11954 &find_dwo_cu
, INSERT
);
11957 return (struct dwo_unit
*) *slot
;
11959 /* Use a for loop so that we don't loop forever on bad debug info. */
11960 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11962 ULONGEST signature_in_table
;
11964 signature_in_table
=
11965 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11966 if (signature_in_table
== signature
)
11968 uint32_t unit_index
=
11969 read_4_bytes (dbfd
,
11970 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11972 if (dwp_file
->version
== 1)
11974 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11975 dwp_file
, unit_index
,
11976 comp_dir
, signature
,
11981 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11982 dwp_file
, unit_index
,
11983 comp_dir
, signature
,
11986 return (struct dwo_unit
*) *slot
;
11988 if (signature_in_table
== 0)
11990 hash
= (hash
+ hash2
) & mask
;
11993 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11994 " [in module %s]"),
11998 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11999 Open the file specified by FILE_NAME and hand it off to BFD for
12000 preliminary analysis. Return a newly initialized bfd *, which
12001 includes a canonicalized copy of FILE_NAME.
12002 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12003 SEARCH_CWD is true if the current directory is to be searched.
12004 It will be searched before debug-file-directory.
12005 If successful, the file is added to the bfd include table of the
12006 objfile's bfd (see gdb_bfd_record_inclusion).
12007 If unable to find/open the file, return NULL.
12008 NOTE: This function is derived from symfile_bfd_open. */
12010 static gdb_bfd_ref_ptr
12011 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12012 const char *file_name
, int is_dwp
, int search_cwd
)
12015 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12016 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12017 to debug_file_directory. */
12018 const char *search_path
;
12019 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12021 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12024 if (*debug_file_directory
!= '\0')
12026 search_path_holder
.reset (concat (".", dirname_separator_string
,
12027 debug_file_directory
,
12029 search_path
= search_path_holder
.get ();
12035 search_path
= debug_file_directory
;
12037 openp_flags flags
= OPF_RETURN_REALPATH
;
12039 flags
|= OPF_SEARCH_IN_PATH
;
12041 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12042 desc
= openp (search_path
, flags
, file_name
,
12043 O_RDONLY
| O_BINARY
, &absolute_name
);
12047 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12049 if (sym_bfd
== NULL
)
12051 bfd_set_cacheable (sym_bfd
.get (), 1);
12053 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12056 /* Success. Record the bfd as having been included by the objfile's bfd.
12057 This is important because things like demangled_names_hash lives in the
12058 objfile's per_bfd space and may have references to things like symbol
12059 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12060 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12065 /* Try to open DWO file FILE_NAME.
12066 COMP_DIR is the DW_AT_comp_dir attribute.
12067 The result is the bfd handle of the file.
12068 If there is a problem finding or opening the file, return NULL.
12069 Upon success, the canonicalized path of the file is stored in the bfd,
12070 same as symfile_bfd_open. */
12072 static gdb_bfd_ref_ptr
12073 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12074 const char *file_name
, const char *comp_dir
)
12076 if (IS_ABSOLUTE_PATH (file_name
))
12077 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12078 0 /*is_dwp*/, 0 /*search_cwd*/);
12080 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12082 if (comp_dir
!= NULL
)
12084 gdb::unique_xmalloc_ptr
<char> path_to_try
12085 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12087 /* NOTE: If comp_dir is a relative path, this will also try the
12088 search path, which seems useful. */
12089 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12090 path_to_try
.get (),
12092 1 /*search_cwd*/));
12097 /* That didn't work, try debug-file-directory, which, despite its name,
12098 is a list of paths. */
12100 if (*debug_file_directory
== '\0')
12103 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12104 0 /*is_dwp*/, 1 /*search_cwd*/);
12107 /* This function is mapped across the sections and remembers the offset and
12108 size of each of the DWO debugging sections we are interested in. */
12111 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12113 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12114 const struct dwop_section_names
*names
= &dwop_section_names
;
12116 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12118 dwo_sections
->abbrev
.s
.section
= sectp
;
12119 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12121 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12123 dwo_sections
->info
.s
.section
= sectp
;
12124 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12126 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12128 dwo_sections
->line
.s
.section
= sectp
;
12129 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12131 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12133 dwo_sections
->loc
.s
.section
= sectp
;
12134 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12136 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12138 dwo_sections
->macinfo
.s
.section
= sectp
;
12139 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12141 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12143 dwo_sections
->macro
.s
.section
= sectp
;
12144 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12146 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12148 dwo_sections
->str
.s
.section
= sectp
;
12149 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12151 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12153 dwo_sections
->str_offsets
.s
.section
= sectp
;
12154 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12156 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12158 struct dwarf2_section_info type_section
;
12160 memset (&type_section
, 0, sizeof (type_section
));
12161 type_section
.s
.section
= sectp
;
12162 type_section
.size
= bfd_section_size (sectp
);
12163 dwo_sections
->types
.push_back (type_section
);
12167 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12168 by PER_CU. This is for the non-DWP case.
12169 The result is NULL if DWO_NAME can't be found. */
12171 static struct dwo_file
*
12172 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12173 const char *dwo_name
, const char *comp_dir
)
12175 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12177 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12180 if (dwarf_read_debug
)
12181 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12185 dwo_file_up
dwo_file (new struct dwo_file
);
12186 dwo_file
->dwo_name
= dwo_name
;
12187 dwo_file
->comp_dir
= comp_dir
;
12188 dwo_file
->dbfd
= std::move (dbfd
);
12190 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12191 &dwo_file
->sections
);
12193 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12194 dwo_file
->sections
.info
, dwo_file
->cus
);
12196 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12197 dwo_file
->sections
.types
, dwo_file
->tus
);
12199 if (dwarf_read_debug
)
12200 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12202 return dwo_file
.release ();
12205 /* This function is mapped across the sections and remembers the offset and
12206 size of each of the DWP debugging sections common to version 1 and 2 that
12207 we are interested in. */
12210 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12211 void *dwp_file_ptr
)
12213 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12214 const struct dwop_section_names
*names
= &dwop_section_names
;
12215 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12217 /* Record the ELF section number for later lookup: this is what the
12218 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12219 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12220 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12222 /* Look for specific sections that we need. */
12223 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12225 dwp_file
->sections
.str
.s
.section
= sectp
;
12226 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12228 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12230 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12231 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12233 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12235 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12236 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12240 /* This function is mapped across the sections and remembers the offset and
12241 size of each of the DWP version 2 debugging sections that we are interested
12242 in. This is split into a separate function because we don't know if we
12243 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12246 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12248 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12249 const struct dwop_section_names
*names
= &dwop_section_names
;
12250 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12252 /* Record the ELF section number for later lookup: this is what the
12253 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12254 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12255 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12257 /* Look for specific sections that we need. */
12258 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12260 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12261 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12263 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12265 dwp_file
->sections
.info
.s
.section
= sectp
;
12266 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12268 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12270 dwp_file
->sections
.line
.s
.section
= sectp
;
12271 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12273 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12275 dwp_file
->sections
.loc
.s
.section
= sectp
;
12276 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12278 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12280 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12281 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12283 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12285 dwp_file
->sections
.macro
.s
.section
= sectp
;
12286 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12288 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12290 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12291 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12293 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12295 dwp_file
->sections
.types
.s
.section
= sectp
;
12296 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12300 /* Hash function for dwp_file loaded CUs/TUs. */
12303 hash_dwp_loaded_cutus (const void *item
)
12305 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12307 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12308 return dwo_unit
->signature
;
12311 /* Equality function for dwp_file loaded CUs/TUs. */
12314 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12316 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12317 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12319 return dua
->signature
== dub
->signature
;
12322 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12325 allocate_dwp_loaded_cutus_table ()
12327 return htab_up (htab_create_alloc (3,
12328 hash_dwp_loaded_cutus
,
12329 eq_dwp_loaded_cutus
,
12330 NULL
, xcalloc
, xfree
));
12333 /* Try to open DWP file FILE_NAME.
12334 The result is the bfd handle of the file.
12335 If there is a problem finding or opening the file, return NULL.
12336 Upon success, the canonicalized path of the file is stored in the bfd,
12337 same as symfile_bfd_open. */
12339 static gdb_bfd_ref_ptr
12340 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12341 const char *file_name
)
12343 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12345 1 /*search_cwd*/));
12349 /* Work around upstream bug 15652.
12350 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12351 [Whether that's a "bug" is debatable, but it is getting in our way.]
12352 We have no real idea where the dwp file is, because gdb's realpath-ing
12353 of the executable's path may have discarded the needed info.
12354 [IWBN if the dwp file name was recorded in the executable, akin to
12355 .gnu_debuglink, but that doesn't exist yet.]
12356 Strip the directory from FILE_NAME and search again. */
12357 if (*debug_file_directory
!= '\0')
12359 /* Don't implicitly search the current directory here.
12360 If the user wants to search "." to handle this case,
12361 it must be added to debug-file-directory. */
12362 return try_open_dwop_file (dwarf2_per_objfile
,
12363 lbasename (file_name
), 1 /*is_dwp*/,
12370 /* Initialize the use of the DWP file for the current objfile.
12371 By convention the name of the DWP file is ${objfile}.dwp.
12372 The result is NULL if it can't be found. */
12374 static std::unique_ptr
<struct dwp_file
>
12375 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12377 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12379 /* Try to find first .dwp for the binary file before any symbolic links
12382 /* If the objfile is a debug file, find the name of the real binary
12383 file and get the name of dwp file from there. */
12384 std::string dwp_name
;
12385 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12387 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12388 const char *backlink_basename
= lbasename (backlink
->original_name
);
12390 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12393 dwp_name
= objfile
->original_name
;
12395 dwp_name
+= ".dwp";
12397 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12399 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12401 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12402 dwp_name
= objfile_name (objfile
);
12403 dwp_name
+= ".dwp";
12404 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12409 if (dwarf_read_debug
)
12410 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12411 return std::unique_ptr
<dwp_file
> ();
12414 const char *name
= bfd_get_filename (dbfd
.get ());
12415 std::unique_ptr
<struct dwp_file
> dwp_file
12416 (new struct dwp_file (name
, std::move (dbfd
)));
12418 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12419 dwp_file
->elf_sections
=
12420 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12421 dwp_file
->num_sections
, asection
*);
12423 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12424 dwarf2_locate_common_dwp_sections
,
12427 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12430 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12433 /* The DWP file version is stored in the hash table. Oh well. */
12434 if (dwp_file
->cus
&& dwp_file
->tus
12435 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12437 /* Technically speaking, we should try to limp along, but this is
12438 pretty bizarre. We use pulongest here because that's the established
12439 portability solution (e.g, we cannot use %u for uint32_t). */
12440 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12441 " TU version %s [in DWP file %s]"),
12442 pulongest (dwp_file
->cus
->version
),
12443 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12447 dwp_file
->version
= dwp_file
->cus
->version
;
12448 else if (dwp_file
->tus
)
12449 dwp_file
->version
= dwp_file
->tus
->version
;
12451 dwp_file
->version
= 2;
12453 if (dwp_file
->version
== 2)
12454 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12455 dwarf2_locate_v2_dwp_sections
,
12458 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12459 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12461 if (dwarf_read_debug
)
12463 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12464 fprintf_unfiltered (gdb_stdlog
,
12465 " %s CUs, %s TUs\n",
12466 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12467 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12473 /* Wrapper around open_and_init_dwp_file, only open it once. */
12475 static struct dwp_file
*
12476 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12478 if (! dwarf2_per_objfile
->dwp_checked
)
12480 dwarf2_per_objfile
->dwp_file
12481 = open_and_init_dwp_file (dwarf2_per_objfile
);
12482 dwarf2_per_objfile
->dwp_checked
= 1;
12484 return dwarf2_per_objfile
->dwp_file
.get ();
12487 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12488 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12489 or in the DWP file for the objfile, referenced by THIS_UNIT.
12490 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12491 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12493 This is called, for example, when wanting to read a variable with a
12494 complex location. Therefore we don't want to do file i/o for every call.
12495 Therefore we don't want to look for a DWO file on every call.
12496 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12497 then we check if we've already seen DWO_NAME, and only THEN do we check
12500 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12501 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12503 static struct dwo_unit
*
12504 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12505 const char *dwo_name
, const char *comp_dir
,
12506 ULONGEST signature
, int is_debug_types
)
12508 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12509 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12510 const char *kind
= is_debug_types
? "TU" : "CU";
12511 void **dwo_file_slot
;
12512 struct dwo_file
*dwo_file
;
12513 struct dwp_file
*dwp_file
;
12515 /* First see if there's a DWP file.
12516 If we have a DWP file but didn't find the DWO inside it, don't
12517 look for the original DWO file. It makes gdb behave differently
12518 depending on whether one is debugging in the build tree. */
12520 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12521 if (dwp_file
!= NULL
)
12523 const struct dwp_hash_table
*dwp_htab
=
12524 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12526 if (dwp_htab
!= NULL
)
12528 struct dwo_unit
*dwo_cutu
=
12529 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12530 signature
, is_debug_types
);
12532 if (dwo_cutu
!= NULL
)
12534 if (dwarf_read_debug
)
12536 fprintf_unfiltered (gdb_stdlog
,
12537 "Virtual DWO %s %s found: @%s\n",
12538 kind
, hex_string (signature
),
12539 host_address_to_string (dwo_cutu
));
12547 /* No DWP file, look for the DWO file. */
12549 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12550 dwo_name
, comp_dir
);
12551 if (*dwo_file_slot
== NULL
)
12553 /* Read in the file and build a table of the CUs/TUs it contains. */
12554 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12556 /* NOTE: This will be NULL if unable to open the file. */
12557 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12559 if (dwo_file
!= NULL
)
12561 struct dwo_unit
*dwo_cutu
= NULL
;
12563 if (is_debug_types
&& dwo_file
->tus
)
12565 struct dwo_unit find_dwo_cutu
;
12567 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12568 find_dwo_cutu
.signature
= signature
;
12570 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12573 else if (!is_debug_types
&& dwo_file
->cus
)
12575 struct dwo_unit find_dwo_cutu
;
12577 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12578 find_dwo_cutu
.signature
= signature
;
12579 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12583 if (dwo_cutu
!= NULL
)
12585 if (dwarf_read_debug
)
12587 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12588 kind
, dwo_name
, hex_string (signature
),
12589 host_address_to_string (dwo_cutu
));
12596 /* We didn't find it. This could mean a dwo_id mismatch, or
12597 someone deleted the DWO/DWP file, or the search path isn't set up
12598 correctly to find the file. */
12600 if (dwarf_read_debug
)
12602 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12603 kind
, dwo_name
, hex_string (signature
));
12606 /* This is a warning and not a complaint because it can be caused by
12607 pilot error (e.g., user accidentally deleting the DWO). */
12609 /* Print the name of the DWP file if we looked there, helps the user
12610 better diagnose the problem. */
12611 std::string dwp_text
;
12613 if (dwp_file
!= NULL
)
12614 dwp_text
= string_printf (" [in DWP file %s]",
12615 lbasename (dwp_file
->name
));
12617 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12618 " [in module %s]"),
12619 kind
, dwo_name
, hex_string (signature
),
12621 this_unit
->is_debug_types
? "TU" : "CU",
12622 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12627 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12628 See lookup_dwo_cutu_unit for details. */
12630 static struct dwo_unit
*
12631 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12632 const char *dwo_name
, const char *comp_dir
,
12633 ULONGEST signature
)
12635 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12638 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12639 See lookup_dwo_cutu_unit for details. */
12641 static struct dwo_unit
*
12642 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12643 const char *dwo_name
, const char *comp_dir
)
12645 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12648 /* Traversal function for queue_and_load_all_dwo_tus. */
12651 queue_and_load_dwo_tu (void **slot
, void *info
)
12653 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12654 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12655 ULONGEST signature
= dwo_unit
->signature
;
12656 struct signatured_type
*sig_type
=
12657 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12659 if (sig_type
!= NULL
)
12661 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12663 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12664 a real dependency of PER_CU on SIG_TYPE. That is detected later
12665 while processing PER_CU. */
12666 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12667 load_full_type_unit (sig_cu
);
12668 per_cu
->imported_symtabs_push (sig_cu
);
12674 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12675 The DWO may have the only definition of the type, though it may not be
12676 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12677 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12680 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12682 struct dwo_unit
*dwo_unit
;
12683 struct dwo_file
*dwo_file
;
12685 gdb_assert (!per_cu
->is_debug_types
);
12686 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12687 gdb_assert (per_cu
->cu
!= NULL
);
12689 dwo_unit
= per_cu
->cu
->dwo_unit
;
12690 gdb_assert (dwo_unit
!= NULL
);
12692 dwo_file
= dwo_unit
->dwo_file
;
12693 if (dwo_file
->tus
!= NULL
)
12694 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12698 /* Read in various DIEs. */
12700 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12701 Inherit only the children of the DW_AT_abstract_origin DIE not being
12702 already referenced by DW_AT_abstract_origin from the children of the
12706 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12708 struct die_info
*child_die
;
12709 sect_offset
*offsetp
;
12710 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12711 struct die_info
*origin_die
;
12712 /* Iterator of the ORIGIN_DIE children. */
12713 struct die_info
*origin_child_die
;
12714 struct attribute
*attr
;
12715 struct dwarf2_cu
*origin_cu
;
12716 struct pending
**origin_previous_list_in_scope
;
12718 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12722 /* Note that following die references may follow to a die in a
12726 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12728 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12730 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12731 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12733 if (die
->tag
!= origin_die
->tag
12734 && !(die
->tag
== DW_TAG_inlined_subroutine
12735 && origin_die
->tag
== DW_TAG_subprogram
))
12736 complaint (_("DIE %s and its abstract origin %s have different tags"),
12737 sect_offset_str (die
->sect_off
),
12738 sect_offset_str (origin_die
->sect_off
));
12740 std::vector
<sect_offset
> offsets
;
12742 for (child_die
= die
->child
;
12743 child_die
&& child_die
->tag
;
12744 child_die
= sibling_die (child_die
))
12746 struct die_info
*child_origin_die
;
12747 struct dwarf2_cu
*child_origin_cu
;
12749 /* We are trying to process concrete instance entries:
12750 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12751 it's not relevant to our analysis here. i.e. detecting DIEs that are
12752 present in the abstract instance but not referenced in the concrete
12754 if (child_die
->tag
== DW_TAG_call_site
12755 || child_die
->tag
== DW_TAG_GNU_call_site
)
12758 /* For each CHILD_DIE, find the corresponding child of
12759 ORIGIN_DIE. If there is more than one layer of
12760 DW_AT_abstract_origin, follow them all; there shouldn't be,
12761 but GCC versions at least through 4.4 generate this (GCC PR
12763 child_origin_die
= child_die
;
12764 child_origin_cu
= cu
;
12767 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12771 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12775 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12776 counterpart may exist. */
12777 if (child_origin_die
!= child_die
)
12779 if (child_die
->tag
!= child_origin_die
->tag
12780 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12781 && child_origin_die
->tag
== DW_TAG_subprogram
))
12782 complaint (_("Child DIE %s and its abstract origin %s have "
12784 sect_offset_str (child_die
->sect_off
),
12785 sect_offset_str (child_origin_die
->sect_off
));
12786 if (child_origin_die
->parent
!= origin_die
)
12787 complaint (_("Child DIE %s and its abstract origin %s have "
12788 "different parents"),
12789 sect_offset_str (child_die
->sect_off
),
12790 sect_offset_str (child_origin_die
->sect_off
));
12792 offsets
.push_back (child_origin_die
->sect_off
);
12795 std::sort (offsets
.begin (), offsets
.end ());
12796 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12797 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12798 if (offsetp
[-1] == *offsetp
)
12799 complaint (_("Multiple children of DIE %s refer "
12800 "to DIE %s as their abstract origin"),
12801 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12803 offsetp
= offsets
.data ();
12804 origin_child_die
= origin_die
->child
;
12805 while (origin_child_die
&& origin_child_die
->tag
)
12807 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12808 while (offsetp
< offsets_end
12809 && *offsetp
< origin_child_die
->sect_off
)
12811 if (offsetp
>= offsets_end
12812 || *offsetp
> origin_child_die
->sect_off
)
12814 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12815 Check whether we're already processing ORIGIN_CHILD_DIE.
12816 This can happen with mutually referenced abstract_origins.
12818 if (!origin_child_die
->in_process
)
12819 process_die (origin_child_die
, origin_cu
);
12821 origin_child_die
= sibling_die (origin_child_die
);
12823 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12825 if (cu
!= origin_cu
)
12826 compute_delayed_physnames (origin_cu
);
12830 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12832 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12833 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12834 struct context_stack
*newobj
;
12837 struct die_info
*child_die
;
12838 struct attribute
*attr
, *call_line
, *call_file
;
12840 CORE_ADDR baseaddr
;
12841 struct block
*block
;
12842 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12843 std::vector
<struct symbol
*> template_args
;
12844 struct template_symbol
*templ_func
= NULL
;
12848 /* If we do not have call site information, we can't show the
12849 caller of this inlined function. That's too confusing, so
12850 only use the scope for local variables. */
12851 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12852 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12853 if (call_line
== NULL
|| call_file
== NULL
)
12855 read_lexical_block_scope (die
, cu
);
12860 baseaddr
= objfile
->text_section_offset ();
12862 name
= dwarf2_name (die
, cu
);
12864 /* Ignore functions with missing or empty names. These are actually
12865 illegal according to the DWARF standard. */
12868 complaint (_("missing name for subprogram DIE at %s"),
12869 sect_offset_str (die
->sect_off
));
12873 /* Ignore functions with missing or invalid low and high pc attributes. */
12874 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12875 <= PC_BOUNDS_INVALID
)
12877 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12878 if (!attr
|| !DW_UNSND (attr
))
12879 complaint (_("cannot get low and high bounds "
12880 "for subprogram DIE at %s"),
12881 sect_offset_str (die
->sect_off
));
12885 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12886 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12888 /* If we have any template arguments, then we must allocate a
12889 different sort of symbol. */
12890 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12892 if (child_die
->tag
== DW_TAG_template_type_param
12893 || child_die
->tag
== DW_TAG_template_value_param
)
12895 templ_func
= allocate_template_symbol (objfile
);
12896 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12901 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12902 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12903 (struct symbol
*) templ_func
);
12905 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12906 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12909 /* If there is a location expression for DW_AT_frame_base, record
12911 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12912 if (attr
!= nullptr)
12913 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12915 /* If there is a location for the static link, record it. */
12916 newobj
->static_link
= NULL
;
12917 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12918 if (attr
!= nullptr)
12920 newobj
->static_link
12921 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12922 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12923 cu
->per_cu
->addr_type ());
12926 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12928 if (die
->child
!= NULL
)
12930 child_die
= die
->child
;
12931 while (child_die
&& child_die
->tag
)
12933 if (child_die
->tag
== DW_TAG_template_type_param
12934 || child_die
->tag
== DW_TAG_template_value_param
)
12936 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12939 template_args
.push_back (arg
);
12942 process_die (child_die
, cu
);
12943 child_die
= sibling_die (child_die
);
12947 inherit_abstract_dies (die
, cu
);
12949 /* If we have a DW_AT_specification, we might need to import using
12950 directives from the context of the specification DIE. See the
12951 comment in determine_prefix. */
12952 if (cu
->language
== language_cplus
12953 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12955 struct dwarf2_cu
*spec_cu
= cu
;
12956 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12960 child_die
= spec_die
->child
;
12961 while (child_die
&& child_die
->tag
)
12963 if (child_die
->tag
== DW_TAG_imported_module
)
12964 process_die (child_die
, spec_cu
);
12965 child_die
= sibling_die (child_die
);
12968 /* In some cases, GCC generates specification DIEs that
12969 themselves contain DW_AT_specification attributes. */
12970 spec_die
= die_specification (spec_die
, &spec_cu
);
12974 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12975 /* Make a block for the local symbols within. */
12976 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12977 cstk
.static_link
, lowpc
, highpc
);
12979 /* For C++, set the block's scope. */
12980 if ((cu
->language
== language_cplus
12981 || cu
->language
== language_fortran
12982 || cu
->language
== language_d
12983 || cu
->language
== language_rust
)
12984 && cu
->processing_has_namespace_info
)
12985 block_set_scope (block
, determine_prefix (die
, cu
),
12986 &objfile
->objfile_obstack
);
12988 /* If we have address ranges, record them. */
12989 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12991 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12993 /* Attach template arguments to function. */
12994 if (!template_args
.empty ())
12996 gdb_assert (templ_func
!= NULL
);
12998 templ_func
->n_template_arguments
= template_args
.size ();
12999 templ_func
->template_arguments
13000 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13001 templ_func
->n_template_arguments
);
13002 memcpy (templ_func
->template_arguments
,
13003 template_args
.data (),
13004 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13006 /* Make sure that the symtab is set on the new symbols. Even
13007 though they don't appear in this symtab directly, other parts
13008 of gdb assume that symbols do, and this is reasonably
13010 for (symbol
*sym
: template_args
)
13011 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13014 /* In C++, we can have functions nested inside functions (e.g., when
13015 a function declares a class that has methods). This means that
13016 when we finish processing a function scope, we may need to go
13017 back to building a containing block's symbol lists. */
13018 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13019 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13021 /* If we've finished processing a top-level function, subsequent
13022 symbols go in the file symbol list. */
13023 if (cu
->get_builder ()->outermost_context_p ())
13024 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13027 /* Process all the DIES contained within a lexical block scope. Start
13028 a new scope, process the dies, and then close the scope. */
13031 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13033 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13034 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13035 CORE_ADDR lowpc
, highpc
;
13036 struct die_info
*child_die
;
13037 CORE_ADDR baseaddr
;
13039 baseaddr
= objfile
->text_section_offset ();
13041 /* Ignore blocks with missing or invalid low and high pc attributes. */
13042 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13043 as multiple lexical blocks? Handling children in a sane way would
13044 be nasty. Might be easier to properly extend generic blocks to
13045 describe ranges. */
13046 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13048 case PC_BOUNDS_NOT_PRESENT
:
13049 /* DW_TAG_lexical_block has no attributes, process its children as if
13050 there was no wrapping by that DW_TAG_lexical_block.
13051 GCC does no longer produces such DWARF since GCC r224161. */
13052 for (child_die
= die
->child
;
13053 child_die
!= NULL
&& child_die
->tag
;
13054 child_die
= sibling_die (child_die
))
13055 process_die (child_die
, cu
);
13057 case PC_BOUNDS_INVALID
:
13060 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13061 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13063 cu
->get_builder ()->push_context (0, lowpc
);
13064 if (die
->child
!= NULL
)
13066 child_die
= die
->child
;
13067 while (child_die
&& child_die
->tag
)
13069 process_die (child_die
, cu
);
13070 child_die
= sibling_die (child_die
);
13073 inherit_abstract_dies (die
, cu
);
13074 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13076 if (*cu
->get_builder ()->get_local_symbols () != NULL
13077 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13079 struct block
*block
13080 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13081 cstk
.start_addr
, highpc
);
13083 /* Note that recording ranges after traversing children, as we
13084 do here, means that recording a parent's ranges entails
13085 walking across all its children's ranges as they appear in
13086 the address map, which is quadratic behavior.
13088 It would be nicer to record the parent's ranges before
13089 traversing its children, simply overriding whatever you find
13090 there. But since we don't even decide whether to create a
13091 block until after we've traversed its children, that's hard
13093 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13095 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13096 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13099 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13102 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13104 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13105 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13106 CORE_ADDR pc
, baseaddr
;
13107 struct attribute
*attr
;
13108 struct call_site
*call_site
, call_site_local
;
13111 struct die_info
*child_die
;
13113 baseaddr
= objfile
->text_section_offset ();
13115 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13118 /* This was a pre-DWARF-5 GNU extension alias
13119 for DW_AT_call_return_pc. */
13120 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13124 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13125 "DIE %s [in module %s]"),
13126 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13129 pc
= attr
->value_as_address () + baseaddr
;
13130 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13132 if (cu
->call_site_htab
== NULL
)
13133 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13134 NULL
, &objfile
->objfile_obstack
,
13135 hashtab_obstack_allocate
, NULL
);
13136 call_site_local
.pc
= pc
;
13137 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13140 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13141 "DIE %s [in module %s]"),
13142 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13143 objfile_name (objfile
));
13147 /* Count parameters at the caller. */
13150 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13151 child_die
= sibling_die (child_die
))
13153 if (child_die
->tag
!= DW_TAG_call_site_parameter
13154 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13156 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13157 "DW_TAG_call_site child DIE %s [in module %s]"),
13158 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13159 objfile_name (objfile
));
13167 = ((struct call_site
*)
13168 obstack_alloc (&objfile
->objfile_obstack
,
13169 sizeof (*call_site
)
13170 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13172 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13173 call_site
->pc
= pc
;
13175 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13176 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13178 struct die_info
*func_die
;
13180 /* Skip also over DW_TAG_inlined_subroutine. */
13181 for (func_die
= die
->parent
;
13182 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13183 && func_die
->tag
!= DW_TAG_subroutine_type
;
13184 func_die
= func_die
->parent
);
13186 /* DW_AT_call_all_calls is a superset
13187 of DW_AT_call_all_tail_calls. */
13189 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13190 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13191 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13192 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13194 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13195 not complete. But keep CALL_SITE for look ups via call_site_htab,
13196 both the initial caller containing the real return address PC and
13197 the final callee containing the current PC of a chain of tail
13198 calls do not need to have the tail call list complete. But any
13199 function candidate for a virtual tail call frame searched via
13200 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13201 determined unambiguously. */
13205 struct type
*func_type
= NULL
;
13208 func_type
= get_die_type (func_die
, cu
);
13209 if (func_type
!= NULL
)
13211 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13213 /* Enlist this call site to the function. */
13214 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13215 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13218 complaint (_("Cannot find function owning DW_TAG_call_site "
13219 "DIE %s [in module %s]"),
13220 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13224 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13226 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13228 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13231 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13232 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13234 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13235 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13236 /* Keep NULL DWARF_BLOCK. */;
13237 else if (attr
->form_is_block ())
13239 struct dwarf2_locexpr_baton
*dlbaton
;
13241 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13242 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13243 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13244 dlbaton
->per_cu
= cu
->per_cu
;
13246 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13248 else if (attr
->form_is_ref ())
13250 struct dwarf2_cu
*target_cu
= cu
;
13251 struct die_info
*target_die
;
13253 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13254 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13255 if (die_is_declaration (target_die
, target_cu
))
13257 const char *target_physname
;
13259 /* Prefer the mangled name; otherwise compute the demangled one. */
13260 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13261 if (target_physname
== NULL
)
13262 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13263 if (target_physname
== NULL
)
13264 complaint (_("DW_AT_call_target target DIE has invalid "
13265 "physname, for referencing DIE %s [in module %s]"),
13266 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13268 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13274 /* DW_AT_entry_pc should be preferred. */
13275 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13276 <= PC_BOUNDS_INVALID
)
13277 complaint (_("DW_AT_call_target target DIE has invalid "
13278 "low pc, for referencing DIE %s [in module %s]"),
13279 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13282 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13283 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13288 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13289 "block nor reference, for DIE %s [in module %s]"),
13290 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13292 call_site
->per_cu
= cu
->per_cu
;
13294 for (child_die
= die
->child
;
13295 child_die
&& child_die
->tag
;
13296 child_die
= sibling_die (child_die
))
13298 struct call_site_parameter
*parameter
;
13299 struct attribute
*loc
, *origin
;
13301 if (child_die
->tag
!= DW_TAG_call_site_parameter
13302 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13304 /* Already printed the complaint above. */
13308 gdb_assert (call_site
->parameter_count
< nparams
);
13309 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13311 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13312 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13313 register is contained in DW_AT_call_value. */
13315 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13316 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13317 if (origin
== NULL
)
13319 /* This was a pre-DWARF-5 GNU extension alias
13320 for DW_AT_call_parameter. */
13321 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13323 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13325 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13327 sect_offset sect_off
13328 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13329 if (!cu
->header
.offset_in_cu_p (sect_off
))
13331 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13332 binding can be done only inside one CU. Such referenced DIE
13333 therefore cannot be even moved to DW_TAG_partial_unit. */
13334 complaint (_("DW_AT_call_parameter offset is not in CU for "
13335 "DW_TAG_call_site child DIE %s [in module %s]"),
13336 sect_offset_str (child_die
->sect_off
),
13337 objfile_name (objfile
));
13340 parameter
->u
.param_cu_off
13341 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13343 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13345 complaint (_("No DW_FORM_block* DW_AT_location for "
13346 "DW_TAG_call_site child DIE %s [in module %s]"),
13347 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13352 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13353 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13354 if (parameter
->u
.dwarf_reg
!= -1)
13355 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13356 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13357 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13358 ¶meter
->u
.fb_offset
))
13359 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13362 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13363 "for DW_FORM_block* DW_AT_location is supported for "
13364 "DW_TAG_call_site child DIE %s "
13366 sect_offset_str (child_die
->sect_off
),
13367 objfile_name (objfile
));
13372 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13374 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13375 if (attr
== NULL
|| !attr
->form_is_block ())
13377 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13378 "DW_TAG_call_site child DIE %s [in module %s]"),
13379 sect_offset_str (child_die
->sect_off
),
13380 objfile_name (objfile
));
13383 parameter
->value
= DW_BLOCK (attr
)->data
;
13384 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13386 /* Parameters are not pre-cleared by memset above. */
13387 parameter
->data_value
= NULL
;
13388 parameter
->data_value_size
= 0;
13389 call_site
->parameter_count
++;
13391 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13393 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13394 if (attr
!= nullptr)
13396 if (!attr
->form_is_block ())
13397 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13398 "DW_TAG_call_site child DIE %s [in module %s]"),
13399 sect_offset_str (child_die
->sect_off
),
13400 objfile_name (objfile
));
13403 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13404 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13410 /* Helper function for read_variable. If DIE represents a virtual
13411 table, then return the type of the concrete object that is
13412 associated with the virtual table. Otherwise, return NULL. */
13414 static struct type
*
13415 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13417 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13421 /* Find the type DIE. */
13422 struct die_info
*type_die
= NULL
;
13423 struct dwarf2_cu
*type_cu
= cu
;
13425 if (attr
->form_is_ref ())
13426 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13427 if (type_die
== NULL
)
13430 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13432 return die_containing_type (type_die
, type_cu
);
13435 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13438 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13440 struct rust_vtable_symbol
*storage
= NULL
;
13442 if (cu
->language
== language_rust
)
13444 struct type
*containing_type
= rust_containing_type (die
, cu
);
13446 if (containing_type
!= NULL
)
13448 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13450 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13451 initialize_objfile_symbol (storage
);
13452 storage
->concrete_type
= containing_type
;
13453 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13457 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13458 struct attribute
*abstract_origin
13459 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13460 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13461 if (res
== NULL
&& loc
&& abstract_origin
)
13463 /* We have a variable without a name, but with a location and an abstract
13464 origin. This may be a concrete instance of an abstract variable
13465 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13467 struct dwarf2_cu
*origin_cu
= cu
;
13468 struct die_info
*origin_die
13469 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13470 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13471 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13475 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13476 reading .debug_rnglists.
13477 Callback's type should be:
13478 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13479 Return true if the attributes are present and valid, otherwise,
13482 template <typename Callback
>
13484 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13485 Callback
&&callback
)
13487 struct dwarf2_per_objfile
*dwarf2_per_objfile
13488 = cu
->per_cu
->dwarf2_per_objfile
;
13489 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13490 bfd
*obfd
= objfile
->obfd
;
13491 /* Base address selection entry. */
13494 const gdb_byte
*buffer
;
13495 CORE_ADDR baseaddr
;
13496 bool overflow
= false;
13498 found_base
= cu
->base_known
;
13499 base
= cu
->base_address
;
13501 dwarf2_per_objfile
->rnglists
.read (objfile
);
13502 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13504 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13508 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13510 baseaddr
= objfile
->text_section_offset ();
13514 /* Initialize it due to a false compiler warning. */
13515 CORE_ADDR range_beginning
= 0, range_end
= 0;
13516 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13517 + dwarf2_per_objfile
->rnglists
.size
);
13518 unsigned int bytes_read
;
13520 if (buffer
== buf_end
)
13525 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13528 case DW_RLE_end_of_list
:
13530 case DW_RLE_base_address
:
13531 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13536 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13538 buffer
+= bytes_read
;
13540 case DW_RLE_start_length
:
13541 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13546 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13548 buffer
+= bytes_read
;
13549 range_end
= (range_beginning
13550 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13551 buffer
+= bytes_read
;
13552 if (buffer
> buf_end
)
13558 case DW_RLE_offset_pair
:
13559 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13560 buffer
+= bytes_read
;
13561 if (buffer
> buf_end
)
13566 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13567 buffer
+= bytes_read
;
13568 if (buffer
> buf_end
)
13574 case DW_RLE_start_end
:
13575 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13580 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13582 buffer
+= bytes_read
;
13583 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13584 buffer
+= bytes_read
;
13587 complaint (_("Invalid .debug_rnglists data (no base address)"));
13590 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13592 if (rlet
== DW_RLE_base_address
)
13597 /* We have no valid base address for the ranges
13599 complaint (_("Invalid .debug_rnglists data (no base address)"));
13603 if (range_beginning
> range_end
)
13605 /* Inverted range entries are invalid. */
13606 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13610 /* Empty range entries have no effect. */
13611 if (range_beginning
== range_end
)
13614 range_beginning
+= base
;
13617 /* A not-uncommon case of bad debug info.
13618 Don't pollute the addrmap with bad data. */
13619 if (range_beginning
+ baseaddr
== 0
13620 && !dwarf2_per_objfile
->has_section_at_zero
)
13622 complaint (_(".debug_rnglists entry has start address of zero"
13623 " [in module %s]"), objfile_name (objfile
));
13627 callback (range_beginning
, range_end
);
13632 complaint (_("Offset %d is not terminated "
13633 "for DW_AT_ranges attribute"),
13641 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13642 Callback's type should be:
13643 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13644 Return 1 if the attributes are present and valid, otherwise, return 0. */
13646 template <typename Callback
>
13648 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13649 Callback
&&callback
)
13651 struct dwarf2_per_objfile
*dwarf2_per_objfile
13652 = cu
->per_cu
->dwarf2_per_objfile
;
13653 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13654 struct comp_unit_head
*cu_header
= &cu
->header
;
13655 bfd
*obfd
= objfile
->obfd
;
13656 unsigned int addr_size
= cu_header
->addr_size
;
13657 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13658 /* Base address selection entry. */
13661 unsigned int dummy
;
13662 const gdb_byte
*buffer
;
13663 CORE_ADDR baseaddr
;
13665 if (cu_header
->version
>= 5)
13666 return dwarf2_rnglists_process (offset
, cu
, callback
);
13668 found_base
= cu
->base_known
;
13669 base
= cu
->base_address
;
13671 dwarf2_per_objfile
->ranges
.read (objfile
);
13672 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13674 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13678 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13680 baseaddr
= objfile
->text_section_offset ();
13684 CORE_ADDR range_beginning
, range_end
;
13686 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13687 buffer
+= addr_size
;
13688 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13689 buffer
+= addr_size
;
13690 offset
+= 2 * addr_size
;
13692 /* An end of list marker is a pair of zero addresses. */
13693 if (range_beginning
== 0 && range_end
== 0)
13694 /* Found the end of list entry. */
13697 /* Each base address selection entry is a pair of 2 values.
13698 The first is the largest possible address, the second is
13699 the base address. Check for a base address here. */
13700 if ((range_beginning
& mask
) == mask
)
13702 /* If we found the largest possible address, then we already
13703 have the base address in range_end. */
13711 /* We have no valid base address for the ranges
13713 complaint (_("Invalid .debug_ranges data (no base address)"));
13717 if (range_beginning
> range_end
)
13719 /* Inverted range entries are invalid. */
13720 complaint (_("Invalid .debug_ranges data (inverted range)"));
13724 /* Empty range entries have no effect. */
13725 if (range_beginning
== range_end
)
13728 range_beginning
+= base
;
13731 /* A not-uncommon case of bad debug info.
13732 Don't pollute the addrmap with bad data. */
13733 if (range_beginning
+ baseaddr
== 0
13734 && !dwarf2_per_objfile
->has_section_at_zero
)
13736 complaint (_(".debug_ranges entry has start address of zero"
13737 " [in module %s]"), objfile_name (objfile
));
13741 callback (range_beginning
, range_end
);
13747 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13748 Return 1 if the attributes are present and valid, otherwise, return 0.
13749 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13752 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13753 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13754 dwarf2_psymtab
*ranges_pst
)
13756 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13757 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13758 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13761 CORE_ADDR high
= 0;
13764 retval
= dwarf2_ranges_process (offset
, cu
,
13765 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13767 if (ranges_pst
!= NULL
)
13772 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13773 range_beginning
+ baseaddr
)
13775 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13776 range_end
+ baseaddr
)
13778 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13779 lowpc
, highpc
- 1, ranges_pst
);
13782 /* FIXME: This is recording everything as a low-high
13783 segment of consecutive addresses. We should have a
13784 data structure for discontiguous block ranges
13788 low
= range_beginning
;
13794 if (range_beginning
< low
)
13795 low
= range_beginning
;
13796 if (range_end
> high
)
13804 /* If the first entry is an end-of-list marker, the range
13805 describes an empty scope, i.e. no instructions. */
13811 *high_return
= high
;
13815 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13816 definition for the return value. *LOWPC and *HIGHPC are set iff
13817 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13819 static enum pc_bounds_kind
13820 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13821 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13822 dwarf2_psymtab
*pst
)
13824 struct dwarf2_per_objfile
*dwarf2_per_objfile
13825 = cu
->per_cu
->dwarf2_per_objfile
;
13826 struct attribute
*attr
;
13827 struct attribute
*attr_high
;
13829 CORE_ADDR high
= 0;
13830 enum pc_bounds_kind ret
;
13832 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13835 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13836 if (attr
!= nullptr)
13838 low
= attr
->value_as_address ();
13839 high
= attr_high
->value_as_address ();
13840 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13844 /* Found high w/o low attribute. */
13845 return PC_BOUNDS_INVALID
;
13847 /* Found consecutive range of addresses. */
13848 ret
= PC_BOUNDS_HIGH_LOW
;
13852 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13855 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13856 We take advantage of the fact that DW_AT_ranges does not appear
13857 in DW_TAG_compile_unit of DWO files. */
13858 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13859 unsigned int ranges_offset
= (DW_UNSND (attr
)
13860 + (need_ranges_base
13864 /* Value of the DW_AT_ranges attribute is the offset in the
13865 .debug_ranges section. */
13866 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13867 return PC_BOUNDS_INVALID
;
13868 /* Found discontinuous range of addresses. */
13869 ret
= PC_BOUNDS_RANGES
;
13872 return PC_BOUNDS_NOT_PRESENT
;
13875 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13877 return PC_BOUNDS_INVALID
;
13879 /* When using the GNU linker, .gnu.linkonce. sections are used to
13880 eliminate duplicate copies of functions and vtables and such.
13881 The linker will arbitrarily choose one and discard the others.
13882 The AT_*_pc values for such functions refer to local labels in
13883 these sections. If the section from that file was discarded, the
13884 labels are not in the output, so the relocs get a value of 0.
13885 If this is a discarded function, mark the pc bounds as invalid,
13886 so that GDB will ignore it. */
13887 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13888 return PC_BOUNDS_INVALID
;
13896 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13897 its low and high PC addresses. Do nothing if these addresses could not
13898 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13899 and HIGHPC to the high address if greater than HIGHPC. */
13902 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13903 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13904 struct dwarf2_cu
*cu
)
13906 CORE_ADDR low
, high
;
13907 struct die_info
*child
= die
->child
;
13909 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13911 *lowpc
= std::min (*lowpc
, low
);
13912 *highpc
= std::max (*highpc
, high
);
13915 /* If the language does not allow nested subprograms (either inside
13916 subprograms or lexical blocks), we're done. */
13917 if (cu
->language
!= language_ada
)
13920 /* Check all the children of the given DIE. If it contains nested
13921 subprograms, then check their pc bounds. Likewise, we need to
13922 check lexical blocks as well, as they may also contain subprogram
13924 while (child
&& child
->tag
)
13926 if (child
->tag
== DW_TAG_subprogram
13927 || child
->tag
== DW_TAG_lexical_block
)
13928 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13929 child
= sibling_die (child
);
13933 /* Get the low and high pc's represented by the scope DIE, and store
13934 them in *LOWPC and *HIGHPC. If the correct values can't be
13935 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13938 get_scope_pc_bounds (struct die_info
*die
,
13939 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13940 struct dwarf2_cu
*cu
)
13942 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13943 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13944 CORE_ADDR current_low
, current_high
;
13946 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13947 >= PC_BOUNDS_RANGES
)
13949 best_low
= current_low
;
13950 best_high
= current_high
;
13954 struct die_info
*child
= die
->child
;
13956 while (child
&& child
->tag
)
13958 switch (child
->tag
) {
13959 case DW_TAG_subprogram
:
13960 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13962 case DW_TAG_namespace
:
13963 case DW_TAG_module
:
13964 /* FIXME: carlton/2004-01-16: Should we do this for
13965 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13966 that current GCC's always emit the DIEs corresponding
13967 to definitions of methods of classes as children of a
13968 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13969 the DIEs giving the declarations, which could be
13970 anywhere). But I don't see any reason why the
13971 standards says that they have to be there. */
13972 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13974 if (current_low
!= ((CORE_ADDR
) -1))
13976 best_low
= std::min (best_low
, current_low
);
13977 best_high
= std::max (best_high
, current_high
);
13985 child
= sibling_die (child
);
13990 *highpc
= best_high
;
13993 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13997 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13998 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14000 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14001 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14002 struct attribute
*attr
;
14003 struct attribute
*attr_high
;
14005 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14008 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14009 if (attr
!= nullptr)
14011 CORE_ADDR low
= attr
->value_as_address ();
14012 CORE_ADDR high
= attr_high
->value_as_address ();
14014 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14017 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14018 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14019 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14023 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14024 if (attr
!= nullptr)
14026 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14027 We take advantage of the fact that DW_AT_ranges does not appear
14028 in DW_TAG_compile_unit of DWO files. */
14029 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14031 /* The value of the DW_AT_ranges attribute is the offset of the
14032 address range list in the .debug_ranges section. */
14033 unsigned long offset
= (DW_UNSND (attr
)
14034 + (need_ranges_base
? cu
->ranges_base
: 0));
14036 std::vector
<blockrange
> blockvec
;
14037 dwarf2_ranges_process (offset
, cu
,
14038 [&] (CORE_ADDR start
, CORE_ADDR end
)
14042 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14043 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14044 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14045 blockvec
.emplace_back (start
, end
);
14048 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14052 /* Check whether the producer field indicates either of GCC < 4.6, or the
14053 Intel C/C++ compiler, and cache the result in CU. */
14056 check_producer (struct dwarf2_cu
*cu
)
14060 if (cu
->producer
== NULL
)
14062 /* For unknown compilers expect their behavior is DWARF version
14065 GCC started to support .debug_types sections by -gdwarf-4 since
14066 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14067 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14068 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14069 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14071 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14073 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14074 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14076 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14078 cu
->producer_is_icc
= true;
14079 cu
->producer_is_icc_lt_14
= major
< 14;
14081 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14082 cu
->producer_is_codewarrior
= true;
14085 /* For other non-GCC compilers, expect their behavior is DWARF version
14089 cu
->checked_producer
= true;
14092 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14093 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14094 during 4.6.0 experimental. */
14097 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14099 if (!cu
->checked_producer
)
14100 check_producer (cu
);
14102 return cu
->producer_is_gxx_lt_4_6
;
14106 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14107 with incorrect is_stmt attributes. */
14110 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14112 if (!cu
->checked_producer
)
14113 check_producer (cu
);
14115 return cu
->producer_is_codewarrior
;
14118 /* Return the default accessibility type if it is not overridden by
14119 DW_AT_accessibility. */
14121 static enum dwarf_access_attribute
14122 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14124 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14126 /* The default DWARF 2 accessibility for members is public, the default
14127 accessibility for inheritance is private. */
14129 if (die
->tag
!= DW_TAG_inheritance
)
14130 return DW_ACCESS_public
;
14132 return DW_ACCESS_private
;
14136 /* DWARF 3+ defines the default accessibility a different way. The same
14137 rules apply now for DW_TAG_inheritance as for the members and it only
14138 depends on the container kind. */
14140 if (die
->parent
->tag
== DW_TAG_class_type
)
14141 return DW_ACCESS_private
;
14143 return DW_ACCESS_public
;
14147 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14148 offset. If the attribute was not found return 0, otherwise return
14149 1. If it was found but could not properly be handled, set *OFFSET
14153 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14156 struct attribute
*attr
;
14158 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14163 /* Note that we do not check for a section offset first here.
14164 This is because DW_AT_data_member_location is new in DWARF 4,
14165 so if we see it, we can assume that a constant form is really
14166 a constant and not a section offset. */
14167 if (attr
->form_is_constant ())
14168 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14169 else if (attr
->form_is_section_offset ())
14170 dwarf2_complex_location_expr_complaint ();
14171 else if (attr
->form_is_block ())
14172 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14174 dwarf2_complex_location_expr_complaint ();
14182 /* Add an aggregate field to the field list. */
14185 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14186 struct dwarf2_cu
*cu
)
14188 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14189 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14190 struct nextfield
*new_field
;
14191 struct attribute
*attr
;
14193 const char *fieldname
= "";
14195 if (die
->tag
== DW_TAG_inheritance
)
14197 fip
->baseclasses
.emplace_back ();
14198 new_field
= &fip
->baseclasses
.back ();
14202 fip
->fields
.emplace_back ();
14203 new_field
= &fip
->fields
.back ();
14206 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14207 if (attr
!= nullptr)
14208 new_field
->accessibility
= DW_UNSND (attr
);
14210 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14211 if (new_field
->accessibility
!= DW_ACCESS_public
)
14212 fip
->non_public_fields
= 1;
14214 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14215 if (attr
!= nullptr)
14216 new_field
->virtuality
= DW_UNSND (attr
);
14218 new_field
->virtuality
= DW_VIRTUALITY_none
;
14220 fp
= &new_field
->field
;
14222 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14226 /* Data member other than a C++ static data member. */
14228 /* Get type of field. */
14229 fp
->type
= die_type (die
, cu
);
14231 SET_FIELD_BITPOS (*fp
, 0);
14233 /* Get bit size of field (zero if none). */
14234 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14235 if (attr
!= nullptr)
14237 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14241 FIELD_BITSIZE (*fp
) = 0;
14244 /* Get bit offset of field. */
14245 if (handle_data_member_location (die
, cu
, &offset
))
14246 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14247 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14248 if (attr
!= nullptr)
14250 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14252 /* For big endian bits, the DW_AT_bit_offset gives the
14253 additional bit offset from the MSB of the containing
14254 anonymous object to the MSB of the field. We don't
14255 have to do anything special since we don't need to
14256 know the size of the anonymous object. */
14257 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14261 /* For little endian bits, compute the bit offset to the
14262 MSB of the anonymous object, subtract off the number of
14263 bits from the MSB of the field to the MSB of the
14264 object, and then subtract off the number of bits of
14265 the field itself. The result is the bit offset of
14266 the LSB of the field. */
14267 int anonymous_size
;
14268 int bit_offset
= DW_UNSND (attr
);
14270 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14271 if (attr
!= nullptr)
14273 /* The size of the anonymous object containing
14274 the bit field is explicit, so use the
14275 indicated size (in bytes). */
14276 anonymous_size
= DW_UNSND (attr
);
14280 /* The size of the anonymous object containing
14281 the bit field must be inferred from the type
14282 attribute of the data member containing the
14284 anonymous_size
= TYPE_LENGTH (fp
->type
);
14286 SET_FIELD_BITPOS (*fp
,
14287 (FIELD_BITPOS (*fp
)
14288 + anonymous_size
* bits_per_byte
14289 - bit_offset
- FIELD_BITSIZE (*fp
)));
14292 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14294 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14295 + dwarf2_get_attr_constant_value (attr
, 0)));
14297 /* Get name of field. */
14298 fieldname
= dwarf2_name (die
, cu
);
14299 if (fieldname
== NULL
)
14302 /* The name is already allocated along with this objfile, so we don't
14303 need to duplicate it for the type. */
14304 fp
->name
= fieldname
;
14306 /* Change accessibility for artificial fields (e.g. virtual table
14307 pointer or virtual base class pointer) to private. */
14308 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14310 FIELD_ARTIFICIAL (*fp
) = 1;
14311 new_field
->accessibility
= DW_ACCESS_private
;
14312 fip
->non_public_fields
= 1;
14315 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14317 /* C++ static member. */
14319 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14320 is a declaration, but all versions of G++ as of this writing
14321 (so through at least 3.2.1) incorrectly generate
14322 DW_TAG_variable tags. */
14324 const char *physname
;
14326 /* Get name of field. */
14327 fieldname
= dwarf2_name (die
, cu
);
14328 if (fieldname
== NULL
)
14331 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14333 /* Only create a symbol if this is an external value.
14334 new_symbol checks this and puts the value in the global symbol
14335 table, which we want. If it is not external, new_symbol
14336 will try to put the value in cu->list_in_scope which is wrong. */
14337 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14339 /* A static const member, not much different than an enum as far as
14340 we're concerned, except that we can support more types. */
14341 new_symbol (die
, NULL
, cu
);
14344 /* Get physical name. */
14345 physname
= dwarf2_physname (fieldname
, die
, cu
);
14347 /* The name is already allocated along with this objfile, so we don't
14348 need to duplicate it for the type. */
14349 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14350 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14351 FIELD_NAME (*fp
) = fieldname
;
14353 else if (die
->tag
== DW_TAG_inheritance
)
14357 /* C++ base class field. */
14358 if (handle_data_member_location (die
, cu
, &offset
))
14359 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14360 FIELD_BITSIZE (*fp
) = 0;
14361 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14362 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14364 else if (die
->tag
== DW_TAG_variant_part
)
14366 /* process_structure_scope will treat this DIE as a union. */
14367 process_structure_scope (die
, cu
);
14369 /* The variant part is relative to the start of the enclosing
14371 SET_FIELD_BITPOS (*fp
, 0);
14372 fp
->type
= get_die_type (die
, cu
);
14373 fp
->artificial
= 1;
14374 fp
->name
= "<<variant>>";
14376 /* Normally a DW_TAG_variant_part won't have a size, but our
14377 representation requires one, so set it to the maximum of the
14378 child sizes, being sure to account for the offset at which
14379 each child is seen. */
14380 if (TYPE_LENGTH (fp
->type
) == 0)
14383 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14385 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14386 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14390 TYPE_LENGTH (fp
->type
) = max
;
14394 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14397 /* Can the type given by DIE define another type? */
14400 type_can_define_types (const struct die_info
*die
)
14404 case DW_TAG_typedef
:
14405 case DW_TAG_class_type
:
14406 case DW_TAG_structure_type
:
14407 case DW_TAG_union_type
:
14408 case DW_TAG_enumeration_type
:
14416 /* Add a type definition defined in the scope of the FIP's class. */
14419 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14420 struct dwarf2_cu
*cu
)
14422 struct decl_field fp
;
14423 memset (&fp
, 0, sizeof (fp
));
14425 gdb_assert (type_can_define_types (die
));
14427 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14428 fp
.name
= dwarf2_name (die
, cu
);
14429 fp
.type
= read_type_die (die
, cu
);
14431 /* Save accessibility. */
14432 enum dwarf_access_attribute accessibility
;
14433 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14435 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14437 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14438 switch (accessibility
)
14440 case DW_ACCESS_public
:
14441 /* The assumed value if neither private nor protected. */
14443 case DW_ACCESS_private
:
14446 case DW_ACCESS_protected
:
14447 fp
.is_protected
= 1;
14450 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14453 if (die
->tag
== DW_TAG_typedef
)
14454 fip
->typedef_field_list
.push_back (fp
);
14456 fip
->nested_types_list
.push_back (fp
);
14459 /* Create the vector of fields, and attach it to the type. */
14462 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14463 struct dwarf2_cu
*cu
)
14465 int nfields
= fip
->nfields ();
14467 /* Record the field count, allocate space for the array of fields,
14468 and create blank accessibility bitfields if necessary. */
14469 TYPE_NFIELDS (type
) = nfields
;
14470 TYPE_FIELDS (type
) = (struct field
*)
14471 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14473 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14475 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14477 TYPE_FIELD_PRIVATE_BITS (type
) =
14478 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14479 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14481 TYPE_FIELD_PROTECTED_BITS (type
) =
14482 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14483 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14485 TYPE_FIELD_IGNORE_BITS (type
) =
14486 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14487 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14490 /* If the type has baseclasses, allocate and clear a bit vector for
14491 TYPE_FIELD_VIRTUAL_BITS. */
14492 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14494 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14495 unsigned char *pointer
;
14497 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14498 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14499 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14500 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14501 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14504 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14506 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14508 for (int index
= 0; index
< nfields
; ++index
)
14510 struct nextfield
&field
= fip
->fields
[index
];
14512 if (field
.variant
.is_discriminant
)
14513 di
->discriminant_index
= index
;
14514 else if (field
.variant
.default_branch
)
14515 di
->default_index
= index
;
14517 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14521 /* Copy the saved-up fields into the field vector. */
14522 for (int i
= 0; i
< nfields
; ++i
)
14524 struct nextfield
&field
14525 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14526 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14528 TYPE_FIELD (type
, i
) = field
.field
;
14529 switch (field
.accessibility
)
14531 case DW_ACCESS_private
:
14532 if (cu
->language
!= language_ada
)
14533 SET_TYPE_FIELD_PRIVATE (type
, i
);
14536 case DW_ACCESS_protected
:
14537 if (cu
->language
!= language_ada
)
14538 SET_TYPE_FIELD_PROTECTED (type
, i
);
14541 case DW_ACCESS_public
:
14545 /* Unknown accessibility. Complain and treat it as public. */
14547 complaint (_("unsupported accessibility %d"),
14548 field
.accessibility
);
14552 if (i
< fip
->baseclasses
.size ())
14554 switch (field
.virtuality
)
14556 case DW_VIRTUALITY_virtual
:
14557 case DW_VIRTUALITY_pure_virtual
:
14558 if (cu
->language
== language_ada
)
14559 error (_("unexpected virtuality in component of Ada type"));
14560 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14567 /* Return true if this member function is a constructor, false
14571 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14573 const char *fieldname
;
14574 const char *type_name
;
14577 if (die
->parent
== NULL
)
14580 if (die
->parent
->tag
!= DW_TAG_structure_type
14581 && die
->parent
->tag
!= DW_TAG_union_type
14582 && die
->parent
->tag
!= DW_TAG_class_type
)
14585 fieldname
= dwarf2_name (die
, cu
);
14586 type_name
= dwarf2_name (die
->parent
, cu
);
14587 if (fieldname
== NULL
|| type_name
== NULL
)
14590 len
= strlen (fieldname
);
14591 return (strncmp (fieldname
, type_name
, len
) == 0
14592 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14595 /* Check if the given VALUE is a recognized enum
14596 dwarf_defaulted_attribute constant according to DWARF5 spec,
14600 is_valid_DW_AT_defaulted (ULONGEST value
)
14604 case DW_DEFAULTED_no
:
14605 case DW_DEFAULTED_in_class
:
14606 case DW_DEFAULTED_out_of_class
:
14610 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14614 /* Add a member function to the proper fieldlist. */
14617 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14618 struct type
*type
, struct dwarf2_cu
*cu
)
14620 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14621 struct attribute
*attr
;
14623 struct fnfieldlist
*flp
= nullptr;
14624 struct fn_field
*fnp
;
14625 const char *fieldname
;
14626 struct type
*this_type
;
14627 enum dwarf_access_attribute accessibility
;
14629 if (cu
->language
== language_ada
)
14630 error (_("unexpected member function in Ada type"));
14632 /* Get name of member function. */
14633 fieldname
= dwarf2_name (die
, cu
);
14634 if (fieldname
== NULL
)
14637 /* Look up member function name in fieldlist. */
14638 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14640 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14642 flp
= &fip
->fnfieldlists
[i
];
14647 /* Create a new fnfieldlist if necessary. */
14648 if (flp
== nullptr)
14650 fip
->fnfieldlists
.emplace_back ();
14651 flp
= &fip
->fnfieldlists
.back ();
14652 flp
->name
= fieldname
;
14653 i
= fip
->fnfieldlists
.size () - 1;
14656 /* Create a new member function field and add it to the vector of
14658 flp
->fnfields
.emplace_back ();
14659 fnp
= &flp
->fnfields
.back ();
14661 /* Delay processing of the physname until later. */
14662 if (cu
->language
== language_cplus
)
14663 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14667 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14668 fnp
->physname
= physname
? physname
: "";
14671 fnp
->type
= alloc_type (objfile
);
14672 this_type
= read_type_die (die
, cu
);
14673 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14675 int nparams
= TYPE_NFIELDS (this_type
);
14677 /* TYPE is the domain of this method, and THIS_TYPE is the type
14678 of the method itself (TYPE_CODE_METHOD). */
14679 smash_to_method_type (fnp
->type
, type
,
14680 TYPE_TARGET_TYPE (this_type
),
14681 TYPE_FIELDS (this_type
),
14682 TYPE_NFIELDS (this_type
),
14683 TYPE_VARARGS (this_type
));
14685 /* Handle static member functions.
14686 Dwarf2 has no clean way to discern C++ static and non-static
14687 member functions. G++ helps GDB by marking the first
14688 parameter for non-static member functions (which is the this
14689 pointer) as artificial. We obtain this information from
14690 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14691 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14692 fnp
->voffset
= VOFFSET_STATIC
;
14695 complaint (_("member function type missing for '%s'"),
14696 dwarf2_full_name (fieldname
, die
, cu
));
14698 /* Get fcontext from DW_AT_containing_type if present. */
14699 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14700 fnp
->fcontext
= die_containing_type (die
, cu
);
14702 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14703 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14705 /* Get accessibility. */
14706 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14707 if (attr
!= nullptr)
14708 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14710 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14711 switch (accessibility
)
14713 case DW_ACCESS_private
:
14714 fnp
->is_private
= 1;
14716 case DW_ACCESS_protected
:
14717 fnp
->is_protected
= 1;
14721 /* Check for artificial methods. */
14722 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14723 if (attr
&& DW_UNSND (attr
) != 0)
14724 fnp
->is_artificial
= 1;
14726 /* Check for defaulted methods. */
14727 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14728 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14729 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14731 /* Check for deleted methods. */
14732 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14733 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14734 fnp
->is_deleted
= 1;
14736 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14738 /* Get index in virtual function table if it is a virtual member
14739 function. For older versions of GCC, this is an offset in the
14740 appropriate virtual table, as specified by DW_AT_containing_type.
14741 For everyone else, it is an expression to be evaluated relative
14742 to the object address. */
14744 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14745 if (attr
!= nullptr)
14747 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14749 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14751 /* Old-style GCC. */
14752 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14754 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14755 || (DW_BLOCK (attr
)->size
> 1
14756 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14757 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14759 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14760 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14761 dwarf2_complex_location_expr_complaint ();
14763 fnp
->voffset
/= cu
->header
.addr_size
;
14767 dwarf2_complex_location_expr_complaint ();
14769 if (!fnp
->fcontext
)
14771 /* If there is no `this' field and no DW_AT_containing_type,
14772 we cannot actually find a base class context for the
14774 if (TYPE_NFIELDS (this_type
) == 0
14775 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14777 complaint (_("cannot determine context for virtual member "
14778 "function \"%s\" (offset %s)"),
14779 fieldname
, sect_offset_str (die
->sect_off
));
14784 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14788 else if (attr
->form_is_section_offset ())
14790 dwarf2_complex_location_expr_complaint ();
14794 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14800 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14801 if (attr
&& DW_UNSND (attr
))
14803 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14804 complaint (_("Member function \"%s\" (offset %s) is virtual "
14805 "but the vtable offset is not specified"),
14806 fieldname
, sect_offset_str (die
->sect_off
));
14807 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14808 TYPE_CPLUS_DYNAMIC (type
) = 1;
14813 /* Create the vector of member function fields, and attach it to the type. */
14816 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14817 struct dwarf2_cu
*cu
)
14819 if (cu
->language
== language_ada
)
14820 error (_("unexpected member functions in Ada type"));
14822 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14823 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14825 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14827 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14829 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14830 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14832 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14833 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14834 fn_flp
->fn_fields
= (struct fn_field
*)
14835 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14837 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14838 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14841 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14844 /* Returns non-zero if NAME is the name of a vtable member in CU's
14845 language, zero otherwise. */
14847 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14849 static const char vptr
[] = "_vptr";
14851 /* Look for the C++ form of the vtable. */
14852 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14858 /* GCC outputs unnamed structures that are really pointers to member
14859 functions, with the ABI-specified layout. If TYPE describes
14860 such a structure, smash it into a member function type.
14862 GCC shouldn't do this; it should just output pointer to member DIEs.
14863 This is GCC PR debug/28767. */
14866 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14868 struct type
*pfn_type
, *self_type
, *new_type
;
14870 /* Check for a structure with no name and two children. */
14871 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14874 /* Check for __pfn and __delta members. */
14875 if (TYPE_FIELD_NAME (type
, 0) == NULL
14876 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14877 || TYPE_FIELD_NAME (type
, 1) == NULL
14878 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14881 /* Find the type of the method. */
14882 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14883 if (pfn_type
== NULL
14884 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14885 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14888 /* Look for the "this" argument. */
14889 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14890 if (TYPE_NFIELDS (pfn_type
) == 0
14891 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14892 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14895 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14896 new_type
= alloc_type (objfile
);
14897 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14898 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14899 TYPE_VARARGS (pfn_type
));
14900 smash_to_methodptr_type (type
, new_type
);
14903 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14904 appropriate error checking and issuing complaints if there is a
14908 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14910 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14912 if (attr
== nullptr)
14915 if (!attr
->form_is_constant ())
14917 complaint (_("DW_AT_alignment must have constant form"
14918 " - DIE at %s [in module %s]"),
14919 sect_offset_str (die
->sect_off
),
14920 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14925 if (attr
->form
== DW_FORM_sdata
)
14927 LONGEST val
= DW_SND (attr
);
14930 complaint (_("DW_AT_alignment value must not be negative"
14931 " - DIE at %s [in module %s]"),
14932 sect_offset_str (die
->sect_off
),
14933 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14939 align
= DW_UNSND (attr
);
14943 complaint (_("DW_AT_alignment value must not be zero"
14944 " - DIE at %s [in module %s]"),
14945 sect_offset_str (die
->sect_off
),
14946 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14949 if ((align
& (align
- 1)) != 0)
14951 complaint (_("DW_AT_alignment value must be a power of 2"
14952 " - DIE at %s [in module %s]"),
14953 sect_offset_str (die
->sect_off
),
14954 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14961 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14962 the alignment for TYPE. */
14965 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14968 if (!set_type_align (type
, get_alignment (cu
, die
)))
14969 complaint (_("DW_AT_alignment value too large"
14970 " - DIE at %s [in module %s]"),
14971 sect_offset_str (die
->sect_off
),
14972 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14975 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14976 constant for a type, according to DWARF5 spec, Table 5.5. */
14979 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14984 case DW_CC_pass_by_reference
:
14985 case DW_CC_pass_by_value
:
14989 complaint (_("unrecognized DW_AT_calling_convention value "
14990 "(%s) for a type"), pulongest (value
));
14995 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14996 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14997 also according to GNU-specific values (see include/dwarf2.h). */
15000 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15005 case DW_CC_program
:
15009 case DW_CC_GNU_renesas_sh
:
15010 case DW_CC_GNU_borland_fastcall_i386
:
15011 case DW_CC_GDB_IBM_OpenCL
:
15015 complaint (_("unrecognized DW_AT_calling_convention value "
15016 "(%s) for a subroutine"), pulongest (value
));
15021 /* Called when we find the DIE that starts a structure or union scope
15022 (definition) to create a type for the structure or union. Fill in
15023 the type's name and general properties; the members will not be
15024 processed until process_structure_scope. A symbol table entry for
15025 the type will also not be done until process_structure_scope (assuming
15026 the type has a name).
15028 NOTE: we need to call these functions regardless of whether or not the
15029 DIE has a DW_AT_name attribute, since it might be an anonymous
15030 structure or union. This gets the type entered into our set of
15031 user defined types. */
15033 static struct type
*
15034 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15036 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15038 struct attribute
*attr
;
15041 /* If the definition of this type lives in .debug_types, read that type.
15042 Don't follow DW_AT_specification though, that will take us back up
15043 the chain and we want to go down. */
15044 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15045 if (attr
!= nullptr)
15047 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15049 /* The type's CU may not be the same as CU.
15050 Ensure TYPE is recorded with CU in die_type_hash. */
15051 return set_die_type (die
, type
, cu
);
15054 type
= alloc_type (objfile
);
15055 INIT_CPLUS_SPECIFIC (type
);
15057 name
= dwarf2_name (die
, cu
);
15060 if (cu
->language
== language_cplus
15061 || cu
->language
== language_d
15062 || cu
->language
== language_rust
)
15064 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15066 /* dwarf2_full_name might have already finished building the DIE's
15067 type. If so, there is no need to continue. */
15068 if (get_die_type (die
, cu
) != NULL
)
15069 return get_die_type (die
, cu
);
15071 TYPE_NAME (type
) = full_name
;
15075 /* The name is already allocated along with this objfile, so
15076 we don't need to duplicate it for the type. */
15077 TYPE_NAME (type
) = name
;
15081 if (die
->tag
== DW_TAG_structure_type
)
15083 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15085 else if (die
->tag
== DW_TAG_union_type
)
15087 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15089 else if (die
->tag
== DW_TAG_variant_part
)
15091 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15092 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15096 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15099 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15100 TYPE_DECLARED_CLASS (type
) = 1;
15102 /* Store the calling convention in the type if it's available in
15103 the die. Otherwise the calling convention remains set to
15104 the default value DW_CC_normal. */
15105 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15106 if (attr
!= nullptr
15107 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15109 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15110 TYPE_CPLUS_CALLING_CONVENTION (type
)
15111 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15114 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15115 if (attr
!= nullptr)
15117 if (attr
->form_is_constant ())
15118 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15121 /* For the moment, dynamic type sizes are not supported
15122 by GDB's struct type. The actual size is determined
15123 on-demand when resolving the type of a given object,
15124 so set the type's length to zero for now. Otherwise,
15125 we record an expression as the length, and that expression
15126 could lead to a very large value, which could eventually
15127 lead to us trying to allocate that much memory when creating
15128 a value of that type. */
15129 TYPE_LENGTH (type
) = 0;
15134 TYPE_LENGTH (type
) = 0;
15137 maybe_set_alignment (cu
, die
, type
);
15139 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15141 /* ICC<14 does not output the required DW_AT_declaration on
15142 incomplete types, but gives them a size of zero. */
15143 TYPE_STUB (type
) = 1;
15146 TYPE_STUB_SUPPORTED (type
) = 1;
15148 if (die_is_declaration (die
, cu
))
15149 TYPE_STUB (type
) = 1;
15150 else if (attr
== NULL
&& die
->child
== NULL
15151 && producer_is_realview (cu
->producer
))
15152 /* RealView does not output the required DW_AT_declaration
15153 on incomplete types. */
15154 TYPE_STUB (type
) = 1;
15156 /* We need to add the type field to the die immediately so we don't
15157 infinitely recurse when dealing with pointers to the structure
15158 type within the structure itself. */
15159 set_die_type (die
, type
, cu
);
15161 /* set_die_type should be already done. */
15162 set_descriptive_type (type
, die
, cu
);
15167 /* A helper for process_structure_scope that handles a single member
15171 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15172 struct field_info
*fi
,
15173 std::vector
<struct symbol
*> *template_args
,
15174 struct dwarf2_cu
*cu
)
15176 if (child_die
->tag
== DW_TAG_member
15177 || child_die
->tag
== DW_TAG_variable
15178 || child_die
->tag
== DW_TAG_variant_part
)
15180 /* NOTE: carlton/2002-11-05: A C++ static data member
15181 should be a DW_TAG_member that is a declaration, but
15182 all versions of G++ as of this writing (so through at
15183 least 3.2.1) incorrectly generate DW_TAG_variable
15184 tags for them instead. */
15185 dwarf2_add_field (fi
, child_die
, cu
);
15187 else if (child_die
->tag
== DW_TAG_subprogram
)
15189 /* Rust doesn't have member functions in the C++ sense.
15190 However, it does emit ordinary functions as children
15191 of a struct DIE. */
15192 if (cu
->language
== language_rust
)
15193 read_func_scope (child_die
, cu
);
15196 /* C++ member function. */
15197 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15200 else if (child_die
->tag
== DW_TAG_inheritance
)
15202 /* C++ base class field. */
15203 dwarf2_add_field (fi
, child_die
, cu
);
15205 else if (type_can_define_types (child_die
))
15206 dwarf2_add_type_defn (fi
, child_die
, cu
);
15207 else if (child_die
->tag
== DW_TAG_template_type_param
15208 || child_die
->tag
== DW_TAG_template_value_param
)
15210 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15213 template_args
->push_back (arg
);
15215 else if (child_die
->tag
== DW_TAG_variant
)
15217 /* In a variant we want to get the discriminant and also add a
15218 field for our sole member child. */
15219 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15221 for (die_info
*variant_child
= child_die
->child
;
15222 variant_child
!= NULL
;
15223 variant_child
= sibling_die (variant_child
))
15225 if (variant_child
->tag
== DW_TAG_member
)
15227 handle_struct_member_die (variant_child
, type
, fi
,
15228 template_args
, cu
);
15229 /* Only handle the one. */
15234 /* We don't handle this but we might as well report it if we see
15236 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15237 complaint (_("DW_AT_discr_list is not supported yet"
15238 " - DIE at %s [in module %s]"),
15239 sect_offset_str (child_die
->sect_off
),
15240 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15242 /* The first field was just added, so we can stash the
15243 discriminant there. */
15244 gdb_assert (!fi
->fields
.empty ());
15246 fi
->fields
.back ().variant
.default_branch
= true;
15248 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15252 /* Finish creating a structure or union type, including filling in
15253 its members and creating a symbol for it. */
15256 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15258 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15259 struct die_info
*child_die
;
15262 type
= get_die_type (die
, cu
);
15264 type
= read_structure_type (die
, cu
);
15266 /* When reading a DW_TAG_variant_part, we need to notice when we
15267 read the discriminant member, so we can record it later in the
15268 discriminant_info. */
15269 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15270 sect_offset discr_offset
{};
15271 bool has_template_parameters
= false;
15273 if (is_variant_part
)
15275 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15278 /* Maybe it's a univariant form, an extension we support.
15279 In this case arrange not to check the offset. */
15280 is_variant_part
= false;
15282 else if (discr
->form_is_ref ())
15284 struct dwarf2_cu
*target_cu
= cu
;
15285 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15287 discr_offset
= target_die
->sect_off
;
15291 complaint (_("DW_AT_discr does not have DIE reference form"
15292 " - DIE at %s [in module %s]"),
15293 sect_offset_str (die
->sect_off
),
15294 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15295 is_variant_part
= false;
15299 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15301 struct field_info fi
;
15302 std::vector
<struct symbol
*> template_args
;
15304 child_die
= die
->child
;
15306 while (child_die
&& child_die
->tag
)
15308 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15310 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15311 fi
.fields
.back ().variant
.is_discriminant
= true;
15313 child_die
= sibling_die (child_die
);
15316 /* Attach template arguments to type. */
15317 if (!template_args
.empty ())
15319 has_template_parameters
= true;
15320 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15321 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15322 TYPE_TEMPLATE_ARGUMENTS (type
)
15323 = XOBNEWVEC (&objfile
->objfile_obstack
,
15325 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15326 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15327 template_args
.data (),
15328 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15329 * sizeof (struct symbol
*)));
15332 /* Attach fields and member functions to the type. */
15333 if (fi
.nfields () > 0)
15334 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15335 if (!fi
.fnfieldlists
.empty ())
15337 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15339 /* Get the type which refers to the base class (possibly this
15340 class itself) which contains the vtable pointer for the current
15341 class from the DW_AT_containing_type attribute. This use of
15342 DW_AT_containing_type is a GNU extension. */
15344 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15346 struct type
*t
= die_containing_type (die
, cu
);
15348 set_type_vptr_basetype (type
, t
);
15353 /* Our own class provides vtbl ptr. */
15354 for (i
= TYPE_NFIELDS (t
) - 1;
15355 i
>= TYPE_N_BASECLASSES (t
);
15358 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15360 if (is_vtable_name (fieldname
, cu
))
15362 set_type_vptr_fieldno (type
, i
);
15367 /* Complain if virtual function table field not found. */
15368 if (i
< TYPE_N_BASECLASSES (t
))
15369 complaint (_("virtual function table pointer "
15370 "not found when defining class '%s'"),
15371 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15375 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15378 else if (cu
->producer
15379 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15381 /* The IBM XLC compiler does not provide direct indication
15382 of the containing type, but the vtable pointer is
15383 always named __vfp. */
15387 for (i
= TYPE_NFIELDS (type
) - 1;
15388 i
>= TYPE_N_BASECLASSES (type
);
15391 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15393 set_type_vptr_fieldno (type
, i
);
15394 set_type_vptr_basetype (type
, type
);
15401 /* Copy fi.typedef_field_list linked list elements content into the
15402 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15403 if (!fi
.typedef_field_list
.empty ())
15405 int count
= fi
.typedef_field_list
.size ();
15407 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15408 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15409 = ((struct decl_field
*)
15411 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15412 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15414 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15415 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15418 /* Copy fi.nested_types_list linked list elements content into the
15419 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15420 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15422 int count
= fi
.nested_types_list
.size ();
15424 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15425 TYPE_NESTED_TYPES_ARRAY (type
)
15426 = ((struct decl_field
*)
15427 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15428 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15430 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15431 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15435 quirk_gcc_member_function_pointer (type
, objfile
);
15436 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15437 cu
->rust_unions
.push_back (type
);
15439 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15440 snapshots) has been known to create a die giving a declaration
15441 for a class that has, as a child, a die giving a definition for a
15442 nested class. So we have to process our children even if the
15443 current die is a declaration. Normally, of course, a declaration
15444 won't have any children at all. */
15446 child_die
= die
->child
;
15448 while (child_die
!= NULL
&& child_die
->tag
)
15450 if (child_die
->tag
== DW_TAG_member
15451 || child_die
->tag
== DW_TAG_variable
15452 || child_die
->tag
== DW_TAG_inheritance
15453 || child_die
->tag
== DW_TAG_template_value_param
15454 || child_die
->tag
== DW_TAG_template_type_param
)
15459 process_die (child_die
, cu
);
15461 child_die
= sibling_die (child_die
);
15464 /* Do not consider external references. According to the DWARF standard,
15465 these DIEs are identified by the fact that they have no byte_size
15466 attribute, and a declaration attribute. */
15467 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15468 || !die_is_declaration (die
, cu
))
15470 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15472 if (has_template_parameters
)
15474 struct symtab
*symtab
;
15475 if (sym
!= nullptr)
15476 symtab
= symbol_symtab (sym
);
15477 else if (cu
->line_header
!= nullptr)
15479 /* Any related symtab will do. */
15481 = cu
->line_header
->file_names ()[0].symtab
;
15486 complaint (_("could not find suitable "
15487 "symtab for template parameter"
15488 " - DIE at %s [in module %s]"),
15489 sect_offset_str (die
->sect_off
),
15490 objfile_name (objfile
));
15493 if (symtab
!= nullptr)
15495 /* Make sure that the symtab is set on the new symbols.
15496 Even though they don't appear in this symtab directly,
15497 other parts of gdb assume that symbols do, and this is
15498 reasonably true. */
15499 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15500 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15506 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15507 update TYPE using some information only available in DIE's children. */
15510 update_enumeration_type_from_children (struct die_info
*die
,
15512 struct dwarf2_cu
*cu
)
15514 struct die_info
*child_die
;
15515 int unsigned_enum
= 1;
15518 auto_obstack obstack
;
15520 for (child_die
= die
->child
;
15521 child_die
!= NULL
&& child_die
->tag
;
15522 child_die
= sibling_die (child_die
))
15524 struct attribute
*attr
;
15526 const gdb_byte
*bytes
;
15527 struct dwarf2_locexpr_baton
*baton
;
15530 if (child_die
->tag
!= DW_TAG_enumerator
)
15533 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15537 name
= dwarf2_name (child_die
, cu
);
15539 name
= "<anonymous enumerator>";
15541 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15542 &value
, &bytes
, &baton
);
15550 if (count_one_bits_ll (value
) >= 2)
15554 /* If we already know that the enum type is neither unsigned, nor
15555 a flag type, no need to look at the rest of the enumerates. */
15556 if (!unsigned_enum
&& !flag_enum
)
15561 TYPE_UNSIGNED (type
) = 1;
15563 TYPE_FLAG_ENUM (type
) = 1;
15566 /* Given a DW_AT_enumeration_type die, set its type. We do not
15567 complete the type's fields yet, or create any symbols. */
15569 static struct type
*
15570 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15572 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15574 struct attribute
*attr
;
15577 /* If the definition of this type lives in .debug_types, read that type.
15578 Don't follow DW_AT_specification though, that will take us back up
15579 the chain and we want to go down. */
15580 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15581 if (attr
!= nullptr)
15583 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15585 /* The type's CU may not be the same as CU.
15586 Ensure TYPE is recorded with CU in die_type_hash. */
15587 return set_die_type (die
, type
, cu
);
15590 type
= alloc_type (objfile
);
15592 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15593 name
= dwarf2_full_name (NULL
, die
, cu
);
15595 TYPE_NAME (type
) = name
;
15597 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15600 struct type
*underlying_type
= die_type (die
, cu
);
15602 TYPE_TARGET_TYPE (type
) = underlying_type
;
15605 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15606 if (attr
!= nullptr)
15608 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15612 TYPE_LENGTH (type
) = 0;
15615 maybe_set_alignment (cu
, die
, type
);
15617 /* The enumeration DIE can be incomplete. In Ada, any type can be
15618 declared as private in the package spec, and then defined only
15619 inside the package body. Such types are known as Taft Amendment
15620 Types. When another package uses such a type, an incomplete DIE
15621 may be generated by the compiler. */
15622 if (die_is_declaration (die
, cu
))
15623 TYPE_STUB (type
) = 1;
15625 /* Finish the creation of this type by using the enum's children.
15626 We must call this even when the underlying type has been provided
15627 so that we can determine if we're looking at a "flag" enum. */
15628 update_enumeration_type_from_children (die
, type
, cu
);
15630 /* If this type has an underlying type that is not a stub, then we
15631 may use its attributes. We always use the "unsigned" attribute
15632 in this situation, because ordinarily we guess whether the type
15633 is unsigned -- but the guess can be wrong and the underlying type
15634 can tell us the reality. However, we defer to a local size
15635 attribute if one exists, because this lets the compiler override
15636 the underlying type if needed. */
15637 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15639 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15640 if (TYPE_LENGTH (type
) == 0)
15641 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15642 if (TYPE_RAW_ALIGN (type
) == 0
15643 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15644 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15647 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15649 return set_die_type (die
, type
, cu
);
15652 /* Given a pointer to a die which begins an enumeration, process all
15653 the dies that define the members of the enumeration, and create the
15654 symbol for the enumeration type.
15656 NOTE: We reverse the order of the element list. */
15659 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15661 struct type
*this_type
;
15663 this_type
= get_die_type (die
, cu
);
15664 if (this_type
== NULL
)
15665 this_type
= read_enumeration_type (die
, cu
);
15667 if (die
->child
!= NULL
)
15669 struct die_info
*child_die
;
15670 struct symbol
*sym
;
15671 std::vector
<struct field
> fields
;
15674 child_die
= die
->child
;
15675 while (child_die
&& child_die
->tag
)
15677 if (child_die
->tag
!= DW_TAG_enumerator
)
15679 process_die (child_die
, cu
);
15683 name
= dwarf2_name (child_die
, cu
);
15686 sym
= new_symbol (child_die
, this_type
, cu
);
15688 fields
.emplace_back ();
15689 struct field
&field
= fields
.back ();
15691 FIELD_NAME (field
) = sym
->linkage_name ();
15692 FIELD_TYPE (field
) = NULL
;
15693 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15694 FIELD_BITSIZE (field
) = 0;
15698 child_die
= sibling_die (child_die
);
15701 if (!fields
.empty ())
15703 TYPE_NFIELDS (this_type
) = fields
.size ();
15704 TYPE_FIELDS (this_type
) = (struct field
*)
15705 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15706 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15707 sizeof (struct field
) * fields
.size ());
15711 /* If we are reading an enum from a .debug_types unit, and the enum
15712 is a declaration, and the enum is not the signatured type in the
15713 unit, then we do not want to add a symbol for it. Adding a
15714 symbol would in some cases obscure the true definition of the
15715 enum, giving users an incomplete type when the definition is
15716 actually available. Note that we do not want to do this for all
15717 enums which are just declarations, because C++0x allows forward
15718 enum declarations. */
15719 if (cu
->per_cu
->is_debug_types
15720 && die_is_declaration (die
, cu
))
15722 struct signatured_type
*sig_type
;
15724 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15725 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15726 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15730 new_symbol (die
, this_type
, cu
);
15733 /* Extract all information from a DW_TAG_array_type DIE and put it in
15734 the DIE's type field. For now, this only handles one dimensional
15737 static struct type
*
15738 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15740 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15741 struct die_info
*child_die
;
15743 struct type
*element_type
, *range_type
, *index_type
;
15744 struct attribute
*attr
;
15746 struct dynamic_prop
*byte_stride_prop
= NULL
;
15747 unsigned int bit_stride
= 0;
15749 element_type
= die_type (die
, cu
);
15751 /* The die_type call above may have already set the type for this DIE. */
15752 type
= get_die_type (die
, cu
);
15756 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15760 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15763 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15764 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15768 complaint (_("unable to read array DW_AT_byte_stride "
15769 " - DIE at %s [in module %s]"),
15770 sect_offset_str (die
->sect_off
),
15771 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15772 /* Ignore this attribute. We will likely not be able to print
15773 arrays of this type correctly, but there is little we can do
15774 to help if we cannot read the attribute's value. */
15775 byte_stride_prop
= NULL
;
15779 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15781 bit_stride
= DW_UNSND (attr
);
15783 /* Irix 6.2 native cc creates array types without children for
15784 arrays with unspecified length. */
15785 if (die
->child
== NULL
)
15787 index_type
= objfile_type (objfile
)->builtin_int
;
15788 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15789 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15790 byte_stride_prop
, bit_stride
);
15791 return set_die_type (die
, type
, cu
);
15794 std::vector
<struct type
*> range_types
;
15795 child_die
= die
->child
;
15796 while (child_die
&& child_die
->tag
)
15798 if (child_die
->tag
== DW_TAG_subrange_type
)
15800 struct type
*child_type
= read_type_die (child_die
, cu
);
15802 if (child_type
!= NULL
)
15804 /* The range type was succesfully read. Save it for the
15805 array type creation. */
15806 range_types
.push_back (child_type
);
15809 child_die
= sibling_die (child_die
);
15812 /* Dwarf2 dimensions are output from left to right, create the
15813 necessary array types in backwards order. */
15815 type
= element_type
;
15817 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15821 while (i
< range_types
.size ())
15822 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15823 byte_stride_prop
, bit_stride
);
15827 size_t ndim
= range_types
.size ();
15829 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15830 byte_stride_prop
, bit_stride
);
15833 /* Understand Dwarf2 support for vector types (like they occur on
15834 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15835 array type. This is not part of the Dwarf2/3 standard yet, but a
15836 custom vendor extension. The main difference between a regular
15837 array and the vector variant is that vectors are passed by value
15839 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15840 if (attr
!= nullptr)
15841 make_vector_type (type
);
15843 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15844 implementation may choose to implement triple vectors using this
15846 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15847 if (attr
!= nullptr)
15849 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15850 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15852 complaint (_("DW_AT_byte_size for array type smaller "
15853 "than the total size of elements"));
15856 name
= dwarf2_name (die
, cu
);
15858 TYPE_NAME (type
) = name
;
15860 maybe_set_alignment (cu
, die
, type
);
15862 /* Install the type in the die. */
15863 set_die_type (die
, type
, cu
);
15865 /* set_die_type should be already done. */
15866 set_descriptive_type (type
, die
, cu
);
15871 static enum dwarf_array_dim_ordering
15872 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15874 struct attribute
*attr
;
15876 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15878 if (attr
!= nullptr)
15879 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15881 /* GNU F77 is a special case, as at 08/2004 array type info is the
15882 opposite order to the dwarf2 specification, but data is still
15883 laid out as per normal fortran.
15885 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15886 version checking. */
15888 if (cu
->language
== language_fortran
15889 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15891 return DW_ORD_row_major
;
15894 switch (cu
->language_defn
->la_array_ordering
)
15896 case array_column_major
:
15897 return DW_ORD_col_major
;
15898 case array_row_major
:
15900 return DW_ORD_row_major
;
15904 /* Extract all information from a DW_TAG_set_type DIE and put it in
15905 the DIE's type field. */
15907 static struct type
*
15908 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15910 struct type
*domain_type
, *set_type
;
15911 struct attribute
*attr
;
15913 domain_type
= die_type (die
, cu
);
15915 /* The die_type call above may have already set the type for this DIE. */
15916 set_type
= get_die_type (die
, cu
);
15920 set_type
= create_set_type (NULL
, domain_type
);
15922 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15923 if (attr
!= nullptr)
15924 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15926 maybe_set_alignment (cu
, die
, set_type
);
15928 return set_die_type (die
, set_type
, cu
);
15931 /* A helper for read_common_block that creates a locexpr baton.
15932 SYM is the symbol which we are marking as computed.
15933 COMMON_DIE is the DIE for the common block.
15934 COMMON_LOC is the location expression attribute for the common
15936 MEMBER_LOC is the location expression attribute for the particular
15937 member of the common block that we are processing.
15938 CU is the CU from which the above come. */
15941 mark_common_block_symbol_computed (struct symbol
*sym
,
15942 struct die_info
*common_die
,
15943 struct attribute
*common_loc
,
15944 struct attribute
*member_loc
,
15945 struct dwarf2_cu
*cu
)
15947 struct dwarf2_per_objfile
*dwarf2_per_objfile
15948 = cu
->per_cu
->dwarf2_per_objfile
;
15949 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15950 struct dwarf2_locexpr_baton
*baton
;
15952 unsigned int cu_off
;
15953 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15954 LONGEST offset
= 0;
15956 gdb_assert (common_loc
&& member_loc
);
15957 gdb_assert (common_loc
->form_is_block ());
15958 gdb_assert (member_loc
->form_is_block ()
15959 || member_loc
->form_is_constant ());
15961 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15962 baton
->per_cu
= cu
->per_cu
;
15963 gdb_assert (baton
->per_cu
);
15965 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15967 if (member_loc
->form_is_constant ())
15969 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15970 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15973 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15975 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15978 *ptr
++ = DW_OP_call4
;
15979 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15980 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15983 if (member_loc
->form_is_constant ())
15985 *ptr
++ = DW_OP_addr
;
15986 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15987 ptr
+= cu
->header
.addr_size
;
15991 /* We have to copy the data here, because DW_OP_call4 will only
15992 use a DW_AT_location attribute. */
15993 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15994 ptr
+= DW_BLOCK (member_loc
)->size
;
15997 *ptr
++ = DW_OP_plus
;
15998 gdb_assert (ptr
- baton
->data
== baton
->size
);
16000 SYMBOL_LOCATION_BATON (sym
) = baton
;
16001 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16004 /* Create appropriate locally-scoped variables for all the
16005 DW_TAG_common_block entries. Also create a struct common_block
16006 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16007 is used to separate the common blocks name namespace from regular
16011 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16013 struct attribute
*attr
;
16015 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16016 if (attr
!= nullptr)
16018 /* Support the .debug_loc offsets. */
16019 if (attr
->form_is_block ())
16023 else if (attr
->form_is_section_offset ())
16025 dwarf2_complex_location_expr_complaint ();
16030 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16031 "common block member");
16036 if (die
->child
!= NULL
)
16038 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16039 struct die_info
*child_die
;
16040 size_t n_entries
= 0, size
;
16041 struct common_block
*common_block
;
16042 struct symbol
*sym
;
16044 for (child_die
= die
->child
;
16045 child_die
&& child_die
->tag
;
16046 child_die
= sibling_die (child_die
))
16049 size
= (sizeof (struct common_block
)
16050 + (n_entries
- 1) * sizeof (struct symbol
*));
16052 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16054 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16055 common_block
->n_entries
= 0;
16057 for (child_die
= die
->child
;
16058 child_die
&& child_die
->tag
;
16059 child_die
= sibling_die (child_die
))
16061 /* Create the symbol in the DW_TAG_common_block block in the current
16063 sym
= new_symbol (child_die
, NULL
, cu
);
16066 struct attribute
*member_loc
;
16068 common_block
->contents
[common_block
->n_entries
++] = sym
;
16070 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16074 /* GDB has handled this for a long time, but it is
16075 not specified by DWARF. It seems to have been
16076 emitted by gfortran at least as recently as:
16077 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16078 complaint (_("Variable in common block has "
16079 "DW_AT_data_member_location "
16080 "- DIE at %s [in module %s]"),
16081 sect_offset_str (child_die
->sect_off
),
16082 objfile_name (objfile
));
16084 if (member_loc
->form_is_section_offset ())
16085 dwarf2_complex_location_expr_complaint ();
16086 else if (member_loc
->form_is_constant ()
16087 || member_loc
->form_is_block ())
16089 if (attr
!= nullptr)
16090 mark_common_block_symbol_computed (sym
, die
, attr
,
16094 dwarf2_complex_location_expr_complaint ();
16099 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16100 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16104 /* Create a type for a C++ namespace. */
16106 static struct type
*
16107 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16109 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16110 const char *previous_prefix
, *name
;
16114 /* For extensions, reuse the type of the original namespace. */
16115 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16117 struct die_info
*ext_die
;
16118 struct dwarf2_cu
*ext_cu
= cu
;
16120 ext_die
= dwarf2_extension (die
, &ext_cu
);
16121 type
= read_type_die (ext_die
, ext_cu
);
16123 /* EXT_CU may not be the same as CU.
16124 Ensure TYPE is recorded with CU in die_type_hash. */
16125 return set_die_type (die
, type
, cu
);
16128 name
= namespace_name (die
, &is_anonymous
, cu
);
16130 /* Now build the name of the current namespace. */
16132 previous_prefix
= determine_prefix (die
, cu
);
16133 if (previous_prefix
[0] != '\0')
16134 name
= typename_concat (&objfile
->objfile_obstack
,
16135 previous_prefix
, name
, 0, cu
);
16137 /* Create the type. */
16138 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16140 return set_die_type (die
, type
, cu
);
16143 /* Read a namespace scope. */
16146 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16148 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16151 /* Add a symbol associated to this if we haven't seen the namespace
16152 before. Also, add a using directive if it's an anonymous
16155 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16159 type
= read_type_die (die
, cu
);
16160 new_symbol (die
, type
, cu
);
16162 namespace_name (die
, &is_anonymous
, cu
);
16165 const char *previous_prefix
= determine_prefix (die
, cu
);
16167 std::vector
<const char *> excludes
;
16168 add_using_directive (using_directives (cu
),
16169 previous_prefix
, TYPE_NAME (type
), NULL
,
16170 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16174 if (die
->child
!= NULL
)
16176 struct die_info
*child_die
= die
->child
;
16178 while (child_die
&& child_die
->tag
)
16180 process_die (child_die
, cu
);
16181 child_die
= sibling_die (child_die
);
16186 /* Read a Fortran module as type. This DIE can be only a declaration used for
16187 imported module. Still we need that type as local Fortran "use ... only"
16188 declaration imports depend on the created type in determine_prefix. */
16190 static struct type
*
16191 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16193 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16194 const char *module_name
;
16197 module_name
= dwarf2_name (die
, cu
);
16198 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16200 return set_die_type (die
, type
, cu
);
16203 /* Read a Fortran module. */
16206 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16208 struct die_info
*child_die
= die
->child
;
16211 type
= read_type_die (die
, cu
);
16212 new_symbol (die
, type
, cu
);
16214 while (child_die
&& child_die
->tag
)
16216 process_die (child_die
, cu
);
16217 child_die
= sibling_die (child_die
);
16221 /* Return the name of the namespace represented by DIE. Set
16222 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16225 static const char *
16226 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16228 struct die_info
*current_die
;
16229 const char *name
= NULL
;
16231 /* Loop through the extensions until we find a name. */
16233 for (current_die
= die
;
16234 current_die
!= NULL
;
16235 current_die
= dwarf2_extension (die
, &cu
))
16237 /* We don't use dwarf2_name here so that we can detect the absence
16238 of a name -> anonymous namespace. */
16239 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16245 /* Is it an anonymous namespace? */
16247 *is_anonymous
= (name
== NULL
);
16249 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16254 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16255 the user defined type vector. */
16257 static struct type
*
16258 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16260 struct gdbarch
*gdbarch
16261 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16262 struct comp_unit_head
*cu_header
= &cu
->header
;
16264 struct attribute
*attr_byte_size
;
16265 struct attribute
*attr_address_class
;
16266 int byte_size
, addr_class
;
16267 struct type
*target_type
;
16269 target_type
= die_type (die
, cu
);
16271 /* The die_type call above may have already set the type for this DIE. */
16272 type
= get_die_type (die
, cu
);
16276 type
= lookup_pointer_type (target_type
);
16278 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16279 if (attr_byte_size
)
16280 byte_size
= DW_UNSND (attr_byte_size
);
16282 byte_size
= cu_header
->addr_size
;
16284 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16285 if (attr_address_class
)
16286 addr_class
= DW_UNSND (attr_address_class
);
16288 addr_class
= DW_ADDR_none
;
16290 ULONGEST alignment
= get_alignment (cu
, die
);
16292 /* If the pointer size, alignment, or address class is different
16293 than the default, create a type variant marked as such and set
16294 the length accordingly. */
16295 if (TYPE_LENGTH (type
) != byte_size
16296 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16297 && alignment
!= TYPE_RAW_ALIGN (type
))
16298 || addr_class
!= DW_ADDR_none
)
16300 if (gdbarch_address_class_type_flags_p (gdbarch
))
16304 type_flags
= gdbarch_address_class_type_flags
16305 (gdbarch
, byte_size
, addr_class
);
16306 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16308 type
= make_type_with_address_space (type
, type_flags
);
16310 else if (TYPE_LENGTH (type
) != byte_size
)
16312 complaint (_("invalid pointer size %d"), byte_size
);
16314 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16316 complaint (_("Invalid DW_AT_alignment"
16317 " - DIE at %s [in module %s]"),
16318 sect_offset_str (die
->sect_off
),
16319 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16323 /* Should we also complain about unhandled address classes? */
16327 TYPE_LENGTH (type
) = byte_size
;
16328 set_type_align (type
, alignment
);
16329 return set_die_type (die
, type
, cu
);
16332 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16333 the user defined type vector. */
16335 static struct type
*
16336 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16339 struct type
*to_type
;
16340 struct type
*domain
;
16342 to_type
= die_type (die
, cu
);
16343 domain
= die_containing_type (die
, cu
);
16345 /* The calls above may have already set the type for this DIE. */
16346 type
= get_die_type (die
, cu
);
16350 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16351 type
= lookup_methodptr_type (to_type
);
16352 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16354 struct type
*new_type
16355 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16357 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16358 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16359 TYPE_VARARGS (to_type
));
16360 type
= lookup_methodptr_type (new_type
);
16363 type
= lookup_memberptr_type (to_type
, domain
);
16365 return set_die_type (die
, type
, cu
);
16368 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16369 the user defined type vector. */
16371 static struct type
*
16372 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16373 enum type_code refcode
)
16375 struct comp_unit_head
*cu_header
= &cu
->header
;
16376 struct type
*type
, *target_type
;
16377 struct attribute
*attr
;
16379 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16381 target_type
= die_type (die
, cu
);
16383 /* The die_type call above may have already set the type for this DIE. */
16384 type
= get_die_type (die
, cu
);
16388 type
= lookup_reference_type (target_type
, refcode
);
16389 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16390 if (attr
!= nullptr)
16392 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16396 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16398 maybe_set_alignment (cu
, die
, type
);
16399 return set_die_type (die
, type
, cu
);
16402 /* Add the given cv-qualifiers to the element type of the array. GCC
16403 outputs DWARF type qualifiers that apply to an array, not the
16404 element type. But GDB relies on the array element type to carry
16405 the cv-qualifiers. This mimics section 6.7.3 of the C99
16408 static struct type
*
16409 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16410 struct type
*base_type
, int cnst
, int voltl
)
16412 struct type
*el_type
, *inner_array
;
16414 base_type
= copy_type (base_type
);
16415 inner_array
= base_type
;
16417 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16419 TYPE_TARGET_TYPE (inner_array
) =
16420 copy_type (TYPE_TARGET_TYPE (inner_array
));
16421 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16424 el_type
= TYPE_TARGET_TYPE (inner_array
);
16425 cnst
|= TYPE_CONST (el_type
);
16426 voltl
|= TYPE_VOLATILE (el_type
);
16427 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16429 return set_die_type (die
, base_type
, cu
);
16432 static struct type
*
16433 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16435 struct type
*base_type
, *cv_type
;
16437 base_type
= die_type (die
, cu
);
16439 /* The die_type call above may have already set the type for this DIE. */
16440 cv_type
= get_die_type (die
, cu
);
16444 /* In case the const qualifier is applied to an array type, the element type
16445 is so qualified, not the array type (section 6.7.3 of C99). */
16446 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16447 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16449 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16450 return set_die_type (die
, cv_type
, cu
);
16453 static struct type
*
16454 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16456 struct type
*base_type
, *cv_type
;
16458 base_type
= die_type (die
, cu
);
16460 /* The die_type call above may have already set the type for this DIE. */
16461 cv_type
= get_die_type (die
, cu
);
16465 /* In case the volatile qualifier is applied to an array type, the
16466 element type is so qualified, not the array type (section 6.7.3
16468 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16469 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16471 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16472 return set_die_type (die
, cv_type
, cu
);
16475 /* Handle DW_TAG_restrict_type. */
16477 static struct type
*
16478 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16480 struct type
*base_type
, *cv_type
;
16482 base_type
= die_type (die
, cu
);
16484 /* The die_type call above may have already set the type for this DIE. */
16485 cv_type
= get_die_type (die
, cu
);
16489 cv_type
= make_restrict_type (base_type
);
16490 return set_die_type (die
, cv_type
, cu
);
16493 /* Handle DW_TAG_atomic_type. */
16495 static struct type
*
16496 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16498 struct type
*base_type
, *cv_type
;
16500 base_type
= die_type (die
, cu
);
16502 /* The die_type call above may have already set the type for this DIE. */
16503 cv_type
= get_die_type (die
, cu
);
16507 cv_type
= make_atomic_type (base_type
);
16508 return set_die_type (die
, cv_type
, cu
);
16511 /* Extract all information from a DW_TAG_string_type DIE and add to
16512 the user defined type vector. It isn't really a user defined type,
16513 but it behaves like one, with other DIE's using an AT_user_def_type
16514 attribute to reference it. */
16516 static struct type
*
16517 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16519 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16520 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16521 struct type
*type
, *range_type
, *index_type
, *char_type
;
16522 struct attribute
*attr
;
16523 struct dynamic_prop prop
;
16524 bool length_is_constant
= true;
16527 /* There are a couple of places where bit sizes might be made use of
16528 when parsing a DW_TAG_string_type, however, no producer that we know
16529 of make use of these. Handling bit sizes that are a multiple of the
16530 byte size is easy enough, but what about other bit sizes? Lets deal
16531 with that problem when we have to. Warn about these attributes being
16532 unsupported, then parse the type and ignore them like we always
16534 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16535 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16537 static bool warning_printed
= false;
16538 if (!warning_printed
)
16540 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16541 "currently supported on DW_TAG_string_type."));
16542 warning_printed
= true;
16546 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16547 if (attr
!= nullptr && !attr
->form_is_constant ())
16549 /* The string length describes the location at which the length of
16550 the string can be found. The size of the length field can be
16551 specified with one of the attributes below. */
16552 struct type
*prop_type
;
16553 struct attribute
*len
16554 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16555 if (len
== nullptr)
16556 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16557 if (len
!= nullptr && len
->form_is_constant ())
16559 /* Pass 0 as the default as we know this attribute is constant
16560 and the default value will not be returned. */
16561 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16562 prop_type
= cu
->per_cu
->int_type (sz
, true);
16566 /* If the size is not specified then we assume it is the size of
16567 an address on this target. */
16568 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16571 /* Convert the attribute into a dynamic property. */
16572 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16575 length_is_constant
= false;
16577 else if (attr
!= nullptr)
16579 /* This DW_AT_string_length just contains the length with no
16580 indirection. There's no need to create a dynamic property in this
16581 case. Pass 0 for the default value as we know it will not be
16582 returned in this case. */
16583 length
= dwarf2_get_attr_constant_value (attr
, 0);
16585 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16587 /* We don't currently support non-constant byte sizes for strings. */
16588 length
= dwarf2_get_attr_constant_value (attr
, 1);
16592 /* Use 1 as a fallback length if we have nothing else. */
16596 index_type
= objfile_type (objfile
)->builtin_int
;
16597 if (length_is_constant
)
16598 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16601 struct dynamic_prop low_bound
;
16603 low_bound
.kind
= PROP_CONST
;
16604 low_bound
.data
.const_val
= 1;
16605 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16607 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16608 type
= create_string_type (NULL
, char_type
, range_type
);
16610 return set_die_type (die
, type
, cu
);
16613 /* Assuming that DIE corresponds to a function, returns nonzero
16614 if the function is prototyped. */
16617 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16619 struct attribute
*attr
;
16621 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16622 if (attr
&& (DW_UNSND (attr
) != 0))
16625 /* The DWARF standard implies that the DW_AT_prototyped attribute
16626 is only meaningful for C, but the concept also extends to other
16627 languages that allow unprototyped functions (Eg: Objective C).
16628 For all other languages, assume that functions are always
16630 if (cu
->language
!= language_c
16631 && cu
->language
!= language_objc
16632 && cu
->language
!= language_opencl
)
16635 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16636 prototyped and unprototyped functions; default to prototyped,
16637 since that is more common in modern code (and RealView warns
16638 about unprototyped functions). */
16639 if (producer_is_realview (cu
->producer
))
16645 /* Handle DIES due to C code like:
16649 int (*funcp)(int a, long l);
16653 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16655 static struct type
*
16656 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16658 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16659 struct type
*type
; /* Type that this function returns. */
16660 struct type
*ftype
; /* Function that returns above type. */
16661 struct attribute
*attr
;
16663 type
= die_type (die
, cu
);
16665 /* The die_type call above may have already set the type for this DIE. */
16666 ftype
= get_die_type (die
, cu
);
16670 ftype
= lookup_function_type (type
);
16672 if (prototyped_function_p (die
, cu
))
16673 TYPE_PROTOTYPED (ftype
) = 1;
16675 /* Store the calling convention in the type if it's available in
16676 the subroutine die. Otherwise set the calling convention to
16677 the default value DW_CC_normal. */
16678 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16679 if (attr
!= nullptr
16680 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16681 TYPE_CALLING_CONVENTION (ftype
)
16682 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16683 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16684 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16686 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16688 /* Record whether the function returns normally to its caller or not
16689 if the DWARF producer set that information. */
16690 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16691 if (attr
&& (DW_UNSND (attr
) != 0))
16692 TYPE_NO_RETURN (ftype
) = 1;
16694 /* We need to add the subroutine type to the die immediately so
16695 we don't infinitely recurse when dealing with parameters
16696 declared as the same subroutine type. */
16697 set_die_type (die
, ftype
, cu
);
16699 if (die
->child
!= NULL
)
16701 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16702 struct die_info
*child_die
;
16703 int nparams
, iparams
;
16705 /* Count the number of parameters.
16706 FIXME: GDB currently ignores vararg functions, but knows about
16707 vararg member functions. */
16709 child_die
= die
->child
;
16710 while (child_die
&& child_die
->tag
)
16712 if (child_die
->tag
== DW_TAG_formal_parameter
)
16714 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16715 TYPE_VARARGS (ftype
) = 1;
16716 child_die
= sibling_die (child_die
);
16719 /* Allocate storage for parameters and fill them in. */
16720 TYPE_NFIELDS (ftype
) = nparams
;
16721 TYPE_FIELDS (ftype
) = (struct field
*)
16722 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16724 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16725 even if we error out during the parameters reading below. */
16726 for (iparams
= 0; iparams
< nparams
; iparams
++)
16727 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16730 child_die
= die
->child
;
16731 while (child_die
&& child_die
->tag
)
16733 if (child_die
->tag
== DW_TAG_formal_parameter
)
16735 struct type
*arg_type
;
16737 /* DWARF version 2 has no clean way to discern C++
16738 static and non-static member functions. G++ helps
16739 GDB by marking the first parameter for non-static
16740 member functions (which is the this pointer) as
16741 artificial. We pass this information to
16742 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16744 DWARF version 3 added DW_AT_object_pointer, which GCC
16745 4.5 does not yet generate. */
16746 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16747 if (attr
!= nullptr)
16748 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16750 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16751 arg_type
= die_type (child_die
, cu
);
16753 /* RealView does not mark THIS as const, which the testsuite
16754 expects. GCC marks THIS as const in method definitions,
16755 but not in the class specifications (GCC PR 43053). */
16756 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16757 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16760 struct dwarf2_cu
*arg_cu
= cu
;
16761 const char *name
= dwarf2_name (child_die
, cu
);
16763 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16764 if (attr
!= nullptr)
16766 /* If the compiler emits this, use it. */
16767 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16770 else if (name
&& strcmp (name
, "this") == 0)
16771 /* Function definitions will have the argument names. */
16773 else if (name
== NULL
&& iparams
== 0)
16774 /* Declarations may not have the names, so like
16775 elsewhere in GDB, assume an artificial first
16776 argument is "this". */
16780 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16784 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16787 child_die
= sibling_die (child_die
);
16794 static struct type
*
16795 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16797 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16798 const char *name
= NULL
;
16799 struct type
*this_type
, *target_type
;
16801 name
= dwarf2_full_name (NULL
, die
, cu
);
16802 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16803 TYPE_TARGET_STUB (this_type
) = 1;
16804 set_die_type (die
, this_type
, cu
);
16805 target_type
= die_type (die
, cu
);
16806 if (target_type
!= this_type
)
16807 TYPE_TARGET_TYPE (this_type
) = target_type
;
16810 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16811 spec and cause infinite loops in GDB. */
16812 complaint (_("Self-referential DW_TAG_typedef "
16813 "- DIE at %s [in module %s]"),
16814 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16815 TYPE_TARGET_TYPE (this_type
) = NULL
;
16819 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16820 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16821 Handle these by just returning the target type, rather than
16822 constructing an anonymous typedef type and trying to handle this
16824 set_die_type (die
, target_type
, cu
);
16825 return target_type
;
16830 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16831 (which may be different from NAME) to the architecture back-end to allow
16832 it to guess the correct format if necessary. */
16834 static struct type
*
16835 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16836 const char *name_hint
, enum bfd_endian byte_order
)
16838 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16839 const struct floatformat
**format
;
16842 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16844 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16846 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16851 /* Allocate an integer type of size BITS and name NAME. */
16853 static struct type
*
16854 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16855 int bits
, int unsigned_p
, const char *name
)
16859 /* Versions of Intel's C Compiler generate an integer type called "void"
16860 instead of using DW_TAG_unspecified_type. This has been seen on
16861 at least versions 14, 17, and 18. */
16862 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16863 && strcmp (name
, "void") == 0)
16864 type
= objfile_type (objfile
)->builtin_void
;
16866 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16871 /* Initialise and return a floating point type of size BITS suitable for
16872 use as a component of a complex number. The NAME_HINT is passed through
16873 when initialising the floating point type and is the name of the complex
16876 As DWARF doesn't currently provide an explicit name for the components
16877 of a complex number, but it can be helpful to have these components
16878 named, we try to select a suitable name based on the size of the
16880 static struct type
*
16881 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16882 struct objfile
*objfile
,
16883 int bits
, const char *name_hint
,
16884 enum bfd_endian byte_order
)
16886 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16887 struct type
*tt
= nullptr;
16889 /* Try to find a suitable floating point builtin type of size BITS.
16890 We're going to use the name of this type as the name for the complex
16891 target type that we are about to create. */
16892 switch (cu
->language
)
16894 case language_fortran
:
16898 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16901 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16903 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16905 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16913 tt
= builtin_type (gdbarch
)->builtin_float
;
16916 tt
= builtin_type (gdbarch
)->builtin_double
;
16918 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16920 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16926 /* If the type we found doesn't match the size we were looking for, then
16927 pretend we didn't find a type at all, the complex target type we
16928 create will then be nameless. */
16929 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16932 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16933 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16936 /* Find a representation of a given base type and install
16937 it in the TYPE field of the die. */
16939 static struct type
*
16940 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16942 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16944 struct attribute
*attr
;
16945 int encoding
= 0, bits
= 0;
16949 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16950 if (attr
!= nullptr)
16951 encoding
= DW_UNSND (attr
);
16952 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16953 if (attr
!= nullptr)
16954 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16955 name
= dwarf2_name (die
, cu
);
16957 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16959 arch
= get_objfile_arch (objfile
);
16960 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16962 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16965 int endianity
= DW_UNSND (attr
);
16970 byte_order
= BFD_ENDIAN_BIG
;
16972 case DW_END_little
:
16973 byte_order
= BFD_ENDIAN_LITTLE
;
16976 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16983 case DW_ATE_address
:
16984 /* Turn DW_ATE_address into a void * pointer. */
16985 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16986 type
= init_pointer_type (objfile
, bits
, name
, type
);
16988 case DW_ATE_boolean
:
16989 type
= init_boolean_type (objfile
, bits
, 1, name
);
16991 case DW_ATE_complex_float
:
16992 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16994 type
= init_complex_type (objfile
, name
, type
);
16996 case DW_ATE_decimal_float
:
16997 type
= init_decfloat_type (objfile
, bits
, name
);
17000 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17002 case DW_ATE_signed
:
17003 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17005 case DW_ATE_unsigned
:
17006 if (cu
->language
== language_fortran
17008 && startswith (name
, "character("))
17009 type
= init_character_type (objfile
, bits
, 1, name
);
17011 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17013 case DW_ATE_signed_char
:
17014 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17015 || cu
->language
== language_pascal
17016 || cu
->language
== language_fortran
)
17017 type
= init_character_type (objfile
, bits
, 0, name
);
17019 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17021 case DW_ATE_unsigned_char
:
17022 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17023 || cu
->language
== language_pascal
17024 || cu
->language
== language_fortran
17025 || cu
->language
== language_rust
)
17026 type
= init_character_type (objfile
, bits
, 1, name
);
17028 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17033 type
= builtin_type (arch
)->builtin_char16
;
17034 else if (bits
== 32)
17035 type
= builtin_type (arch
)->builtin_char32
;
17038 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17040 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17042 return set_die_type (die
, type
, cu
);
17047 complaint (_("unsupported DW_AT_encoding: '%s'"),
17048 dwarf_type_encoding_name (encoding
));
17049 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17053 if (name
&& strcmp (name
, "char") == 0)
17054 TYPE_NOSIGN (type
) = 1;
17056 maybe_set_alignment (cu
, die
, type
);
17058 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17060 return set_die_type (die
, type
, cu
);
17063 /* Parse dwarf attribute if it's a block, reference or constant and put the
17064 resulting value of the attribute into struct bound_prop.
17065 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17068 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17069 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17070 struct type
*default_type
)
17072 struct dwarf2_property_baton
*baton
;
17073 struct obstack
*obstack
17074 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17076 gdb_assert (default_type
!= NULL
);
17078 if (attr
== NULL
|| prop
== NULL
)
17081 if (attr
->form_is_block ())
17083 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17084 baton
->property_type
= default_type
;
17085 baton
->locexpr
.per_cu
= cu
->per_cu
;
17086 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17087 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17088 switch (attr
->name
)
17090 case DW_AT_string_length
:
17091 baton
->locexpr
.is_reference
= true;
17094 baton
->locexpr
.is_reference
= false;
17097 prop
->data
.baton
= baton
;
17098 prop
->kind
= PROP_LOCEXPR
;
17099 gdb_assert (prop
->data
.baton
!= NULL
);
17101 else if (attr
->form_is_ref ())
17103 struct dwarf2_cu
*target_cu
= cu
;
17104 struct die_info
*target_die
;
17105 struct attribute
*target_attr
;
17107 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17108 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17109 if (target_attr
== NULL
)
17110 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17112 if (target_attr
== NULL
)
17115 switch (target_attr
->name
)
17117 case DW_AT_location
:
17118 if (target_attr
->form_is_section_offset ())
17120 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17121 baton
->property_type
= die_type (target_die
, target_cu
);
17122 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17123 prop
->data
.baton
= baton
;
17124 prop
->kind
= PROP_LOCLIST
;
17125 gdb_assert (prop
->data
.baton
!= NULL
);
17127 else if (target_attr
->form_is_block ())
17129 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17130 baton
->property_type
= die_type (target_die
, target_cu
);
17131 baton
->locexpr
.per_cu
= cu
->per_cu
;
17132 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17133 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17134 baton
->locexpr
.is_reference
= true;
17135 prop
->data
.baton
= baton
;
17136 prop
->kind
= PROP_LOCEXPR
;
17137 gdb_assert (prop
->data
.baton
!= NULL
);
17141 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17142 "dynamic property");
17146 case DW_AT_data_member_location
:
17150 if (!handle_data_member_location (target_die
, target_cu
,
17154 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17155 baton
->property_type
= read_type_die (target_die
->parent
,
17157 baton
->offset_info
.offset
= offset
;
17158 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17159 prop
->data
.baton
= baton
;
17160 prop
->kind
= PROP_ADDR_OFFSET
;
17165 else if (attr
->form_is_constant ())
17167 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17168 prop
->kind
= PROP_CONST
;
17172 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17173 dwarf2_name (die
, cu
));
17183 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17185 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17186 struct type
*int_type
;
17188 /* Helper macro to examine the various builtin types. */
17189 #define TRY_TYPE(F) \
17190 int_type = (unsigned_p \
17191 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17192 : objfile_type (objfile)->builtin_ ## F); \
17193 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17200 TRY_TYPE (long_long
);
17204 gdb_assert_not_reached ("unable to find suitable integer type");
17210 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17212 int addr_size
= this->addr_size ();
17213 return int_type (addr_size
, unsigned_p
);
17216 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17217 present (which is valid) then compute the default type based on the
17218 compilation units address size. */
17220 static struct type
*
17221 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17223 struct type
*index_type
= die_type (die
, cu
);
17225 /* Dwarf-2 specifications explicitly allows to create subrange types
17226 without specifying a base type.
17227 In that case, the base type must be set to the type of
17228 the lower bound, upper bound or count, in that order, if any of these
17229 three attributes references an object that has a type.
17230 If no base type is found, the Dwarf-2 specifications say that
17231 a signed integer type of size equal to the size of an address should
17233 For the following C code: `extern char gdb_int [];'
17234 GCC produces an empty range DIE.
17235 FIXME: muller/2010-05-28: Possible references to object for low bound,
17236 high bound or count are not yet handled by this code. */
17237 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17238 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17243 /* Read the given DW_AT_subrange DIE. */
17245 static struct type
*
17246 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17248 struct type
*base_type
, *orig_base_type
;
17249 struct type
*range_type
;
17250 struct attribute
*attr
;
17251 struct dynamic_prop low
, high
;
17252 int low_default_is_valid
;
17253 int high_bound_is_count
= 0;
17255 ULONGEST negative_mask
;
17257 orig_base_type
= read_subrange_index_type (die
, cu
);
17259 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17260 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17261 creating the range type, but we use the result of check_typedef
17262 when examining properties of the type. */
17263 base_type
= check_typedef (orig_base_type
);
17265 /* The die_type call above may have already set the type for this DIE. */
17266 range_type
= get_die_type (die
, cu
);
17270 low
.kind
= PROP_CONST
;
17271 high
.kind
= PROP_CONST
;
17272 high
.data
.const_val
= 0;
17274 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17275 omitting DW_AT_lower_bound. */
17276 switch (cu
->language
)
17279 case language_cplus
:
17280 low
.data
.const_val
= 0;
17281 low_default_is_valid
= 1;
17283 case language_fortran
:
17284 low
.data
.const_val
= 1;
17285 low_default_is_valid
= 1;
17288 case language_objc
:
17289 case language_rust
:
17290 low
.data
.const_val
= 0;
17291 low_default_is_valid
= (cu
->header
.version
>= 4);
17295 case language_pascal
:
17296 low
.data
.const_val
= 1;
17297 low_default_is_valid
= (cu
->header
.version
>= 4);
17300 low
.data
.const_val
= 0;
17301 low_default_is_valid
= 0;
17305 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17306 if (attr
!= nullptr)
17307 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17308 else if (!low_default_is_valid
)
17309 complaint (_("Missing DW_AT_lower_bound "
17310 "- DIE at %s [in module %s]"),
17311 sect_offset_str (die
->sect_off
),
17312 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17314 struct attribute
*attr_ub
, *attr_count
;
17315 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17316 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17318 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17319 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17321 /* If bounds are constant do the final calculation here. */
17322 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17323 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17325 high_bound_is_count
= 1;
17329 if (attr_ub
!= NULL
)
17330 complaint (_("Unresolved DW_AT_upper_bound "
17331 "- DIE at %s [in module %s]"),
17332 sect_offset_str (die
->sect_off
),
17333 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17334 if (attr_count
!= NULL
)
17335 complaint (_("Unresolved DW_AT_count "
17336 "- DIE at %s [in module %s]"),
17337 sect_offset_str (die
->sect_off
),
17338 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17343 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17344 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17345 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17347 /* Normally, the DWARF producers are expected to use a signed
17348 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17349 But this is unfortunately not always the case, as witnessed
17350 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17351 is used instead. To work around that ambiguity, we treat
17352 the bounds as signed, and thus sign-extend their values, when
17353 the base type is signed. */
17355 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17356 if (low
.kind
== PROP_CONST
17357 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17358 low
.data
.const_val
|= negative_mask
;
17359 if (high
.kind
== PROP_CONST
17360 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17361 high
.data
.const_val
|= negative_mask
;
17363 /* Check for bit and byte strides. */
17364 struct dynamic_prop byte_stride_prop
;
17365 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17366 if (attr_byte_stride
!= nullptr)
17368 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17369 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17373 struct dynamic_prop bit_stride_prop
;
17374 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17375 if (attr_bit_stride
!= nullptr)
17377 /* It only makes sense to have either a bit or byte stride. */
17378 if (attr_byte_stride
!= nullptr)
17380 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17381 "- DIE at %s [in module %s]"),
17382 sect_offset_str (die
->sect_off
),
17383 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17384 attr_bit_stride
= nullptr;
17388 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17389 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17394 if (attr_byte_stride
!= nullptr
17395 || attr_bit_stride
!= nullptr)
17397 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17398 struct dynamic_prop
*stride
17399 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17402 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17403 &high
, bias
, stride
, byte_stride_p
);
17406 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17408 if (high_bound_is_count
)
17409 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17411 /* Ada expects an empty array on no boundary attributes. */
17412 if (attr
== NULL
&& cu
->language
!= language_ada
)
17413 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17415 name
= dwarf2_name (die
, cu
);
17417 TYPE_NAME (range_type
) = name
;
17419 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17420 if (attr
!= nullptr)
17421 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17423 maybe_set_alignment (cu
, die
, range_type
);
17425 set_die_type (die
, range_type
, cu
);
17427 /* set_die_type should be already done. */
17428 set_descriptive_type (range_type
, die
, cu
);
17433 static struct type
*
17434 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17438 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17440 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17442 /* In Ada, an unspecified type is typically used when the description
17443 of the type is deferred to a different unit. When encountering
17444 such a type, we treat it as a stub, and try to resolve it later on,
17446 if (cu
->language
== language_ada
)
17447 TYPE_STUB (type
) = 1;
17449 return set_die_type (die
, type
, cu
);
17452 /* Read a single die and all its descendents. Set the die's sibling
17453 field to NULL; set other fields in the die correctly, and set all
17454 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17455 location of the info_ptr after reading all of those dies. PARENT
17456 is the parent of the die in question. */
17458 static struct die_info
*
17459 read_die_and_children (const struct die_reader_specs
*reader
,
17460 const gdb_byte
*info_ptr
,
17461 const gdb_byte
**new_info_ptr
,
17462 struct die_info
*parent
)
17464 struct die_info
*die
;
17465 const gdb_byte
*cur_ptr
;
17467 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17470 *new_info_ptr
= cur_ptr
;
17473 store_in_ref_table (die
, reader
->cu
);
17475 if (die
->has_children
)
17476 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17480 *new_info_ptr
= cur_ptr
;
17483 die
->sibling
= NULL
;
17484 die
->parent
= parent
;
17488 /* Read a die, all of its descendents, and all of its siblings; set
17489 all of the fields of all of the dies correctly. Arguments are as
17490 in read_die_and_children. */
17492 static struct die_info
*
17493 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17494 const gdb_byte
*info_ptr
,
17495 const gdb_byte
**new_info_ptr
,
17496 struct die_info
*parent
)
17498 struct die_info
*first_die
, *last_sibling
;
17499 const gdb_byte
*cur_ptr
;
17501 cur_ptr
= info_ptr
;
17502 first_die
= last_sibling
= NULL
;
17506 struct die_info
*die
17507 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17511 *new_info_ptr
= cur_ptr
;
17518 last_sibling
->sibling
= die
;
17520 last_sibling
= die
;
17524 /* Read a die, all of its descendents, and all of its siblings; set
17525 all of the fields of all of the dies correctly. Arguments are as
17526 in read_die_and_children.
17527 This the main entry point for reading a DIE and all its children. */
17529 static struct die_info
*
17530 read_die_and_siblings (const struct die_reader_specs
*reader
,
17531 const gdb_byte
*info_ptr
,
17532 const gdb_byte
**new_info_ptr
,
17533 struct die_info
*parent
)
17535 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17536 new_info_ptr
, parent
);
17538 if (dwarf_die_debug
)
17540 fprintf_unfiltered (gdb_stdlog
,
17541 "Read die from %s@0x%x of %s:\n",
17542 reader
->die_section
->get_name (),
17543 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17544 bfd_get_filename (reader
->abfd
));
17545 dump_die (die
, dwarf_die_debug
);
17551 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17553 The caller is responsible for filling in the extra attributes
17554 and updating (*DIEP)->num_attrs.
17555 Set DIEP to point to a newly allocated die with its information,
17556 except for its child, sibling, and parent fields. */
17558 static const gdb_byte
*
17559 read_full_die_1 (const struct die_reader_specs
*reader
,
17560 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17561 int num_extra_attrs
)
17563 unsigned int abbrev_number
, bytes_read
, i
;
17564 struct abbrev_info
*abbrev
;
17565 struct die_info
*die
;
17566 struct dwarf2_cu
*cu
= reader
->cu
;
17567 bfd
*abfd
= reader
->abfd
;
17569 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17570 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17571 info_ptr
+= bytes_read
;
17572 if (!abbrev_number
)
17578 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17580 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17582 bfd_get_filename (abfd
));
17584 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17585 die
->sect_off
= sect_off
;
17586 die
->tag
= abbrev
->tag
;
17587 die
->abbrev
= abbrev_number
;
17588 die
->has_children
= abbrev
->has_children
;
17590 /* Make the result usable.
17591 The caller needs to update num_attrs after adding the extra
17593 die
->num_attrs
= abbrev
->num_attrs
;
17595 std::vector
<int> indexes_that_need_reprocess
;
17596 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17598 bool need_reprocess
;
17600 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17601 info_ptr
, &need_reprocess
);
17602 if (need_reprocess
)
17603 indexes_that_need_reprocess
.push_back (i
);
17606 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17607 if (attr
!= nullptr)
17608 cu
->str_offsets_base
= DW_UNSND (attr
);
17610 auto maybe_addr_base
= lookup_addr_base(die
);
17611 if (maybe_addr_base
.has_value ())
17612 cu
->addr_base
= *maybe_addr_base
;
17613 for (int index
: indexes_that_need_reprocess
)
17614 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17619 /* Read a die and all its attributes.
17620 Set DIEP to point to a newly allocated die with its information,
17621 except for its child, sibling, and parent fields. */
17623 static const gdb_byte
*
17624 read_full_die (const struct die_reader_specs
*reader
,
17625 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17627 const gdb_byte
*result
;
17629 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17631 if (dwarf_die_debug
)
17633 fprintf_unfiltered (gdb_stdlog
,
17634 "Read die from %s@0x%x of %s:\n",
17635 reader
->die_section
->get_name (),
17636 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17637 bfd_get_filename (reader
->abfd
));
17638 dump_die (*diep
, dwarf_die_debug
);
17645 /* Returns nonzero if TAG represents a type that we might generate a partial
17649 is_type_tag_for_partial (int tag
)
17654 /* Some types that would be reasonable to generate partial symbols for,
17655 that we don't at present. */
17656 case DW_TAG_array_type
:
17657 case DW_TAG_file_type
:
17658 case DW_TAG_ptr_to_member_type
:
17659 case DW_TAG_set_type
:
17660 case DW_TAG_string_type
:
17661 case DW_TAG_subroutine_type
:
17663 case DW_TAG_base_type
:
17664 case DW_TAG_class_type
:
17665 case DW_TAG_interface_type
:
17666 case DW_TAG_enumeration_type
:
17667 case DW_TAG_structure_type
:
17668 case DW_TAG_subrange_type
:
17669 case DW_TAG_typedef
:
17670 case DW_TAG_union_type
:
17677 /* Load all DIEs that are interesting for partial symbols into memory. */
17679 static struct partial_die_info
*
17680 load_partial_dies (const struct die_reader_specs
*reader
,
17681 const gdb_byte
*info_ptr
, int building_psymtab
)
17683 struct dwarf2_cu
*cu
= reader
->cu
;
17684 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17685 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17686 unsigned int bytes_read
;
17687 unsigned int load_all
= 0;
17688 int nesting_level
= 1;
17693 gdb_assert (cu
->per_cu
!= NULL
);
17694 if (cu
->per_cu
->load_all_dies
)
17698 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17702 &cu
->comp_unit_obstack
,
17703 hashtab_obstack_allocate
,
17704 dummy_obstack_deallocate
);
17708 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17710 /* A NULL abbrev means the end of a series of children. */
17711 if (abbrev
== NULL
)
17713 if (--nesting_level
== 0)
17716 info_ptr
+= bytes_read
;
17717 last_die
= parent_die
;
17718 parent_die
= parent_die
->die_parent
;
17722 /* Check for template arguments. We never save these; if
17723 they're seen, we just mark the parent, and go on our way. */
17724 if (parent_die
!= NULL
17725 && cu
->language
== language_cplus
17726 && (abbrev
->tag
== DW_TAG_template_type_param
17727 || abbrev
->tag
== DW_TAG_template_value_param
))
17729 parent_die
->has_template_arguments
= 1;
17733 /* We don't need a partial DIE for the template argument. */
17734 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17739 /* We only recurse into c++ subprograms looking for template arguments.
17740 Skip their other children. */
17742 && cu
->language
== language_cplus
17743 && parent_die
!= NULL
17744 && parent_die
->tag
== DW_TAG_subprogram
)
17746 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17750 /* Check whether this DIE is interesting enough to save. Normally
17751 we would not be interested in members here, but there may be
17752 later variables referencing them via DW_AT_specification (for
17753 static members). */
17755 && !is_type_tag_for_partial (abbrev
->tag
)
17756 && abbrev
->tag
!= DW_TAG_constant
17757 && abbrev
->tag
!= DW_TAG_enumerator
17758 && abbrev
->tag
!= DW_TAG_subprogram
17759 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17760 && abbrev
->tag
!= DW_TAG_lexical_block
17761 && abbrev
->tag
!= DW_TAG_variable
17762 && abbrev
->tag
!= DW_TAG_namespace
17763 && abbrev
->tag
!= DW_TAG_module
17764 && abbrev
->tag
!= DW_TAG_member
17765 && abbrev
->tag
!= DW_TAG_imported_unit
17766 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17768 /* Otherwise we skip to the next sibling, if any. */
17769 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17773 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17776 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17778 /* This two-pass algorithm for processing partial symbols has a
17779 high cost in cache pressure. Thus, handle some simple cases
17780 here which cover the majority of C partial symbols. DIEs
17781 which neither have specification tags in them, nor could have
17782 specification tags elsewhere pointing at them, can simply be
17783 processed and discarded.
17785 This segment is also optional; scan_partial_symbols and
17786 add_partial_symbol will handle these DIEs if we chain
17787 them in normally. When compilers which do not emit large
17788 quantities of duplicate debug information are more common,
17789 this code can probably be removed. */
17791 /* Any complete simple types at the top level (pretty much all
17792 of them, for a language without namespaces), can be processed
17794 if (parent_die
== NULL
17795 && pdi
.has_specification
== 0
17796 && pdi
.is_declaration
== 0
17797 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17798 || pdi
.tag
== DW_TAG_base_type
17799 || pdi
.tag
== DW_TAG_subrange_type
))
17801 if (building_psymtab
&& pdi
.name
!= NULL
)
17802 add_psymbol_to_list (pdi
.name
, false,
17803 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17804 psymbol_placement::STATIC
,
17805 0, cu
->language
, objfile
);
17806 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17810 /* The exception for DW_TAG_typedef with has_children above is
17811 a workaround of GCC PR debug/47510. In the case of this complaint
17812 type_name_or_error will error on such types later.
17814 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17815 it could not find the child DIEs referenced later, this is checked
17816 above. In correct DWARF DW_TAG_typedef should have no children. */
17818 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17819 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17820 "- DIE at %s [in module %s]"),
17821 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17823 /* If we're at the second level, and we're an enumerator, and
17824 our parent has no specification (meaning possibly lives in a
17825 namespace elsewhere), then we can add the partial symbol now
17826 instead of queueing it. */
17827 if (pdi
.tag
== DW_TAG_enumerator
17828 && parent_die
!= NULL
17829 && parent_die
->die_parent
== NULL
17830 && parent_die
->tag
== DW_TAG_enumeration_type
17831 && parent_die
->has_specification
== 0)
17833 if (pdi
.name
== NULL
)
17834 complaint (_("malformed enumerator DIE ignored"));
17835 else if (building_psymtab
)
17836 add_psymbol_to_list (pdi
.name
, false,
17837 VAR_DOMAIN
, LOC_CONST
, -1,
17838 cu
->language
== language_cplus
17839 ? psymbol_placement::GLOBAL
17840 : psymbol_placement::STATIC
,
17841 0, cu
->language
, objfile
);
17843 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17847 struct partial_die_info
*part_die
17848 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17850 /* We'll save this DIE so link it in. */
17851 part_die
->die_parent
= parent_die
;
17852 part_die
->die_sibling
= NULL
;
17853 part_die
->die_child
= NULL
;
17855 if (last_die
&& last_die
== parent_die
)
17856 last_die
->die_child
= part_die
;
17858 last_die
->die_sibling
= part_die
;
17860 last_die
= part_die
;
17862 if (first_die
== NULL
)
17863 first_die
= part_die
;
17865 /* Maybe add the DIE to the hash table. Not all DIEs that we
17866 find interesting need to be in the hash table, because we
17867 also have the parent/sibling/child chains; only those that we
17868 might refer to by offset later during partial symbol reading.
17870 For now this means things that might have be the target of a
17871 DW_AT_specification, DW_AT_abstract_origin, or
17872 DW_AT_extension. DW_AT_extension will refer only to
17873 namespaces; DW_AT_abstract_origin refers to functions (and
17874 many things under the function DIE, but we do not recurse
17875 into function DIEs during partial symbol reading) and
17876 possibly variables as well; DW_AT_specification refers to
17877 declarations. Declarations ought to have the DW_AT_declaration
17878 flag. It happens that GCC forgets to put it in sometimes, but
17879 only for functions, not for types.
17881 Adding more things than necessary to the hash table is harmless
17882 except for the performance cost. Adding too few will result in
17883 wasted time in find_partial_die, when we reread the compilation
17884 unit with load_all_dies set. */
17887 || abbrev
->tag
== DW_TAG_constant
17888 || abbrev
->tag
== DW_TAG_subprogram
17889 || abbrev
->tag
== DW_TAG_variable
17890 || abbrev
->tag
== DW_TAG_namespace
17891 || part_die
->is_declaration
)
17895 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17896 to_underlying (part_die
->sect_off
),
17901 /* For some DIEs we want to follow their children (if any). For C
17902 we have no reason to follow the children of structures; for other
17903 languages we have to, so that we can get at method physnames
17904 to infer fully qualified class names, for DW_AT_specification,
17905 and for C++ template arguments. For C++, we also look one level
17906 inside functions to find template arguments (if the name of the
17907 function does not already contain the template arguments).
17909 For Ada and Fortran, we need to scan the children of subprograms
17910 and lexical blocks as well because these languages allow the
17911 definition of nested entities that could be interesting for the
17912 debugger, such as nested subprograms for instance. */
17913 if (last_die
->has_children
17915 || last_die
->tag
== DW_TAG_namespace
17916 || last_die
->tag
== DW_TAG_module
17917 || last_die
->tag
== DW_TAG_enumeration_type
17918 || (cu
->language
== language_cplus
17919 && last_die
->tag
== DW_TAG_subprogram
17920 && (last_die
->name
== NULL
17921 || strchr (last_die
->name
, '<') == NULL
))
17922 || (cu
->language
!= language_c
17923 && (last_die
->tag
== DW_TAG_class_type
17924 || last_die
->tag
== DW_TAG_interface_type
17925 || last_die
->tag
== DW_TAG_structure_type
17926 || last_die
->tag
== DW_TAG_union_type
))
17927 || ((cu
->language
== language_ada
17928 || cu
->language
== language_fortran
)
17929 && (last_die
->tag
== DW_TAG_subprogram
17930 || last_die
->tag
== DW_TAG_lexical_block
))))
17933 parent_die
= last_die
;
17937 /* Otherwise we skip to the next sibling, if any. */
17938 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17940 /* Back to the top, do it again. */
17944 partial_die_info::partial_die_info (sect_offset sect_off_
,
17945 struct abbrev_info
*abbrev
)
17946 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17950 /* Read a minimal amount of information into the minimal die structure.
17951 INFO_PTR should point just after the initial uleb128 of a DIE. */
17954 partial_die_info::read (const struct die_reader_specs
*reader
,
17955 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17957 struct dwarf2_cu
*cu
= reader
->cu
;
17958 struct dwarf2_per_objfile
*dwarf2_per_objfile
17959 = cu
->per_cu
->dwarf2_per_objfile
;
17961 int has_low_pc_attr
= 0;
17962 int has_high_pc_attr
= 0;
17963 int high_pc_relative
= 0;
17965 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17966 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17968 bool need_reprocess
;
17969 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17970 info_ptr
, &need_reprocess
);
17971 /* String and address offsets that need to do the reprocessing have
17972 already been read at this point, so there is no need to wait until
17973 the loop terminates to do the reprocessing. */
17974 if (need_reprocess
)
17975 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17976 attribute
&attr
= attr_vec
[i
];
17977 /* Store the data if it is of an attribute we want to keep in a
17978 partial symbol table. */
17984 case DW_TAG_compile_unit
:
17985 case DW_TAG_partial_unit
:
17986 case DW_TAG_type_unit
:
17987 /* Compilation units have a DW_AT_name that is a filename, not
17988 a source language identifier. */
17989 case DW_TAG_enumeration_type
:
17990 case DW_TAG_enumerator
:
17991 /* These tags always have simple identifiers already; no need
17992 to canonicalize them. */
17993 name
= DW_STRING (&attr
);
17997 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18000 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18005 case DW_AT_linkage_name
:
18006 case DW_AT_MIPS_linkage_name
:
18007 /* Note that both forms of linkage name might appear. We
18008 assume they will be the same, and we only store the last
18010 linkage_name
= DW_STRING (&attr
);
18013 has_low_pc_attr
= 1;
18014 lowpc
= attr
.value_as_address ();
18016 case DW_AT_high_pc
:
18017 has_high_pc_attr
= 1;
18018 highpc
= attr
.value_as_address ();
18019 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18020 high_pc_relative
= 1;
18022 case DW_AT_location
:
18023 /* Support the .debug_loc offsets. */
18024 if (attr
.form_is_block ())
18026 d
.locdesc
= DW_BLOCK (&attr
);
18028 else if (attr
.form_is_section_offset ())
18030 dwarf2_complex_location_expr_complaint ();
18034 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18035 "partial symbol information");
18038 case DW_AT_external
:
18039 is_external
= DW_UNSND (&attr
);
18041 case DW_AT_declaration
:
18042 is_declaration
= DW_UNSND (&attr
);
18047 case DW_AT_abstract_origin
:
18048 case DW_AT_specification
:
18049 case DW_AT_extension
:
18050 has_specification
= 1;
18051 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18052 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18053 || cu
->per_cu
->is_dwz
);
18055 case DW_AT_sibling
:
18056 /* Ignore absolute siblings, they might point outside of
18057 the current compile unit. */
18058 if (attr
.form
== DW_FORM_ref_addr
)
18059 complaint (_("ignoring absolute DW_AT_sibling"));
18062 const gdb_byte
*buffer
= reader
->buffer
;
18063 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18064 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18066 if (sibling_ptr
< info_ptr
)
18067 complaint (_("DW_AT_sibling points backwards"));
18068 else if (sibling_ptr
> reader
->buffer_end
)
18069 reader
->die_section
->overflow_complaint ();
18071 sibling
= sibling_ptr
;
18074 case DW_AT_byte_size
:
18077 case DW_AT_const_value
:
18078 has_const_value
= 1;
18080 case DW_AT_calling_convention
:
18081 /* DWARF doesn't provide a way to identify a program's source-level
18082 entry point. DW_AT_calling_convention attributes are only meant
18083 to describe functions' calling conventions.
18085 However, because it's a necessary piece of information in
18086 Fortran, and before DWARF 4 DW_CC_program was the only
18087 piece of debugging information whose definition refers to
18088 a 'main program' at all, several compilers marked Fortran
18089 main programs with DW_CC_program --- even when those
18090 functions use the standard calling conventions.
18092 Although DWARF now specifies a way to provide this
18093 information, we support this practice for backward
18095 if (DW_UNSND (&attr
) == DW_CC_program
18096 && cu
->language
== language_fortran
)
18097 main_subprogram
= 1;
18100 if (DW_UNSND (&attr
) == DW_INL_inlined
18101 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18102 may_be_inlined
= 1;
18106 if (tag
== DW_TAG_imported_unit
)
18108 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18109 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18110 || cu
->per_cu
->is_dwz
);
18114 case DW_AT_main_subprogram
:
18115 main_subprogram
= DW_UNSND (&attr
);
18120 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18121 but that requires a full DIE, so instead we just
18123 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18124 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18125 + (need_ranges_base
18129 /* Value of the DW_AT_ranges attribute is the offset in the
18130 .debug_ranges section. */
18131 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18142 /* For Ada, if both the name and the linkage name appear, we prefer
18143 the latter. This lets "catch exception" work better, regardless
18144 of the order in which the name and linkage name were emitted.
18145 Really, though, this is just a workaround for the fact that gdb
18146 doesn't store both the name and the linkage name. */
18147 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18148 name
= linkage_name
;
18150 if (high_pc_relative
)
18153 if (has_low_pc_attr
&& has_high_pc_attr
)
18155 /* When using the GNU linker, .gnu.linkonce. sections are used to
18156 eliminate duplicate copies of functions and vtables and such.
18157 The linker will arbitrarily choose one and discard the others.
18158 The AT_*_pc values for such functions refer to local labels in
18159 these sections. If the section from that file was discarded, the
18160 labels are not in the output, so the relocs get a value of 0.
18161 If this is a discarded function, mark the pc bounds as invalid,
18162 so that GDB will ignore it. */
18163 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18165 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18166 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18168 complaint (_("DW_AT_low_pc %s is zero "
18169 "for DIE at %s [in module %s]"),
18170 paddress (gdbarch
, lowpc
),
18171 sect_offset_str (sect_off
),
18172 objfile_name (objfile
));
18174 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18175 else if (lowpc
>= highpc
)
18177 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18178 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18180 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18181 "for DIE at %s [in module %s]"),
18182 paddress (gdbarch
, lowpc
),
18183 paddress (gdbarch
, highpc
),
18184 sect_offset_str (sect_off
),
18185 objfile_name (objfile
));
18194 /* Find a cached partial DIE at OFFSET in CU. */
18196 struct partial_die_info
*
18197 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18199 struct partial_die_info
*lookup_die
= NULL
;
18200 struct partial_die_info
part_die (sect_off
);
18202 lookup_die
= ((struct partial_die_info
*)
18203 htab_find_with_hash (partial_dies
, &part_die
,
18204 to_underlying (sect_off
)));
18209 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18210 except in the case of .debug_types DIEs which do not reference
18211 outside their CU (they do however referencing other types via
18212 DW_FORM_ref_sig8). */
18214 static const struct cu_partial_die_info
18215 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18217 struct dwarf2_per_objfile
*dwarf2_per_objfile
18218 = cu
->per_cu
->dwarf2_per_objfile
;
18219 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18220 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18221 struct partial_die_info
*pd
= NULL
;
18223 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18224 && cu
->header
.offset_in_cu_p (sect_off
))
18226 pd
= cu
->find_partial_die (sect_off
);
18229 /* We missed recording what we needed.
18230 Load all dies and try again. */
18231 per_cu
= cu
->per_cu
;
18235 /* TUs don't reference other CUs/TUs (except via type signatures). */
18236 if (cu
->per_cu
->is_debug_types
)
18238 error (_("Dwarf Error: Type Unit at offset %s contains"
18239 " external reference to offset %s [in module %s].\n"),
18240 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18241 bfd_get_filename (objfile
->obfd
));
18243 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18244 dwarf2_per_objfile
);
18246 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18247 load_partial_comp_unit (per_cu
);
18249 per_cu
->cu
->last_used
= 0;
18250 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18253 /* If we didn't find it, and not all dies have been loaded,
18254 load them all and try again. */
18256 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18258 per_cu
->load_all_dies
= 1;
18260 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18261 THIS_CU->cu may already be in use. So we can't just free it and
18262 replace its DIEs with the ones we read in. Instead, we leave those
18263 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18264 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18266 load_partial_comp_unit (per_cu
);
18268 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18272 internal_error (__FILE__
, __LINE__
,
18273 _("could not find partial DIE %s "
18274 "in cache [from module %s]\n"),
18275 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18276 return { per_cu
->cu
, pd
};
18279 /* See if we can figure out if the class lives in a namespace. We do
18280 this by looking for a member function; its demangled name will
18281 contain namespace info, if there is any. */
18284 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18285 struct dwarf2_cu
*cu
)
18287 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18288 what template types look like, because the demangler
18289 frequently doesn't give the same name as the debug info. We
18290 could fix this by only using the demangled name to get the
18291 prefix (but see comment in read_structure_type). */
18293 struct partial_die_info
*real_pdi
;
18294 struct partial_die_info
*child_pdi
;
18296 /* If this DIE (this DIE's specification, if any) has a parent, then
18297 we should not do this. We'll prepend the parent's fully qualified
18298 name when we create the partial symbol. */
18300 real_pdi
= struct_pdi
;
18301 while (real_pdi
->has_specification
)
18303 auto res
= find_partial_die (real_pdi
->spec_offset
,
18304 real_pdi
->spec_is_dwz
, cu
);
18305 real_pdi
= res
.pdi
;
18309 if (real_pdi
->die_parent
!= NULL
)
18312 for (child_pdi
= struct_pdi
->die_child
;
18314 child_pdi
= child_pdi
->die_sibling
)
18316 if (child_pdi
->tag
== DW_TAG_subprogram
18317 && child_pdi
->linkage_name
!= NULL
)
18319 gdb::unique_xmalloc_ptr
<char> actual_class_name
18320 (language_class_name_from_physname (cu
->language_defn
,
18321 child_pdi
->linkage_name
));
18322 if (actual_class_name
!= NULL
)
18324 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18325 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18333 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18335 /* Once we've fixed up a die, there's no point in doing so again.
18336 This also avoids a memory leak if we were to call
18337 guess_partial_die_structure_name multiple times. */
18341 /* If we found a reference attribute and the DIE has no name, try
18342 to find a name in the referred to DIE. */
18344 if (name
== NULL
&& has_specification
)
18346 struct partial_die_info
*spec_die
;
18348 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18349 spec_die
= res
.pdi
;
18352 spec_die
->fixup (cu
);
18354 if (spec_die
->name
)
18356 name
= spec_die
->name
;
18358 /* Copy DW_AT_external attribute if it is set. */
18359 if (spec_die
->is_external
)
18360 is_external
= spec_die
->is_external
;
18364 /* Set default names for some unnamed DIEs. */
18366 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18367 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18369 /* If there is no parent die to provide a namespace, and there are
18370 children, see if we can determine the namespace from their linkage
18372 if (cu
->language
== language_cplus
18373 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18374 && die_parent
== NULL
18376 && (tag
== DW_TAG_class_type
18377 || tag
== DW_TAG_structure_type
18378 || tag
== DW_TAG_union_type
))
18379 guess_partial_die_structure_name (this, cu
);
18381 /* GCC might emit a nameless struct or union that has a linkage
18382 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18384 && (tag
== DW_TAG_class_type
18385 || tag
== DW_TAG_interface_type
18386 || tag
== DW_TAG_structure_type
18387 || tag
== DW_TAG_union_type
)
18388 && linkage_name
!= NULL
)
18390 gdb::unique_xmalloc_ptr
<char> demangled
18391 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18392 if (demangled
!= nullptr)
18396 /* Strip any leading namespaces/classes, keep only the base name.
18397 DW_AT_name for named DIEs does not contain the prefixes. */
18398 base
= strrchr (demangled
.get (), ':');
18399 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18402 base
= demangled
.get ();
18404 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18405 name
= objfile
->intern (base
);
18412 /* Process the attributes that had to be skipped in the first round. These
18413 attributes are the ones that need str_offsets_base or addr_base attributes.
18414 They could not have been processed in the first round, because at the time
18415 the values of str_offsets_base or addr_base may not have been known. */
18416 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18417 struct attribute
*attr
)
18419 struct dwarf2_cu
*cu
= reader
->cu
;
18420 switch (attr
->form
)
18422 case DW_FORM_addrx
:
18423 case DW_FORM_GNU_addr_index
:
18424 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18427 case DW_FORM_strx1
:
18428 case DW_FORM_strx2
:
18429 case DW_FORM_strx3
:
18430 case DW_FORM_strx4
:
18431 case DW_FORM_GNU_str_index
:
18433 unsigned int str_index
= DW_UNSND (attr
);
18434 if (reader
->dwo_file
!= NULL
)
18436 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18437 DW_STRING_IS_CANONICAL (attr
) = 0;
18441 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18442 DW_STRING_IS_CANONICAL (attr
) = 0;
18447 gdb_assert_not_reached (_("Unexpected DWARF form."));
18451 /* Read an attribute value described by an attribute form. */
18453 static const gdb_byte
*
18454 read_attribute_value (const struct die_reader_specs
*reader
,
18455 struct attribute
*attr
, unsigned form
,
18456 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18457 bool *need_reprocess
)
18459 struct dwarf2_cu
*cu
= reader
->cu
;
18460 struct dwarf2_per_objfile
*dwarf2_per_objfile
18461 = cu
->per_cu
->dwarf2_per_objfile
;
18462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18463 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18464 bfd
*abfd
= reader
->abfd
;
18465 struct comp_unit_head
*cu_header
= &cu
->header
;
18466 unsigned int bytes_read
;
18467 struct dwarf_block
*blk
;
18468 *need_reprocess
= false;
18470 attr
->form
= (enum dwarf_form
) form
;
18473 case DW_FORM_ref_addr
:
18474 if (cu
->header
.version
== 2)
18475 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18478 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18480 info_ptr
+= bytes_read
;
18482 case DW_FORM_GNU_ref_alt
:
18483 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18484 info_ptr
+= bytes_read
;
18487 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18488 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18489 info_ptr
+= bytes_read
;
18491 case DW_FORM_block2
:
18492 blk
= dwarf_alloc_block (cu
);
18493 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18495 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18496 info_ptr
+= blk
->size
;
18497 DW_BLOCK (attr
) = blk
;
18499 case DW_FORM_block4
:
18500 blk
= dwarf_alloc_block (cu
);
18501 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18503 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18504 info_ptr
+= blk
->size
;
18505 DW_BLOCK (attr
) = blk
;
18507 case DW_FORM_data2
:
18508 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18511 case DW_FORM_data4
:
18512 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18515 case DW_FORM_data8
:
18516 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18519 case DW_FORM_data16
:
18520 blk
= dwarf_alloc_block (cu
);
18522 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18524 DW_BLOCK (attr
) = blk
;
18526 case DW_FORM_sec_offset
:
18527 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18528 info_ptr
+= bytes_read
;
18530 case DW_FORM_string
:
18531 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18532 DW_STRING_IS_CANONICAL (attr
) = 0;
18533 info_ptr
+= bytes_read
;
18536 if (!cu
->per_cu
->is_dwz
)
18538 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18539 abfd
, info_ptr
, cu_header
,
18541 DW_STRING_IS_CANONICAL (attr
) = 0;
18542 info_ptr
+= bytes_read
;
18546 case DW_FORM_line_strp
:
18547 if (!cu
->per_cu
->is_dwz
)
18550 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18552 DW_STRING_IS_CANONICAL (attr
) = 0;
18553 info_ptr
+= bytes_read
;
18557 case DW_FORM_GNU_strp_alt
:
18559 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18560 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18563 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18564 DW_STRING_IS_CANONICAL (attr
) = 0;
18565 info_ptr
+= bytes_read
;
18568 case DW_FORM_exprloc
:
18569 case DW_FORM_block
:
18570 blk
= dwarf_alloc_block (cu
);
18571 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18572 info_ptr
+= bytes_read
;
18573 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18574 info_ptr
+= blk
->size
;
18575 DW_BLOCK (attr
) = blk
;
18577 case DW_FORM_block1
:
18578 blk
= dwarf_alloc_block (cu
);
18579 blk
->size
= read_1_byte (abfd
, info_ptr
);
18581 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18582 info_ptr
+= blk
->size
;
18583 DW_BLOCK (attr
) = blk
;
18585 case DW_FORM_data1
:
18586 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18590 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18593 case DW_FORM_flag_present
:
18594 DW_UNSND (attr
) = 1;
18596 case DW_FORM_sdata
:
18597 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18598 info_ptr
+= bytes_read
;
18600 case DW_FORM_udata
:
18601 case DW_FORM_rnglistx
:
18602 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18603 info_ptr
+= bytes_read
;
18606 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18607 + read_1_byte (abfd
, info_ptr
));
18611 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18612 + read_2_bytes (abfd
, info_ptr
));
18616 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18617 + read_4_bytes (abfd
, info_ptr
));
18621 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18622 + read_8_bytes (abfd
, info_ptr
));
18625 case DW_FORM_ref_sig8
:
18626 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18629 case DW_FORM_ref_udata
:
18630 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18631 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18632 info_ptr
+= bytes_read
;
18634 case DW_FORM_indirect
:
18635 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18636 info_ptr
+= bytes_read
;
18637 if (form
== DW_FORM_implicit_const
)
18639 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18640 info_ptr
+= bytes_read
;
18642 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18643 info_ptr
, need_reprocess
);
18645 case DW_FORM_implicit_const
:
18646 DW_SND (attr
) = implicit_const
;
18648 case DW_FORM_addrx
:
18649 case DW_FORM_GNU_addr_index
:
18650 *need_reprocess
= true;
18651 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18652 info_ptr
+= bytes_read
;
18655 case DW_FORM_strx1
:
18656 case DW_FORM_strx2
:
18657 case DW_FORM_strx3
:
18658 case DW_FORM_strx4
:
18659 case DW_FORM_GNU_str_index
:
18661 ULONGEST str_index
;
18662 if (form
== DW_FORM_strx1
)
18664 str_index
= read_1_byte (abfd
, info_ptr
);
18667 else if (form
== DW_FORM_strx2
)
18669 str_index
= read_2_bytes (abfd
, info_ptr
);
18672 else if (form
== DW_FORM_strx3
)
18674 str_index
= read_3_bytes (abfd
, info_ptr
);
18677 else if (form
== DW_FORM_strx4
)
18679 str_index
= read_4_bytes (abfd
, info_ptr
);
18684 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18685 info_ptr
+= bytes_read
;
18687 *need_reprocess
= true;
18688 DW_UNSND (attr
) = str_index
;
18692 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18693 dwarf_form_name (form
),
18694 bfd_get_filename (abfd
));
18698 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18699 attr
->form
= DW_FORM_GNU_ref_alt
;
18701 /* We have seen instances where the compiler tried to emit a byte
18702 size attribute of -1 which ended up being encoded as an unsigned
18703 0xffffffff. Although 0xffffffff is technically a valid size value,
18704 an object of this size seems pretty unlikely so we can relatively
18705 safely treat these cases as if the size attribute was invalid and
18706 treat them as zero by default. */
18707 if (attr
->name
== DW_AT_byte_size
18708 && form
== DW_FORM_data4
18709 && DW_UNSND (attr
) >= 0xffffffff)
18712 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18713 hex_string (DW_UNSND (attr
)));
18714 DW_UNSND (attr
) = 0;
18720 /* Read an attribute described by an abbreviated attribute. */
18722 static const gdb_byte
*
18723 read_attribute (const struct die_reader_specs
*reader
,
18724 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18725 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18727 attr
->name
= abbrev
->name
;
18728 return read_attribute_value (reader
, attr
, abbrev
->form
,
18729 abbrev
->implicit_const
, info_ptr
,
18733 /* Cover function for read_initial_length.
18734 Returns the length of the object at BUF, and stores the size of the
18735 initial length in *BYTES_READ and stores the size that offsets will be in
18737 If the initial length size is not equivalent to that specified in
18738 CU_HEADER then issue a complaint.
18739 This is useful when reading non-comp-unit headers. */
18742 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18743 const struct comp_unit_head
*cu_header
,
18744 unsigned int *bytes_read
,
18745 unsigned int *offset_size
)
18747 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18749 gdb_assert (cu_header
->initial_length_size
== 4
18750 || cu_header
->initial_length_size
== 8
18751 || cu_header
->initial_length_size
== 12);
18753 if (cu_header
->initial_length_size
!= *bytes_read
)
18754 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18756 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18760 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18762 static const char *
18763 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18764 LONGEST str_offset
)
18766 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18767 str_offset
, "DW_FORM_strp");
18770 /* Return pointer to string at .debug_str offset as read from BUF.
18771 BUF is assumed to be in a compilation unit described by CU_HEADER.
18772 Return *BYTES_READ_PTR count of bytes read from BUF. */
18774 static const char *
18775 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18776 const gdb_byte
*buf
,
18777 const struct comp_unit_head
*cu_header
,
18778 unsigned int *bytes_read_ptr
)
18780 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18782 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18788 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18789 const struct comp_unit_head
*cu_header
,
18790 unsigned int *bytes_read_ptr
)
18792 bfd
*abfd
= objfile
->obfd
;
18793 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18795 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18798 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18799 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18800 ADDR_SIZE is the size of addresses from the CU header. */
18803 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18804 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18807 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18808 bfd
*abfd
= objfile
->obfd
;
18809 const gdb_byte
*info_ptr
;
18810 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18812 dwarf2_per_objfile
->addr
.read (objfile
);
18813 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18814 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18815 objfile_name (objfile
));
18816 if (addr_base_or_zero
+ addr_index
* addr_size
18817 >= dwarf2_per_objfile
->addr
.size
)
18818 error (_("DW_FORM_addr_index pointing outside of "
18819 ".debug_addr section [in module %s]"),
18820 objfile_name (objfile
));
18821 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18822 + addr_base_or_zero
+ addr_index
* addr_size
);
18823 if (addr_size
== 4)
18824 return bfd_get_32 (abfd
, info_ptr
);
18826 return bfd_get_64 (abfd
, info_ptr
);
18829 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18832 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18834 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18835 cu
->addr_base
, cu
->header
.addr_size
);
18838 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18841 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18842 unsigned int *bytes_read
)
18844 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18845 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18847 return read_addr_index (cu
, addr_index
);
18853 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18855 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18856 struct dwarf2_cu
*cu
= per_cu
->cu
;
18857 gdb::optional
<ULONGEST
> addr_base
;
18860 /* We need addr_base and addr_size.
18861 If we don't have PER_CU->cu, we have to get it.
18862 Nasty, but the alternative is storing the needed info in PER_CU,
18863 which at this point doesn't seem justified: it's not clear how frequently
18864 it would get used and it would increase the size of every PER_CU.
18865 Entry points like dwarf2_per_cu_addr_size do a similar thing
18866 so we're not in uncharted territory here.
18867 Alas we need to be a bit more complicated as addr_base is contained
18870 We don't need to read the entire CU(/TU).
18871 We just need the header and top level die.
18873 IWBN to use the aging mechanism to let us lazily later discard the CU.
18874 For now we skip this optimization. */
18878 addr_base
= cu
->addr_base
;
18879 addr_size
= cu
->header
.addr_size
;
18883 cutu_reader
reader (per_cu
, NULL
, 0, false);
18884 addr_base
= reader
.cu
->addr_base
;
18885 addr_size
= reader
.cu
->header
.addr_size
;
18888 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18892 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18893 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18896 static const char *
18897 read_str_index (struct dwarf2_cu
*cu
,
18898 struct dwarf2_section_info
*str_section
,
18899 struct dwarf2_section_info
*str_offsets_section
,
18900 ULONGEST str_offsets_base
, ULONGEST str_index
)
18902 struct dwarf2_per_objfile
*dwarf2_per_objfile
18903 = cu
->per_cu
->dwarf2_per_objfile
;
18904 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18905 const char *objf_name
= objfile_name (objfile
);
18906 bfd
*abfd
= objfile
->obfd
;
18907 const gdb_byte
*info_ptr
;
18908 ULONGEST str_offset
;
18909 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18911 str_section
->read (objfile
);
18912 str_offsets_section
->read (objfile
);
18913 if (str_section
->buffer
== NULL
)
18914 error (_("%s used without %s section"
18915 " in CU at offset %s [in module %s]"),
18916 form_name
, str_section
->get_name (),
18917 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18918 if (str_offsets_section
->buffer
== NULL
)
18919 error (_("%s used without %s section"
18920 " in CU at offset %s [in module %s]"),
18921 form_name
, str_section
->get_name (),
18922 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18923 info_ptr
= (str_offsets_section
->buffer
18925 + str_index
* cu
->header
.offset_size
);
18926 if (cu
->header
.offset_size
== 4)
18927 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18929 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18930 if (str_offset
>= str_section
->size
)
18931 error (_("Offset from %s pointing outside of"
18932 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18933 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18934 return (const char *) (str_section
->buffer
+ str_offset
);
18937 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18939 static const char *
18940 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18942 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18943 ? reader
->cu
->header
.addr_size
: 0;
18944 return read_str_index (reader
->cu
,
18945 &reader
->dwo_file
->sections
.str
,
18946 &reader
->dwo_file
->sections
.str_offsets
,
18947 str_offsets_base
, str_index
);
18950 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18952 static const char *
18953 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18955 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18956 const char *objf_name
= objfile_name (objfile
);
18957 static const char form_name
[] = "DW_FORM_GNU_str_index";
18958 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18960 if (!cu
->str_offsets_base
.has_value ())
18961 error (_("%s used in Fission stub without %s"
18962 " in CU at offset 0x%lx [in module %s]"),
18963 form_name
, str_offsets_attr_name
,
18964 (long) cu
->header
.offset_size
, objf_name
);
18966 return read_str_index (cu
,
18967 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18968 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18969 *cu
->str_offsets_base
, str_index
);
18972 /* Return the length of an LEB128 number in BUF. */
18975 leb128_size (const gdb_byte
*buf
)
18977 const gdb_byte
*begin
= buf
;
18983 if ((byte
& 128) == 0)
18984 return buf
- begin
;
18989 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18998 cu
->language
= language_c
;
19001 case DW_LANG_C_plus_plus
:
19002 case DW_LANG_C_plus_plus_11
:
19003 case DW_LANG_C_plus_plus_14
:
19004 cu
->language
= language_cplus
;
19007 cu
->language
= language_d
;
19009 case DW_LANG_Fortran77
:
19010 case DW_LANG_Fortran90
:
19011 case DW_LANG_Fortran95
:
19012 case DW_LANG_Fortran03
:
19013 case DW_LANG_Fortran08
:
19014 cu
->language
= language_fortran
;
19017 cu
->language
= language_go
;
19019 case DW_LANG_Mips_Assembler
:
19020 cu
->language
= language_asm
;
19022 case DW_LANG_Ada83
:
19023 case DW_LANG_Ada95
:
19024 cu
->language
= language_ada
;
19026 case DW_LANG_Modula2
:
19027 cu
->language
= language_m2
;
19029 case DW_LANG_Pascal83
:
19030 cu
->language
= language_pascal
;
19033 cu
->language
= language_objc
;
19036 case DW_LANG_Rust_old
:
19037 cu
->language
= language_rust
;
19039 case DW_LANG_Cobol74
:
19040 case DW_LANG_Cobol85
:
19042 cu
->language
= language_minimal
;
19045 cu
->language_defn
= language_def (cu
->language
);
19048 /* Return the named attribute or NULL if not there. */
19050 static struct attribute
*
19051 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19056 struct attribute
*spec
= NULL
;
19058 for (i
= 0; i
< die
->num_attrs
; ++i
)
19060 if (die
->attrs
[i
].name
== name
)
19061 return &die
->attrs
[i
];
19062 if (die
->attrs
[i
].name
== DW_AT_specification
19063 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19064 spec
= &die
->attrs
[i
];
19070 die
= follow_die_ref (die
, spec
, &cu
);
19076 /* Return the named attribute or NULL if not there,
19077 but do not follow DW_AT_specification, etc.
19078 This is for use in contexts where we're reading .debug_types dies.
19079 Following DW_AT_specification, DW_AT_abstract_origin will take us
19080 back up the chain, and we want to go down. */
19082 static struct attribute
*
19083 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19087 for (i
= 0; i
< die
->num_attrs
; ++i
)
19088 if (die
->attrs
[i
].name
== name
)
19089 return &die
->attrs
[i
];
19094 /* Return the string associated with a string-typed attribute, or NULL if it
19095 is either not found or is of an incorrect type. */
19097 static const char *
19098 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19100 struct attribute
*attr
;
19101 const char *str
= NULL
;
19103 attr
= dwarf2_attr (die
, name
, cu
);
19107 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19108 || attr
->form
== DW_FORM_string
19109 || attr
->form
== DW_FORM_strx
19110 || attr
->form
== DW_FORM_strx1
19111 || attr
->form
== DW_FORM_strx2
19112 || attr
->form
== DW_FORM_strx3
19113 || attr
->form
== DW_FORM_strx4
19114 || attr
->form
== DW_FORM_GNU_str_index
19115 || attr
->form
== DW_FORM_GNU_strp_alt
)
19116 str
= DW_STRING (attr
);
19118 complaint (_("string type expected for attribute %s for "
19119 "DIE at %s in module %s"),
19120 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19121 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19127 /* Return the dwo name or NULL if not present. If present, it is in either
19128 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19129 static const char *
19130 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19132 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19133 if (dwo_name
== nullptr)
19134 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19138 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19139 and holds a non-zero value. This function should only be used for
19140 DW_FORM_flag or DW_FORM_flag_present attributes. */
19143 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19145 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19147 return (attr
&& DW_UNSND (attr
));
19151 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19153 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19154 which value is non-zero. However, we have to be careful with
19155 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19156 (via dwarf2_flag_true_p) follows this attribute. So we may
19157 end up accidently finding a declaration attribute that belongs
19158 to a different DIE referenced by the specification attribute,
19159 even though the given DIE does not have a declaration attribute. */
19160 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19161 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19164 /* Return the die giving the specification for DIE, if there is
19165 one. *SPEC_CU is the CU containing DIE on input, and the CU
19166 containing the return value on output. If there is no
19167 specification, but there is an abstract origin, that is
19170 static struct die_info
*
19171 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19173 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19176 if (spec_attr
== NULL
)
19177 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19179 if (spec_attr
== NULL
)
19182 return follow_die_ref (die
, spec_attr
, spec_cu
);
19185 /* Stub for free_line_header to match void * callback types. */
19188 free_line_header_voidp (void *arg
)
19190 struct line_header
*lh
= (struct line_header
*) arg
;
19195 /* A convenience function to find the proper .debug_line section for a CU. */
19197 static struct dwarf2_section_info
*
19198 get_debug_line_section (struct dwarf2_cu
*cu
)
19200 struct dwarf2_section_info
*section
;
19201 struct dwarf2_per_objfile
*dwarf2_per_objfile
19202 = cu
->per_cu
->dwarf2_per_objfile
;
19204 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19206 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19207 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19208 else if (cu
->per_cu
->is_dwz
)
19210 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19212 section
= &dwz
->line
;
19215 section
= &dwarf2_per_objfile
->line
;
19220 /* Read directory or file name entry format, starting with byte of
19221 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19222 entries count and the entries themselves in the described entry
19226 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19227 bfd
*abfd
, const gdb_byte
**bufp
,
19228 struct line_header
*lh
,
19229 const struct comp_unit_head
*cu_header
,
19230 void (*callback
) (struct line_header
*lh
,
19233 unsigned int mod_time
,
19234 unsigned int length
))
19236 gdb_byte format_count
, formati
;
19237 ULONGEST data_count
, datai
;
19238 const gdb_byte
*buf
= *bufp
;
19239 const gdb_byte
*format_header_data
;
19240 unsigned int bytes_read
;
19242 format_count
= read_1_byte (abfd
, buf
);
19244 format_header_data
= buf
;
19245 for (formati
= 0; formati
< format_count
; formati
++)
19247 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19249 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19253 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19255 for (datai
= 0; datai
< data_count
; datai
++)
19257 const gdb_byte
*format
= format_header_data
;
19258 struct file_entry fe
;
19260 for (formati
= 0; formati
< format_count
; formati
++)
19262 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19263 format
+= bytes_read
;
19265 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19266 format
+= bytes_read
;
19268 gdb::optional
<const char *> string
;
19269 gdb::optional
<unsigned int> uint
;
19273 case DW_FORM_string
:
19274 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19278 case DW_FORM_line_strp
:
19280 (dwarf2_per_objfile
->read_line_string (buf
,
19286 case DW_FORM_data1
:
19287 uint
.emplace (read_1_byte (abfd
, buf
));
19291 case DW_FORM_data2
:
19292 uint
.emplace (read_2_bytes (abfd
, buf
));
19296 case DW_FORM_data4
:
19297 uint
.emplace (read_4_bytes (abfd
, buf
));
19301 case DW_FORM_data8
:
19302 uint
.emplace (read_8_bytes (abfd
, buf
));
19306 case DW_FORM_data16
:
19307 /* This is used for MD5, but file_entry does not record MD5s. */
19311 case DW_FORM_udata
:
19312 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19316 case DW_FORM_block
:
19317 /* It is valid only for DW_LNCT_timestamp which is ignored by
19322 switch (content_type
)
19325 if (string
.has_value ())
19328 case DW_LNCT_directory_index
:
19329 if (uint
.has_value ())
19330 fe
.d_index
= (dir_index
) *uint
;
19332 case DW_LNCT_timestamp
:
19333 if (uint
.has_value ())
19334 fe
.mod_time
= *uint
;
19337 if (uint
.has_value ())
19343 complaint (_("Unknown format content type %s"),
19344 pulongest (content_type
));
19348 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19354 /* Read the statement program header starting at OFFSET in
19355 .debug_line, or .debug_line.dwo. Return a pointer
19356 to a struct line_header, allocated using xmalloc.
19357 Returns NULL if there is a problem reading the header, e.g., if it
19358 has a version we don't understand.
19360 NOTE: the strings in the include directory and file name tables of
19361 the returned object point into the dwarf line section buffer,
19362 and must not be freed. */
19364 static line_header_up
19365 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19367 const gdb_byte
*line_ptr
;
19368 unsigned int bytes_read
, offset_size
;
19370 const char *cur_dir
, *cur_file
;
19371 struct dwarf2_section_info
*section
;
19373 struct dwarf2_per_objfile
*dwarf2_per_objfile
19374 = cu
->per_cu
->dwarf2_per_objfile
;
19376 section
= get_debug_line_section (cu
);
19377 section
->read (dwarf2_per_objfile
->objfile
);
19378 if (section
->buffer
== NULL
)
19380 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19381 complaint (_("missing .debug_line.dwo section"));
19383 complaint (_("missing .debug_line section"));
19387 /* We can't do this until we know the section is non-empty.
19388 Only then do we know we have such a section. */
19389 abfd
= section
->get_bfd_owner ();
19391 /* Make sure that at least there's room for the total_length field.
19392 That could be 12 bytes long, but we're just going to fudge that. */
19393 if (to_underlying (sect_off
) + 4 >= section
->size
)
19395 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19399 line_header_up
lh (new line_header ());
19401 lh
->sect_off
= sect_off
;
19402 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19404 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19406 /* Read in the header. */
19408 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19409 &bytes_read
, &offset_size
);
19410 line_ptr
+= bytes_read
;
19412 const gdb_byte
*start_here
= line_ptr
;
19414 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19416 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19419 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19420 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19422 if (lh
->version
> 5)
19424 /* This is a version we don't understand. The format could have
19425 changed in ways we don't handle properly so just punt. */
19426 complaint (_("unsupported version in .debug_line section"));
19429 if (lh
->version
>= 5)
19431 gdb_byte segment_selector_size
;
19433 /* Skip address size. */
19434 read_1_byte (abfd
, line_ptr
);
19437 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19439 if (segment_selector_size
!= 0)
19441 complaint (_("unsupported segment selector size %u "
19442 "in .debug_line section"),
19443 segment_selector_size
);
19447 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19448 line_ptr
+= offset_size
;
19449 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19450 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19452 if (lh
->version
>= 4)
19454 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19458 lh
->maximum_ops_per_instruction
= 1;
19460 if (lh
->maximum_ops_per_instruction
== 0)
19462 lh
->maximum_ops_per_instruction
= 1;
19463 complaint (_("invalid maximum_ops_per_instruction "
19464 "in `.debug_line' section"));
19467 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19469 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19471 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19473 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19475 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19477 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19478 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19480 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19484 if (lh
->version
>= 5)
19486 /* Read directory table. */
19487 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19489 [] (struct line_header
*header
, const char *name
,
19490 dir_index d_index
, unsigned int mod_time
,
19491 unsigned int length
)
19493 header
->add_include_dir (name
);
19496 /* Read file name table. */
19497 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19499 [] (struct line_header
*header
, const char *name
,
19500 dir_index d_index
, unsigned int mod_time
,
19501 unsigned int length
)
19503 header
->add_file_name (name
, d_index
, mod_time
, length
);
19508 /* Read directory table. */
19509 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19511 line_ptr
+= bytes_read
;
19512 lh
->add_include_dir (cur_dir
);
19514 line_ptr
+= bytes_read
;
19516 /* Read file name table. */
19517 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19519 unsigned int mod_time
, length
;
19522 line_ptr
+= bytes_read
;
19523 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19524 line_ptr
+= bytes_read
;
19525 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19526 line_ptr
+= bytes_read
;
19527 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19528 line_ptr
+= bytes_read
;
19530 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19532 line_ptr
+= bytes_read
;
19535 if (line_ptr
> (section
->buffer
+ section
->size
))
19536 complaint (_("line number info header doesn't "
19537 "fit in `.debug_line' section"));
19542 /* Subroutine of dwarf_decode_lines to simplify it.
19543 Return the file name of the psymtab for the given file_entry.
19544 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19545 If space for the result is malloc'd, *NAME_HOLDER will be set.
19546 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19548 static const char *
19549 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19550 const dwarf2_psymtab
*pst
,
19551 const char *comp_dir
,
19552 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19554 const char *include_name
= fe
.name
;
19555 const char *include_name_to_compare
= include_name
;
19556 const char *pst_filename
;
19559 const char *dir_name
= fe
.include_dir (lh
);
19561 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19562 if (!IS_ABSOLUTE_PATH (include_name
)
19563 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19565 /* Avoid creating a duplicate psymtab for PST.
19566 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19567 Before we do the comparison, however, we need to account
19568 for DIR_NAME and COMP_DIR.
19569 First prepend dir_name (if non-NULL). If we still don't
19570 have an absolute path prepend comp_dir (if non-NULL).
19571 However, the directory we record in the include-file's
19572 psymtab does not contain COMP_DIR (to match the
19573 corresponding symtab(s)).
19578 bash$ gcc -g ./hello.c
19579 include_name = "hello.c"
19581 DW_AT_comp_dir = comp_dir = "/tmp"
19582 DW_AT_name = "./hello.c"
19586 if (dir_name
!= NULL
)
19588 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19589 include_name
, (char *) NULL
));
19590 include_name
= name_holder
->get ();
19591 include_name_to_compare
= include_name
;
19593 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19595 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19596 include_name
, (char *) NULL
));
19597 include_name_to_compare
= hold_compare
.get ();
19601 pst_filename
= pst
->filename
;
19602 gdb::unique_xmalloc_ptr
<char> copied_name
;
19603 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19605 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19606 pst_filename
, (char *) NULL
));
19607 pst_filename
= copied_name
.get ();
19610 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19614 return include_name
;
19617 /* State machine to track the state of the line number program. */
19619 class lnp_state_machine
19622 /* Initialize a machine state for the start of a line number
19624 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19625 bool record_lines_p
);
19627 file_entry
*current_file ()
19629 /* lh->file_names is 0-based, but the file name numbers in the
19630 statement program are 1-based. */
19631 return m_line_header
->file_name_at (m_file
);
19634 /* Record the line in the state machine. END_SEQUENCE is true if
19635 we're processing the end of a sequence. */
19636 void record_line (bool end_sequence
);
19638 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19639 nop-out rest of the lines in this sequence. */
19640 void check_line_address (struct dwarf2_cu
*cu
,
19641 const gdb_byte
*line_ptr
,
19642 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19644 void handle_set_discriminator (unsigned int discriminator
)
19646 m_discriminator
= discriminator
;
19647 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19650 /* Handle DW_LNE_set_address. */
19651 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19654 address
+= baseaddr
;
19655 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19658 /* Handle DW_LNS_advance_pc. */
19659 void handle_advance_pc (CORE_ADDR adjust
);
19661 /* Handle a special opcode. */
19662 void handle_special_opcode (unsigned char op_code
);
19664 /* Handle DW_LNS_advance_line. */
19665 void handle_advance_line (int line_delta
)
19667 advance_line (line_delta
);
19670 /* Handle DW_LNS_set_file. */
19671 void handle_set_file (file_name_index file
);
19673 /* Handle DW_LNS_negate_stmt. */
19674 void handle_negate_stmt ()
19676 m_is_stmt
= !m_is_stmt
;
19679 /* Handle DW_LNS_const_add_pc. */
19680 void handle_const_add_pc ();
19682 /* Handle DW_LNS_fixed_advance_pc. */
19683 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19685 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19689 /* Handle DW_LNS_copy. */
19690 void handle_copy ()
19692 record_line (false);
19693 m_discriminator
= 0;
19696 /* Handle DW_LNE_end_sequence. */
19697 void handle_end_sequence ()
19699 m_currently_recording_lines
= true;
19703 /* Advance the line by LINE_DELTA. */
19704 void advance_line (int line_delta
)
19706 m_line
+= line_delta
;
19708 if (line_delta
!= 0)
19709 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19712 struct dwarf2_cu
*m_cu
;
19714 gdbarch
*m_gdbarch
;
19716 /* True if we're recording lines.
19717 Otherwise we're building partial symtabs and are just interested in
19718 finding include files mentioned by the line number program. */
19719 bool m_record_lines_p
;
19721 /* The line number header. */
19722 line_header
*m_line_header
;
19724 /* These are part of the standard DWARF line number state machine,
19725 and initialized according to the DWARF spec. */
19727 unsigned char m_op_index
= 0;
19728 /* The line table index of the current file. */
19729 file_name_index m_file
= 1;
19730 unsigned int m_line
= 1;
19732 /* These are initialized in the constructor. */
19734 CORE_ADDR m_address
;
19736 unsigned int m_discriminator
;
19738 /* Additional bits of state we need to track. */
19740 /* The last file that we called dwarf2_start_subfile for.
19741 This is only used for TLLs. */
19742 unsigned int m_last_file
= 0;
19743 /* The last file a line number was recorded for. */
19744 struct subfile
*m_last_subfile
= NULL
;
19746 /* When true, record the lines we decode. */
19747 bool m_currently_recording_lines
= false;
19749 /* The last line number that was recorded, used to coalesce
19750 consecutive entries for the same line. This can happen, for
19751 example, when discriminators are present. PR 17276. */
19752 unsigned int m_last_line
= 0;
19753 bool m_line_has_non_zero_discriminator
= false;
19757 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19759 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19760 / m_line_header
->maximum_ops_per_instruction
)
19761 * m_line_header
->minimum_instruction_length
);
19762 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19763 m_op_index
= ((m_op_index
+ adjust
)
19764 % m_line_header
->maximum_ops_per_instruction
);
19768 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19770 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19771 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19772 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19773 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19774 / m_line_header
->maximum_ops_per_instruction
)
19775 * m_line_header
->minimum_instruction_length
);
19776 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19777 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19778 % m_line_header
->maximum_ops_per_instruction
);
19780 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19781 advance_line (line_delta
);
19782 record_line (false);
19783 m_discriminator
= 0;
19787 lnp_state_machine::handle_set_file (file_name_index file
)
19791 const file_entry
*fe
= current_file ();
19793 dwarf2_debug_line_missing_file_complaint ();
19794 else if (m_record_lines_p
)
19796 const char *dir
= fe
->include_dir (m_line_header
);
19798 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19799 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19800 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19805 lnp_state_machine::handle_const_add_pc ()
19808 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19811 = (((m_op_index
+ adjust
)
19812 / m_line_header
->maximum_ops_per_instruction
)
19813 * m_line_header
->minimum_instruction_length
);
19815 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19816 m_op_index
= ((m_op_index
+ adjust
)
19817 % m_line_header
->maximum_ops_per_instruction
);
19820 /* Return non-zero if we should add LINE to the line number table.
19821 LINE is the line to add, LAST_LINE is the last line that was added,
19822 LAST_SUBFILE is the subfile for LAST_LINE.
19823 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19824 had a non-zero discriminator.
19826 We have to be careful in the presence of discriminators.
19827 E.g., for this line:
19829 for (i = 0; i < 100000; i++);
19831 clang can emit four line number entries for that one line,
19832 each with a different discriminator.
19833 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19835 However, we want gdb to coalesce all four entries into one.
19836 Otherwise the user could stepi into the middle of the line and
19837 gdb would get confused about whether the pc really was in the
19838 middle of the line.
19840 Things are further complicated by the fact that two consecutive
19841 line number entries for the same line is a heuristic used by gcc
19842 to denote the end of the prologue. So we can't just discard duplicate
19843 entries, we have to be selective about it. The heuristic we use is
19844 that we only collapse consecutive entries for the same line if at least
19845 one of those entries has a non-zero discriminator. PR 17276.
19847 Note: Addresses in the line number state machine can never go backwards
19848 within one sequence, thus this coalescing is ok. */
19851 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19852 unsigned int line
, unsigned int last_line
,
19853 int line_has_non_zero_discriminator
,
19854 struct subfile
*last_subfile
)
19856 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19858 if (line
!= last_line
)
19860 /* Same line for the same file that we've seen already.
19861 As a last check, for pr 17276, only record the line if the line
19862 has never had a non-zero discriminator. */
19863 if (!line_has_non_zero_discriminator
)
19868 /* Use the CU's builder to record line number LINE beginning at
19869 address ADDRESS in the line table of subfile SUBFILE. */
19872 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19873 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19874 struct dwarf2_cu
*cu
)
19876 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19878 if (dwarf_line_debug
)
19880 fprintf_unfiltered (gdb_stdlog
,
19881 "Recording line %u, file %s, address %s\n",
19882 line
, lbasename (subfile
->name
),
19883 paddress (gdbarch
, address
));
19887 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19890 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19891 Mark the end of a set of line number records.
19892 The arguments are the same as for dwarf_record_line_1.
19893 If SUBFILE is NULL the request is ignored. */
19896 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19897 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19899 if (subfile
== NULL
)
19902 if (dwarf_line_debug
)
19904 fprintf_unfiltered (gdb_stdlog
,
19905 "Finishing current line, file %s, address %s\n",
19906 lbasename (subfile
->name
),
19907 paddress (gdbarch
, address
));
19910 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19914 lnp_state_machine::record_line (bool end_sequence
)
19916 if (dwarf_line_debug
)
19918 fprintf_unfiltered (gdb_stdlog
,
19919 "Processing actual line %u: file %u,"
19920 " address %s, is_stmt %u, discrim %u%s\n",
19922 paddress (m_gdbarch
, m_address
),
19923 m_is_stmt
, m_discriminator
,
19924 (end_sequence
? "\t(end sequence)" : ""));
19927 file_entry
*fe
= current_file ();
19930 dwarf2_debug_line_missing_file_complaint ();
19931 /* For now we ignore lines not starting on an instruction boundary.
19932 But not when processing end_sequence for compatibility with the
19933 previous version of the code. */
19934 else if (m_op_index
== 0 || end_sequence
)
19936 fe
->included_p
= 1;
19937 if (m_record_lines_p
)
19939 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19942 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19943 m_currently_recording_lines
? m_cu
: nullptr);
19948 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19950 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19951 m_line_has_non_zero_discriminator
,
19954 buildsym_compunit
*builder
= m_cu
->get_builder ();
19955 dwarf_record_line_1 (m_gdbarch
,
19956 builder
->get_current_subfile (),
19957 m_line
, m_address
, is_stmt
,
19958 m_currently_recording_lines
? m_cu
: nullptr);
19960 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19961 m_last_line
= m_line
;
19967 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19968 line_header
*lh
, bool record_lines_p
)
19972 m_record_lines_p
= record_lines_p
;
19973 m_line_header
= lh
;
19975 m_currently_recording_lines
= true;
19977 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19978 was a line entry for it so that the backend has a chance to adjust it
19979 and also record it in case it needs it. This is currently used by MIPS
19980 code, cf. `mips_adjust_dwarf2_line'. */
19981 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19982 m_is_stmt
= lh
->default_is_stmt
;
19983 m_discriminator
= 0;
19987 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19988 const gdb_byte
*line_ptr
,
19989 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19991 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19992 the pc range of the CU. However, we restrict the test to only ADDRESS
19993 values of zero to preserve GDB's previous behaviour which is to handle
19994 the specific case of a function being GC'd by the linker. */
19996 if (address
== 0 && address
< unrelocated_lowpc
)
19998 /* This line table is for a function which has been
19999 GCd by the linker. Ignore it. PR gdb/12528 */
20001 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20002 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20004 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20005 line_offset
, objfile_name (objfile
));
20006 m_currently_recording_lines
= false;
20007 /* Note: m_currently_recording_lines is left as false until we see
20008 DW_LNE_end_sequence. */
20012 /* Subroutine of dwarf_decode_lines to simplify it.
20013 Process the line number information in LH.
20014 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20015 program in order to set included_p for every referenced header. */
20018 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20019 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20021 const gdb_byte
*line_ptr
, *extended_end
;
20022 const gdb_byte
*line_end
;
20023 unsigned int bytes_read
, extended_len
;
20024 unsigned char op_code
, extended_op
;
20025 CORE_ADDR baseaddr
;
20026 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20027 bfd
*abfd
= objfile
->obfd
;
20028 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20029 /* True if we're recording line info (as opposed to building partial
20030 symtabs and just interested in finding include files mentioned by
20031 the line number program). */
20032 bool record_lines_p
= !decode_for_pst_p
;
20034 baseaddr
= objfile
->text_section_offset ();
20036 line_ptr
= lh
->statement_program_start
;
20037 line_end
= lh
->statement_program_end
;
20039 /* Read the statement sequences until there's nothing left. */
20040 while (line_ptr
< line_end
)
20042 /* The DWARF line number program state machine. Reset the state
20043 machine at the start of each sequence. */
20044 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20045 bool end_sequence
= false;
20047 if (record_lines_p
)
20049 /* Start a subfile for the current file of the state
20051 const file_entry
*fe
= state_machine
.current_file ();
20054 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20057 /* Decode the table. */
20058 while (line_ptr
< line_end
&& !end_sequence
)
20060 op_code
= read_1_byte (abfd
, line_ptr
);
20063 if (op_code
>= lh
->opcode_base
)
20065 /* Special opcode. */
20066 state_machine
.handle_special_opcode (op_code
);
20068 else switch (op_code
)
20070 case DW_LNS_extended_op
:
20071 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20073 line_ptr
+= bytes_read
;
20074 extended_end
= line_ptr
+ extended_len
;
20075 extended_op
= read_1_byte (abfd
, line_ptr
);
20077 switch (extended_op
)
20079 case DW_LNE_end_sequence
:
20080 state_machine
.handle_end_sequence ();
20081 end_sequence
= true;
20083 case DW_LNE_set_address
:
20086 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20087 line_ptr
+= bytes_read
;
20089 state_machine
.check_line_address (cu
, line_ptr
,
20090 lowpc
- baseaddr
, address
);
20091 state_machine
.handle_set_address (baseaddr
, address
);
20094 case DW_LNE_define_file
:
20096 const char *cur_file
;
20097 unsigned int mod_time
, length
;
20100 cur_file
= read_direct_string (abfd
, line_ptr
,
20102 line_ptr
+= bytes_read
;
20103 dindex
= (dir_index
)
20104 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20105 line_ptr
+= bytes_read
;
20107 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20108 line_ptr
+= bytes_read
;
20110 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20111 line_ptr
+= bytes_read
;
20112 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20115 case DW_LNE_set_discriminator
:
20117 /* The discriminator is not interesting to the
20118 debugger; just ignore it. We still need to
20119 check its value though:
20120 if there are consecutive entries for the same
20121 (non-prologue) line we want to coalesce them.
20124 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20125 line_ptr
+= bytes_read
;
20127 state_machine
.handle_set_discriminator (discr
);
20131 complaint (_("mangled .debug_line section"));
20134 /* Make sure that we parsed the extended op correctly. If e.g.
20135 we expected a different address size than the producer used,
20136 we may have read the wrong number of bytes. */
20137 if (line_ptr
!= extended_end
)
20139 complaint (_("mangled .debug_line section"));
20144 state_machine
.handle_copy ();
20146 case DW_LNS_advance_pc
:
20149 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20150 line_ptr
+= bytes_read
;
20152 state_machine
.handle_advance_pc (adjust
);
20155 case DW_LNS_advance_line
:
20158 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20159 line_ptr
+= bytes_read
;
20161 state_machine
.handle_advance_line (line_delta
);
20164 case DW_LNS_set_file
:
20166 file_name_index file
20167 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20169 line_ptr
+= bytes_read
;
20171 state_machine
.handle_set_file (file
);
20174 case DW_LNS_set_column
:
20175 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20176 line_ptr
+= bytes_read
;
20178 case DW_LNS_negate_stmt
:
20179 state_machine
.handle_negate_stmt ();
20181 case DW_LNS_set_basic_block
:
20183 /* Add to the address register of the state machine the
20184 address increment value corresponding to special opcode
20185 255. I.e., this value is scaled by the minimum
20186 instruction length since special opcode 255 would have
20187 scaled the increment. */
20188 case DW_LNS_const_add_pc
:
20189 state_machine
.handle_const_add_pc ();
20191 case DW_LNS_fixed_advance_pc
:
20193 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20196 state_machine
.handle_fixed_advance_pc (addr_adj
);
20201 /* Unknown standard opcode, ignore it. */
20204 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20206 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20207 line_ptr
+= bytes_read
;
20214 dwarf2_debug_line_missing_end_sequence_complaint ();
20216 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20217 in which case we still finish recording the last line). */
20218 state_machine
.record_line (true);
20222 /* Decode the Line Number Program (LNP) for the given line_header
20223 structure and CU. The actual information extracted and the type
20224 of structures created from the LNP depends on the value of PST.
20226 1. If PST is NULL, then this procedure uses the data from the program
20227 to create all necessary symbol tables, and their linetables.
20229 2. If PST is not NULL, this procedure reads the program to determine
20230 the list of files included by the unit represented by PST, and
20231 builds all the associated partial symbol tables.
20233 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20234 It is used for relative paths in the line table.
20235 NOTE: When processing partial symtabs (pst != NULL),
20236 comp_dir == pst->dirname.
20238 NOTE: It is important that psymtabs have the same file name (via strcmp)
20239 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20240 symtab we don't use it in the name of the psymtabs we create.
20241 E.g. expand_line_sal requires this when finding psymtabs to expand.
20242 A good testcase for this is mb-inline.exp.
20244 LOWPC is the lowest address in CU (or 0 if not known).
20246 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20247 for its PC<->lines mapping information. Otherwise only the filename
20248 table is read in. */
20251 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20252 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20253 CORE_ADDR lowpc
, int decode_mapping
)
20255 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20256 const int decode_for_pst_p
= (pst
!= NULL
);
20258 if (decode_mapping
)
20259 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20261 if (decode_for_pst_p
)
20263 /* Now that we're done scanning the Line Header Program, we can
20264 create the psymtab of each included file. */
20265 for (auto &file_entry
: lh
->file_names ())
20266 if (file_entry
.included_p
== 1)
20268 gdb::unique_xmalloc_ptr
<char> name_holder
;
20269 const char *include_name
=
20270 psymtab_include_file_name (lh
, file_entry
, pst
,
20271 comp_dir
, &name_holder
);
20272 if (include_name
!= NULL
)
20273 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20278 /* Make sure a symtab is created for every file, even files
20279 which contain only variables (i.e. no code with associated
20281 buildsym_compunit
*builder
= cu
->get_builder ();
20282 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20284 for (auto &fe
: lh
->file_names ())
20286 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20287 if (builder
->get_current_subfile ()->symtab
== NULL
)
20289 builder
->get_current_subfile ()->symtab
20290 = allocate_symtab (cust
,
20291 builder
->get_current_subfile ()->name
);
20293 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20298 /* Start a subfile for DWARF. FILENAME is the name of the file and
20299 DIRNAME the name of the source directory which contains FILENAME
20300 or NULL if not known.
20301 This routine tries to keep line numbers from identical absolute and
20302 relative file names in a common subfile.
20304 Using the `list' example from the GDB testsuite, which resides in
20305 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20306 of /srcdir/list0.c yields the following debugging information for list0.c:
20308 DW_AT_name: /srcdir/list0.c
20309 DW_AT_comp_dir: /compdir
20310 files.files[0].name: list0.h
20311 files.files[0].dir: /srcdir
20312 files.files[1].name: list0.c
20313 files.files[1].dir: /srcdir
20315 The line number information for list0.c has to end up in a single
20316 subfile, so that `break /srcdir/list0.c:1' works as expected.
20317 start_subfile will ensure that this happens provided that we pass the
20318 concatenation of files.files[1].dir and files.files[1].name as the
20322 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20323 const char *dirname
)
20325 gdb::unique_xmalloc_ptr
<char> copy
;
20327 /* In order not to lose the line information directory,
20328 we concatenate it to the filename when it makes sense.
20329 Note that the Dwarf3 standard says (speaking of filenames in line
20330 information): ``The directory index is ignored for file names
20331 that represent full path names''. Thus ignoring dirname in the
20332 `else' branch below isn't an issue. */
20334 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20336 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20337 filename
= copy
.get ();
20340 cu
->get_builder ()->start_subfile (filename
);
20343 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20344 buildsym_compunit constructor. */
20346 struct compunit_symtab
*
20347 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20350 gdb_assert (m_builder
== nullptr);
20352 m_builder
.reset (new struct buildsym_compunit
20353 (per_cu
->dwarf2_per_objfile
->objfile
,
20354 name
, comp_dir
, language
, low_pc
));
20356 list_in_scope
= get_builder ()->get_file_symbols ();
20358 get_builder ()->record_debugformat ("DWARF 2");
20359 get_builder ()->record_producer (producer
);
20361 processing_has_namespace_info
= false;
20363 return get_builder ()->get_compunit_symtab ();
20367 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20368 struct dwarf2_cu
*cu
)
20370 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20371 struct comp_unit_head
*cu_header
= &cu
->header
;
20373 /* NOTE drow/2003-01-30: There used to be a comment and some special
20374 code here to turn a symbol with DW_AT_external and a
20375 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20376 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20377 with some versions of binutils) where shared libraries could have
20378 relocations against symbols in their debug information - the
20379 minimal symbol would have the right address, but the debug info
20380 would not. It's no longer necessary, because we will explicitly
20381 apply relocations when we read in the debug information now. */
20383 /* A DW_AT_location attribute with no contents indicates that a
20384 variable has been optimized away. */
20385 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20387 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20391 /* Handle one degenerate form of location expression specially, to
20392 preserve GDB's previous behavior when section offsets are
20393 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20394 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20396 if (attr
->form_is_block ()
20397 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20398 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20399 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20400 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20401 && (DW_BLOCK (attr
)->size
20402 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20404 unsigned int dummy
;
20406 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20407 SET_SYMBOL_VALUE_ADDRESS
20408 (sym
, cu
->header
.read_address (objfile
->obfd
,
20409 DW_BLOCK (attr
)->data
+ 1,
20412 SET_SYMBOL_VALUE_ADDRESS
20413 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20415 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20416 fixup_symbol_section (sym
, objfile
);
20417 SET_SYMBOL_VALUE_ADDRESS
20419 SYMBOL_VALUE_ADDRESS (sym
)
20420 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20424 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20425 expression evaluator, and use LOC_COMPUTED only when necessary
20426 (i.e. when the value of a register or memory location is
20427 referenced, or a thread-local block, etc.). Then again, it might
20428 not be worthwhile. I'm assuming that it isn't unless performance
20429 or memory numbers show me otherwise. */
20431 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20433 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20434 cu
->has_loclist
= true;
20437 /* Given a pointer to a DWARF information entry, figure out if we need
20438 to make a symbol table entry for it, and if so, create a new entry
20439 and return a pointer to it.
20440 If TYPE is NULL, determine symbol type from the die, otherwise
20441 used the passed type.
20442 If SPACE is not NULL, use it to hold the new symbol. If it is
20443 NULL, allocate a new symbol on the objfile's obstack. */
20445 static struct symbol
*
20446 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20447 struct symbol
*space
)
20449 struct dwarf2_per_objfile
*dwarf2_per_objfile
20450 = cu
->per_cu
->dwarf2_per_objfile
;
20451 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20452 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20453 struct symbol
*sym
= NULL
;
20455 struct attribute
*attr
= NULL
;
20456 struct attribute
*attr2
= NULL
;
20457 CORE_ADDR baseaddr
;
20458 struct pending
**list_to_add
= NULL
;
20460 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20462 baseaddr
= objfile
->text_section_offset ();
20464 name
= dwarf2_name (die
, cu
);
20467 const char *linkagename
;
20468 int suppress_add
= 0;
20473 sym
= allocate_symbol (objfile
);
20474 OBJSTAT (objfile
, n_syms
++);
20476 /* Cache this symbol's name and the name's demangled form (if any). */
20477 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20478 linkagename
= dwarf2_physname (name
, die
, cu
);
20479 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20481 /* Fortran does not have mangling standard and the mangling does differ
20482 between gfortran, iFort etc. */
20483 if (cu
->language
== language_fortran
20484 && symbol_get_demangled_name (sym
) == NULL
)
20485 symbol_set_demangled_name (sym
,
20486 dwarf2_full_name (name
, die
, cu
),
20489 /* Default assumptions.
20490 Use the passed type or decode it from the die. */
20491 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20492 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20494 SYMBOL_TYPE (sym
) = type
;
20496 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20497 attr
= dwarf2_attr (die
,
20498 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20500 if (attr
!= nullptr)
20502 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20505 attr
= dwarf2_attr (die
,
20506 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20508 if (attr
!= nullptr)
20510 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20511 struct file_entry
*fe
;
20513 if (cu
->line_header
!= NULL
)
20514 fe
= cu
->line_header
->file_name_at (file_index
);
20519 complaint (_("file index out of range"));
20521 symbol_set_symtab (sym
, fe
->symtab
);
20527 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20528 if (attr
!= nullptr)
20532 addr
= attr
->value_as_address ();
20533 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20534 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20536 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20537 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20538 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20539 add_symbol_to_list (sym
, cu
->list_in_scope
);
20541 case DW_TAG_subprogram
:
20542 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20544 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20545 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20546 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20547 || cu
->language
== language_ada
20548 || cu
->language
== language_fortran
)
20550 /* Subprograms marked external are stored as a global symbol.
20551 Ada and Fortran subprograms, whether marked external or
20552 not, are always stored as a global symbol, because we want
20553 to be able to access them globally. For instance, we want
20554 to be able to break on a nested subprogram without having
20555 to specify the context. */
20556 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20560 list_to_add
= cu
->list_in_scope
;
20563 case DW_TAG_inlined_subroutine
:
20564 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20566 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20567 SYMBOL_INLINED (sym
) = 1;
20568 list_to_add
= cu
->list_in_scope
;
20570 case DW_TAG_template_value_param
:
20572 /* Fall through. */
20573 case DW_TAG_constant
:
20574 case DW_TAG_variable
:
20575 case DW_TAG_member
:
20576 /* Compilation with minimal debug info may result in
20577 variables with missing type entries. Change the
20578 misleading `void' type to something sensible. */
20579 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20580 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20582 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20583 /* In the case of DW_TAG_member, we should only be called for
20584 static const members. */
20585 if (die
->tag
== DW_TAG_member
)
20587 /* dwarf2_add_field uses die_is_declaration,
20588 so we do the same. */
20589 gdb_assert (die_is_declaration (die
, cu
));
20592 if (attr
!= nullptr)
20594 dwarf2_const_value (attr
, sym
, cu
);
20595 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20598 if (attr2
&& (DW_UNSND (attr2
) != 0))
20599 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20601 list_to_add
= cu
->list_in_scope
;
20605 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20606 if (attr
!= nullptr)
20608 var_decode_location (attr
, sym
, cu
);
20609 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20611 /* Fortran explicitly imports any global symbols to the local
20612 scope by DW_TAG_common_block. */
20613 if (cu
->language
== language_fortran
&& die
->parent
20614 && die
->parent
->tag
== DW_TAG_common_block
)
20617 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20618 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20619 && !dwarf2_per_objfile
->has_section_at_zero
)
20621 /* When a static variable is eliminated by the linker,
20622 the corresponding debug information is not stripped
20623 out, but the variable address is set to null;
20624 do not add such variables into symbol table. */
20626 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20628 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20629 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20630 && dwarf2_per_objfile
->can_copy
)
20632 /* A global static variable might be subject to
20633 copy relocation. We first check for a local
20634 minsym, though, because maybe the symbol was
20635 marked hidden, in which case this would not
20637 bound_minimal_symbol found
20638 = (lookup_minimal_symbol_linkage
20639 (sym
->linkage_name (), objfile
));
20640 if (found
.minsym
!= nullptr)
20641 sym
->maybe_copied
= 1;
20644 /* A variable with DW_AT_external is never static,
20645 but it may be block-scoped. */
20647 = ((cu
->list_in_scope
20648 == cu
->get_builder ()->get_file_symbols ())
20649 ? cu
->get_builder ()->get_global_symbols ()
20650 : cu
->list_in_scope
);
20653 list_to_add
= cu
->list_in_scope
;
20657 /* We do not know the address of this symbol.
20658 If it is an external symbol and we have type information
20659 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20660 The address of the variable will then be determined from
20661 the minimal symbol table whenever the variable is
20663 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20665 /* Fortran explicitly imports any global symbols to the local
20666 scope by DW_TAG_common_block. */
20667 if (cu
->language
== language_fortran
&& die
->parent
20668 && die
->parent
->tag
== DW_TAG_common_block
)
20670 /* SYMBOL_CLASS doesn't matter here because
20671 read_common_block is going to reset it. */
20673 list_to_add
= cu
->list_in_scope
;
20675 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20676 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20678 /* A variable with DW_AT_external is never static, but it
20679 may be block-scoped. */
20681 = ((cu
->list_in_scope
20682 == cu
->get_builder ()->get_file_symbols ())
20683 ? cu
->get_builder ()->get_global_symbols ()
20684 : cu
->list_in_scope
);
20686 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20688 else if (!die_is_declaration (die
, cu
))
20690 /* Use the default LOC_OPTIMIZED_OUT class. */
20691 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20693 list_to_add
= cu
->list_in_scope
;
20697 case DW_TAG_formal_parameter
:
20699 /* If we are inside a function, mark this as an argument. If
20700 not, we might be looking at an argument to an inlined function
20701 when we do not have enough information to show inlined frames;
20702 pretend it's a local variable in that case so that the user can
20704 struct context_stack
*curr
20705 = cu
->get_builder ()->get_current_context_stack ();
20706 if (curr
!= nullptr && curr
->name
!= nullptr)
20707 SYMBOL_IS_ARGUMENT (sym
) = 1;
20708 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20709 if (attr
!= nullptr)
20711 var_decode_location (attr
, sym
, cu
);
20713 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20714 if (attr
!= nullptr)
20716 dwarf2_const_value (attr
, sym
, cu
);
20719 list_to_add
= cu
->list_in_scope
;
20722 case DW_TAG_unspecified_parameters
:
20723 /* From varargs functions; gdb doesn't seem to have any
20724 interest in this information, so just ignore it for now.
20727 case DW_TAG_template_type_param
:
20729 /* Fall through. */
20730 case DW_TAG_class_type
:
20731 case DW_TAG_interface_type
:
20732 case DW_TAG_structure_type
:
20733 case DW_TAG_union_type
:
20734 case DW_TAG_set_type
:
20735 case DW_TAG_enumeration_type
:
20736 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20737 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20740 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20741 really ever be static objects: otherwise, if you try
20742 to, say, break of a class's method and you're in a file
20743 which doesn't mention that class, it won't work unless
20744 the check for all static symbols in lookup_symbol_aux
20745 saves you. See the OtherFileClass tests in
20746 gdb.c++/namespace.exp. */
20750 buildsym_compunit
*builder
= cu
->get_builder ();
20752 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20753 && cu
->language
== language_cplus
20754 ? builder
->get_global_symbols ()
20755 : cu
->list_in_scope
);
20757 /* The semantics of C++ state that "struct foo {
20758 ... }" also defines a typedef for "foo". */
20759 if (cu
->language
== language_cplus
20760 || cu
->language
== language_ada
20761 || cu
->language
== language_d
20762 || cu
->language
== language_rust
)
20764 /* The symbol's name is already allocated along
20765 with this objfile, so we don't need to
20766 duplicate it for the type. */
20767 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20768 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20773 case DW_TAG_typedef
:
20774 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20775 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20776 list_to_add
= cu
->list_in_scope
;
20778 case DW_TAG_base_type
:
20779 case DW_TAG_subrange_type
:
20780 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20781 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20782 list_to_add
= cu
->list_in_scope
;
20784 case DW_TAG_enumerator
:
20785 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20786 if (attr
!= nullptr)
20788 dwarf2_const_value (attr
, sym
, cu
);
20791 /* NOTE: carlton/2003-11-10: See comment above in the
20792 DW_TAG_class_type, etc. block. */
20795 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20796 && cu
->language
== language_cplus
20797 ? cu
->get_builder ()->get_global_symbols ()
20798 : cu
->list_in_scope
);
20801 case DW_TAG_imported_declaration
:
20802 case DW_TAG_namespace
:
20803 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20804 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20806 case DW_TAG_module
:
20807 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20808 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20809 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20811 case DW_TAG_common_block
:
20812 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20813 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20814 add_symbol_to_list (sym
, cu
->list_in_scope
);
20817 /* Not a tag we recognize. Hopefully we aren't processing
20818 trash data, but since we must specifically ignore things
20819 we don't recognize, there is nothing else we should do at
20821 complaint (_("unsupported tag: '%s'"),
20822 dwarf_tag_name (die
->tag
));
20828 sym
->hash_next
= objfile
->template_symbols
;
20829 objfile
->template_symbols
= sym
;
20830 list_to_add
= NULL
;
20833 if (list_to_add
!= NULL
)
20834 add_symbol_to_list (sym
, list_to_add
);
20836 /* For the benefit of old versions of GCC, check for anonymous
20837 namespaces based on the demangled name. */
20838 if (!cu
->processing_has_namespace_info
20839 && cu
->language
== language_cplus
)
20840 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20845 /* Given an attr with a DW_FORM_dataN value in host byte order,
20846 zero-extend it as appropriate for the symbol's type. The DWARF
20847 standard (v4) is not entirely clear about the meaning of using
20848 DW_FORM_dataN for a constant with a signed type, where the type is
20849 wider than the data. The conclusion of a discussion on the DWARF
20850 list was that this is unspecified. We choose to always zero-extend
20851 because that is the interpretation long in use by GCC. */
20854 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20855 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20857 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20858 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20859 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20860 LONGEST l
= DW_UNSND (attr
);
20862 if (bits
< sizeof (*value
) * 8)
20864 l
&= ((LONGEST
) 1 << bits
) - 1;
20867 else if (bits
== sizeof (*value
) * 8)
20871 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20872 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20879 /* Read a constant value from an attribute. Either set *VALUE, or if
20880 the value does not fit in *VALUE, set *BYTES - either already
20881 allocated on the objfile obstack, or newly allocated on OBSTACK,
20882 or, set *BATON, if we translated the constant to a location
20886 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20887 const char *name
, struct obstack
*obstack
,
20888 struct dwarf2_cu
*cu
,
20889 LONGEST
*value
, const gdb_byte
**bytes
,
20890 struct dwarf2_locexpr_baton
**baton
)
20892 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20893 struct comp_unit_head
*cu_header
= &cu
->header
;
20894 struct dwarf_block
*blk
;
20895 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20896 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20902 switch (attr
->form
)
20905 case DW_FORM_addrx
:
20906 case DW_FORM_GNU_addr_index
:
20910 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20911 dwarf2_const_value_length_mismatch_complaint (name
,
20912 cu_header
->addr_size
,
20913 TYPE_LENGTH (type
));
20914 /* Symbols of this form are reasonably rare, so we just
20915 piggyback on the existing location code rather than writing
20916 a new implementation of symbol_computed_ops. */
20917 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20918 (*baton
)->per_cu
= cu
->per_cu
;
20919 gdb_assert ((*baton
)->per_cu
);
20921 (*baton
)->size
= 2 + cu_header
->addr_size
;
20922 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20923 (*baton
)->data
= data
;
20925 data
[0] = DW_OP_addr
;
20926 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20927 byte_order
, DW_ADDR (attr
));
20928 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20931 case DW_FORM_string
:
20934 case DW_FORM_GNU_str_index
:
20935 case DW_FORM_GNU_strp_alt
:
20936 /* DW_STRING is already allocated on the objfile obstack, point
20938 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20940 case DW_FORM_block1
:
20941 case DW_FORM_block2
:
20942 case DW_FORM_block4
:
20943 case DW_FORM_block
:
20944 case DW_FORM_exprloc
:
20945 case DW_FORM_data16
:
20946 blk
= DW_BLOCK (attr
);
20947 if (TYPE_LENGTH (type
) != blk
->size
)
20948 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20949 TYPE_LENGTH (type
));
20950 *bytes
= blk
->data
;
20953 /* The DW_AT_const_value attributes are supposed to carry the
20954 symbol's value "represented as it would be on the target
20955 architecture." By the time we get here, it's already been
20956 converted to host endianness, so we just need to sign- or
20957 zero-extend it as appropriate. */
20958 case DW_FORM_data1
:
20959 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20961 case DW_FORM_data2
:
20962 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20964 case DW_FORM_data4
:
20965 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20967 case DW_FORM_data8
:
20968 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20971 case DW_FORM_sdata
:
20972 case DW_FORM_implicit_const
:
20973 *value
= DW_SND (attr
);
20976 case DW_FORM_udata
:
20977 *value
= DW_UNSND (attr
);
20981 complaint (_("unsupported const value attribute form: '%s'"),
20982 dwarf_form_name (attr
->form
));
20989 /* Copy constant value from an attribute to a symbol. */
20992 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20993 struct dwarf2_cu
*cu
)
20995 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20997 const gdb_byte
*bytes
;
20998 struct dwarf2_locexpr_baton
*baton
;
21000 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21001 sym
->print_name (),
21002 &objfile
->objfile_obstack
, cu
,
21003 &value
, &bytes
, &baton
);
21007 SYMBOL_LOCATION_BATON (sym
) = baton
;
21008 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21010 else if (bytes
!= NULL
)
21012 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21013 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21017 SYMBOL_VALUE (sym
) = value
;
21018 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21022 /* Return the type of the die in question using its DW_AT_type attribute. */
21024 static struct type
*
21025 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21027 struct attribute
*type_attr
;
21029 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21032 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21033 /* A missing DW_AT_type represents a void type. */
21034 return objfile_type (objfile
)->builtin_void
;
21037 return lookup_die_type (die
, type_attr
, cu
);
21040 /* True iff CU's producer generates GNAT Ada auxiliary information
21041 that allows to find parallel types through that information instead
21042 of having to do expensive parallel lookups by type name. */
21045 need_gnat_info (struct dwarf2_cu
*cu
)
21047 /* Assume that the Ada compiler was GNAT, which always produces
21048 the auxiliary information. */
21049 return (cu
->language
== language_ada
);
21052 /* Return the auxiliary type of the die in question using its
21053 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21054 attribute is not present. */
21056 static struct type
*
21057 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21059 struct attribute
*type_attr
;
21061 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21065 return lookup_die_type (die
, type_attr
, cu
);
21068 /* If DIE has a descriptive_type attribute, then set the TYPE's
21069 descriptive type accordingly. */
21072 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21073 struct dwarf2_cu
*cu
)
21075 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21077 if (descriptive_type
)
21079 ALLOCATE_GNAT_AUX_TYPE (type
);
21080 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21084 /* Return the containing type of the die in question using its
21085 DW_AT_containing_type attribute. */
21087 static struct type
*
21088 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21090 struct attribute
*type_attr
;
21091 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21093 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21095 error (_("Dwarf Error: Problem turning containing type into gdb type "
21096 "[in module %s]"), objfile_name (objfile
));
21098 return lookup_die_type (die
, type_attr
, cu
);
21101 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21103 static struct type
*
21104 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21106 struct dwarf2_per_objfile
*dwarf2_per_objfile
21107 = cu
->per_cu
->dwarf2_per_objfile
;
21108 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21111 std::string message
21112 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21113 objfile_name (objfile
),
21114 sect_offset_str (cu
->header
.sect_off
),
21115 sect_offset_str (die
->sect_off
));
21116 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21118 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21121 /* Look up the type of DIE in CU using its type attribute ATTR.
21122 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21123 DW_AT_containing_type.
21124 If there is no type substitute an error marker. */
21126 static struct type
*
21127 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21128 struct dwarf2_cu
*cu
)
21130 struct dwarf2_per_objfile
*dwarf2_per_objfile
21131 = cu
->per_cu
->dwarf2_per_objfile
;
21132 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21133 struct type
*this_type
;
21135 gdb_assert (attr
->name
== DW_AT_type
21136 || attr
->name
== DW_AT_GNAT_descriptive_type
21137 || attr
->name
== DW_AT_containing_type
);
21139 /* First see if we have it cached. */
21141 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21143 struct dwarf2_per_cu_data
*per_cu
;
21144 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21146 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21147 dwarf2_per_objfile
);
21148 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21150 else if (attr
->form_is_ref ())
21152 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21154 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21156 else if (attr
->form
== DW_FORM_ref_sig8
)
21158 ULONGEST signature
= DW_SIGNATURE (attr
);
21160 return get_signatured_type (die
, signature
, cu
);
21164 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21165 " at %s [in module %s]"),
21166 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21167 objfile_name (objfile
));
21168 return build_error_marker_type (cu
, die
);
21171 /* If not cached we need to read it in. */
21173 if (this_type
== NULL
)
21175 struct die_info
*type_die
= NULL
;
21176 struct dwarf2_cu
*type_cu
= cu
;
21178 if (attr
->form_is_ref ())
21179 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21180 if (type_die
== NULL
)
21181 return build_error_marker_type (cu
, die
);
21182 /* If we find the type now, it's probably because the type came
21183 from an inter-CU reference and the type's CU got expanded before
21185 this_type
= read_type_die (type_die
, type_cu
);
21188 /* If we still don't have a type use an error marker. */
21190 if (this_type
== NULL
)
21191 return build_error_marker_type (cu
, die
);
21196 /* Return the type in DIE, CU.
21197 Returns NULL for invalid types.
21199 This first does a lookup in die_type_hash,
21200 and only reads the die in if necessary.
21202 NOTE: This can be called when reading in partial or full symbols. */
21204 static struct type
*
21205 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21207 struct type
*this_type
;
21209 this_type
= get_die_type (die
, cu
);
21213 return read_type_die_1 (die
, cu
);
21216 /* Read the type in DIE, CU.
21217 Returns NULL for invalid types. */
21219 static struct type
*
21220 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21222 struct type
*this_type
= NULL
;
21226 case DW_TAG_class_type
:
21227 case DW_TAG_interface_type
:
21228 case DW_TAG_structure_type
:
21229 case DW_TAG_union_type
:
21230 this_type
= read_structure_type (die
, cu
);
21232 case DW_TAG_enumeration_type
:
21233 this_type
= read_enumeration_type (die
, cu
);
21235 case DW_TAG_subprogram
:
21236 case DW_TAG_subroutine_type
:
21237 case DW_TAG_inlined_subroutine
:
21238 this_type
= read_subroutine_type (die
, cu
);
21240 case DW_TAG_array_type
:
21241 this_type
= read_array_type (die
, cu
);
21243 case DW_TAG_set_type
:
21244 this_type
= read_set_type (die
, cu
);
21246 case DW_TAG_pointer_type
:
21247 this_type
= read_tag_pointer_type (die
, cu
);
21249 case DW_TAG_ptr_to_member_type
:
21250 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21252 case DW_TAG_reference_type
:
21253 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21255 case DW_TAG_rvalue_reference_type
:
21256 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21258 case DW_TAG_const_type
:
21259 this_type
= read_tag_const_type (die
, cu
);
21261 case DW_TAG_volatile_type
:
21262 this_type
= read_tag_volatile_type (die
, cu
);
21264 case DW_TAG_restrict_type
:
21265 this_type
= read_tag_restrict_type (die
, cu
);
21267 case DW_TAG_string_type
:
21268 this_type
= read_tag_string_type (die
, cu
);
21270 case DW_TAG_typedef
:
21271 this_type
= read_typedef (die
, cu
);
21273 case DW_TAG_subrange_type
:
21274 this_type
= read_subrange_type (die
, cu
);
21276 case DW_TAG_base_type
:
21277 this_type
= read_base_type (die
, cu
);
21279 case DW_TAG_unspecified_type
:
21280 this_type
= read_unspecified_type (die
, cu
);
21282 case DW_TAG_namespace
:
21283 this_type
= read_namespace_type (die
, cu
);
21285 case DW_TAG_module
:
21286 this_type
= read_module_type (die
, cu
);
21288 case DW_TAG_atomic_type
:
21289 this_type
= read_tag_atomic_type (die
, cu
);
21292 complaint (_("unexpected tag in read_type_die: '%s'"),
21293 dwarf_tag_name (die
->tag
));
21300 /* See if we can figure out if the class lives in a namespace. We do
21301 this by looking for a member function; its demangled name will
21302 contain namespace info, if there is any.
21303 Return the computed name or NULL.
21304 Space for the result is allocated on the objfile's obstack.
21305 This is the full-die version of guess_partial_die_structure_name.
21306 In this case we know DIE has no useful parent. */
21308 static const char *
21309 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21311 struct die_info
*spec_die
;
21312 struct dwarf2_cu
*spec_cu
;
21313 struct die_info
*child
;
21314 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21317 spec_die
= die_specification (die
, &spec_cu
);
21318 if (spec_die
!= NULL
)
21324 for (child
= die
->child
;
21326 child
= child
->sibling
)
21328 if (child
->tag
== DW_TAG_subprogram
)
21330 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21332 if (linkage_name
!= NULL
)
21334 gdb::unique_xmalloc_ptr
<char> actual_name
21335 (language_class_name_from_physname (cu
->language_defn
,
21337 const char *name
= NULL
;
21339 if (actual_name
!= NULL
)
21341 const char *die_name
= dwarf2_name (die
, cu
);
21343 if (die_name
!= NULL
21344 && strcmp (die_name
, actual_name
.get ()) != 0)
21346 /* Strip off the class name from the full name.
21347 We want the prefix. */
21348 int die_name_len
= strlen (die_name
);
21349 int actual_name_len
= strlen (actual_name
.get ());
21350 const char *ptr
= actual_name
.get ();
21352 /* Test for '::' as a sanity check. */
21353 if (actual_name_len
> die_name_len
+ 2
21354 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21355 name
= obstack_strndup (
21356 &objfile
->per_bfd
->storage_obstack
,
21357 ptr
, actual_name_len
- die_name_len
- 2);
21368 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21369 prefix part in such case. See
21370 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21372 static const char *
21373 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21375 struct attribute
*attr
;
21378 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21379 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21382 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21385 attr
= dw2_linkage_name_attr (die
, cu
);
21386 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21389 /* dwarf2_name had to be already called. */
21390 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21392 /* Strip the base name, keep any leading namespaces/classes. */
21393 base
= strrchr (DW_STRING (attr
), ':');
21394 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21397 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21398 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21400 &base
[-1] - DW_STRING (attr
));
21403 /* Return the name of the namespace/class that DIE is defined within,
21404 or "" if we can't tell. The caller should not xfree the result.
21406 For example, if we're within the method foo() in the following
21416 then determine_prefix on foo's die will return "N::C". */
21418 static const char *
21419 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21421 struct dwarf2_per_objfile
*dwarf2_per_objfile
21422 = cu
->per_cu
->dwarf2_per_objfile
;
21423 struct die_info
*parent
, *spec_die
;
21424 struct dwarf2_cu
*spec_cu
;
21425 struct type
*parent_type
;
21426 const char *retval
;
21428 if (cu
->language
!= language_cplus
21429 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21430 && cu
->language
!= language_rust
)
21433 retval
= anonymous_struct_prefix (die
, cu
);
21437 /* We have to be careful in the presence of DW_AT_specification.
21438 For example, with GCC 3.4, given the code
21442 // Definition of N::foo.
21446 then we'll have a tree of DIEs like this:
21448 1: DW_TAG_compile_unit
21449 2: DW_TAG_namespace // N
21450 3: DW_TAG_subprogram // declaration of N::foo
21451 4: DW_TAG_subprogram // definition of N::foo
21452 DW_AT_specification // refers to die #3
21454 Thus, when processing die #4, we have to pretend that we're in
21455 the context of its DW_AT_specification, namely the contex of die
21458 spec_die
= die_specification (die
, &spec_cu
);
21459 if (spec_die
== NULL
)
21460 parent
= die
->parent
;
21463 parent
= spec_die
->parent
;
21467 if (parent
== NULL
)
21469 else if (parent
->building_fullname
)
21472 const char *parent_name
;
21474 /* It has been seen on RealView 2.2 built binaries,
21475 DW_TAG_template_type_param types actually _defined_ as
21476 children of the parent class:
21479 template class <class Enum> Class{};
21480 Class<enum E> class_e;
21482 1: DW_TAG_class_type (Class)
21483 2: DW_TAG_enumeration_type (E)
21484 3: DW_TAG_enumerator (enum1:0)
21485 3: DW_TAG_enumerator (enum2:1)
21487 2: DW_TAG_template_type_param
21488 DW_AT_type DW_FORM_ref_udata (E)
21490 Besides being broken debug info, it can put GDB into an
21491 infinite loop. Consider:
21493 When we're building the full name for Class<E>, we'll start
21494 at Class, and go look over its template type parameters,
21495 finding E. We'll then try to build the full name of E, and
21496 reach here. We're now trying to build the full name of E,
21497 and look over the parent DIE for containing scope. In the
21498 broken case, if we followed the parent DIE of E, we'd again
21499 find Class, and once again go look at its template type
21500 arguments, etc., etc. Simply don't consider such parent die
21501 as source-level parent of this die (it can't be, the language
21502 doesn't allow it), and break the loop here. */
21503 name
= dwarf2_name (die
, cu
);
21504 parent_name
= dwarf2_name (parent
, cu
);
21505 complaint (_("template param type '%s' defined within parent '%s'"),
21506 name
? name
: "<unknown>",
21507 parent_name
? parent_name
: "<unknown>");
21511 switch (parent
->tag
)
21513 case DW_TAG_namespace
:
21514 parent_type
= read_type_die (parent
, cu
);
21515 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21516 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21517 Work around this problem here. */
21518 if (cu
->language
== language_cplus
21519 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21521 /* We give a name to even anonymous namespaces. */
21522 return TYPE_NAME (parent_type
);
21523 case DW_TAG_class_type
:
21524 case DW_TAG_interface_type
:
21525 case DW_TAG_structure_type
:
21526 case DW_TAG_union_type
:
21527 case DW_TAG_module
:
21528 parent_type
= read_type_die (parent
, cu
);
21529 if (TYPE_NAME (parent_type
) != NULL
)
21530 return TYPE_NAME (parent_type
);
21532 /* An anonymous structure is only allowed non-static data
21533 members; no typedefs, no member functions, et cetera.
21534 So it does not need a prefix. */
21536 case DW_TAG_compile_unit
:
21537 case DW_TAG_partial_unit
:
21538 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21539 if (cu
->language
== language_cplus
21540 && !dwarf2_per_objfile
->types
.empty ()
21541 && die
->child
!= NULL
21542 && (die
->tag
== DW_TAG_class_type
21543 || die
->tag
== DW_TAG_structure_type
21544 || die
->tag
== DW_TAG_union_type
))
21546 const char *name
= guess_full_die_structure_name (die
, cu
);
21551 case DW_TAG_subprogram
:
21552 /* Nested subroutines in Fortran get a prefix with the name
21553 of the parent's subroutine. */
21554 if (cu
->language
== language_fortran
)
21556 if ((die
->tag
== DW_TAG_subprogram
)
21557 && (dwarf2_name (parent
, cu
) != NULL
))
21558 return dwarf2_name (parent
, cu
);
21560 return determine_prefix (parent
, cu
);
21561 case DW_TAG_enumeration_type
:
21562 parent_type
= read_type_die (parent
, cu
);
21563 if (TYPE_DECLARED_CLASS (parent_type
))
21565 if (TYPE_NAME (parent_type
) != NULL
)
21566 return TYPE_NAME (parent_type
);
21569 /* Fall through. */
21571 return determine_prefix (parent
, cu
);
21575 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21576 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21577 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21578 an obconcat, otherwise allocate storage for the result. The CU argument is
21579 used to determine the language and hence, the appropriate separator. */
21581 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21584 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21585 int physname
, struct dwarf2_cu
*cu
)
21587 const char *lead
= "";
21590 if (suffix
== NULL
|| suffix
[0] == '\0'
21591 || prefix
== NULL
|| prefix
[0] == '\0')
21593 else if (cu
->language
== language_d
)
21595 /* For D, the 'main' function could be defined in any module, but it
21596 should never be prefixed. */
21597 if (strcmp (suffix
, "D main") == 0)
21605 else if (cu
->language
== language_fortran
&& physname
)
21607 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21608 DW_AT_MIPS_linkage_name is preferred and used instead. */
21616 if (prefix
== NULL
)
21618 if (suffix
== NULL
)
21625 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21627 strcpy (retval
, lead
);
21628 strcat (retval
, prefix
);
21629 strcat (retval
, sep
);
21630 strcat (retval
, suffix
);
21635 /* We have an obstack. */
21636 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21640 /* Return sibling of die, NULL if no sibling. */
21642 static struct die_info
*
21643 sibling_die (struct die_info
*die
)
21645 return die
->sibling
;
21648 /* Get name of a die, return NULL if not found. */
21650 static const char *
21651 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21652 struct objfile
*objfile
)
21654 if (name
&& cu
->language
== language_cplus
)
21656 std::string canon_name
= cp_canonicalize_string (name
);
21658 if (!canon_name
.empty ())
21660 if (canon_name
!= name
)
21661 name
= objfile
->intern (canon_name
);
21668 /* Get name of a die, return NULL if not found.
21669 Anonymous namespaces are converted to their magic string. */
21671 static const char *
21672 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21674 struct attribute
*attr
;
21675 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21677 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21678 if ((!attr
|| !DW_STRING (attr
))
21679 && die
->tag
!= DW_TAG_namespace
21680 && die
->tag
!= DW_TAG_class_type
21681 && die
->tag
!= DW_TAG_interface_type
21682 && die
->tag
!= DW_TAG_structure_type
21683 && die
->tag
!= DW_TAG_union_type
)
21688 case DW_TAG_compile_unit
:
21689 case DW_TAG_partial_unit
:
21690 /* Compilation units have a DW_AT_name that is a filename, not
21691 a source language identifier. */
21692 case DW_TAG_enumeration_type
:
21693 case DW_TAG_enumerator
:
21694 /* These tags always have simple identifiers already; no need
21695 to canonicalize them. */
21696 return DW_STRING (attr
);
21698 case DW_TAG_namespace
:
21699 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21700 return DW_STRING (attr
);
21701 return CP_ANONYMOUS_NAMESPACE_STR
;
21703 case DW_TAG_class_type
:
21704 case DW_TAG_interface_type
:
21705 case DW_TAG_structure_type
:
21706 case DW_TAG_union_type
:
21707 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21708 structures or unions. These were of the form "._%d" in GCC 4.1,
21709 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21710 and GCC 4.4. We work around this problem by ignoring these. */
21711 if (attr
&& DW_STRING (attr
)
21712 && (startswith (DW_STRING (attr
), "._")
21713 || startswith (DW_STRING (attr
), "<anonymous")))
21716 /* GCC might emit a nameless typedef that has a linkage name. See
21717 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21718 if (!attr
|| DW_STRING (attr
) == NULL
)
21720 attr
= dw2_linkage_name_attr (die
, cu
);
21721 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21724 /* Avoid demangling DW_STRING (attr) the second time on a second
21725 call for the same DIE. */
21726 if (!DW_STRING_IS_CANONICAL (attr
))
21728 gdb::unique_xmalloc_ptr
<char> demangled
21729 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21730 if (demangled
== nullptr)
21733 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21734 DW_STRING_IS_CANONICAL (attr
) = 1;
21737 /* Strip any leading namespaces/classes, keep only the base name.
21738 DW_AT_name for named DIEs does not contain the prefixes. */
21739 const char *base
= strrchr (DW_STRING (attr
), ':');
21740 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21743 return DW_STRING (attr
);
21751 if (!DW_STRING_IS_CANONICAL (attr
))
21753 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21755 DW_STRING_IS_CANONICAL (attr
) = 1;
21757 return DW_STRING (attr
);
21760 /* Return the die that this die in an extension of, or NULL if there
21761 is none. *EXT_CU is the CU containing DIE on input, and the CU
21762 containing the return value on output. */
21764 static struct die_info
*
21765 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21767 struct attribute
*attr
;
21769 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21773 return follow_die_ref (die
, attr
, ext_cu
);
21776 /* A convenience function that returns an "unknown" DWARF name,
21777 including the value of V. STR is the name of the entity being
21778 printed, e.g., "TAG". */
21780 static const char *
21781 dwarf_unknown (const char *str
, unsigned v
)
21783 char *cell
= get_print_cell ();
21784 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21788 /* Convert a DIE tag into its string name. */
21790 static const char *
21791 dwarf_tag_name (unsigned tag
)
21793 const char *name
= get_DW_TAG_name (tag
);
21796 return dwarf_unknown ("TAG", tag
);
21801 /* Convert a DWARF attribute code into its string name. */
21803 static const char *
21804 dwarf_attr_name (unsigned attr
)
21808 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21809 if (attr
== DW_AT_MIPS_fde
)
21810 return "DW_AT_MIPS_fde";
21812 if (attr
== DW_AT_HP_block_index
)
21813 return "DW_AT_HP_block_index";
21816 name
= get_DW_AT_name (attr
);
21819 return dwarf_unknown ("AT", attr
);
21824 /* Convert a DWARF value form code into its string name. */
21826 static const char *
21827 dwarf_form_name (unsigned form
)
21829 const char *name
= get_DW_FORM_name (form
);
21832 return dwarf_unknown ("FORM", form
);
21837 static const char *
21838 dwarf_bool_name (unsigned mybool
)
21846 /* Convert a DWARF type code into its string name. */
21848 static const char *
21849 dwarf_type_encoding_name (unsigned enc
)
21851 const char *name
= get_DW_ATE_name (enc
);
21854 return dwarf_unknown ("ATE", enc
);
21860 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21864 print_spaces (indent
, f
);
21865 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21866 dwarf_tag_name (die
->tag
), die
->abbrev
,
21867 sect_offset_str (die
->sect_off
));
21869 if (die
->parent
!= NULL
)
21871 print_spaces (indent
, f
);
21872 fprintf_unfiltered (f
, " parent at offset: %s\n",
21873 sect_offset_str (die
->parent
->sect_off
));
21876 print_spaces (indent
, f
);
21877 fprintf_unfiltered (f
, " has children: %s\n",
21878 dwarf_bool_name (die
->child
!= NULL
));
21880 print_spaces (indent
, f
);
21881 fprintf_unfiltered (f
, " attributes:\n");
21883 for (i
= 0; i
< die
->num_attrs
; ++i
)
21885 print_spaces (indent
, f
);
21886 fprintf_unfiltered (f
, " %s (%s) ",
21887 dwarf_attr_name (die
->attrs
[i
].name
),
21888 dwarf_form_name (die
->attrs
[i
].form
));
21890 switch (die
->attrs
[i
].form
)
21893 case DW_FORM_addrx
:
21894 case DW_FORM_GNU_addr_index
:
21895 fprintf_unfiltered (f
, "address: ");
21896 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21898 case DW_FORM_block2
:
21899 case DW_FORM_block4
:
21900 case DW_FORM_block
:
21901 case DW_FORM_block1
:
21902 fprintf_unfiltered (f
, "block: size %s",
21903 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21905 case DW_FORM_exprloc
:
21906 fprintf_unfiltered (f
, "expression: size %s",
21907 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21909 case DW_FORM_data16
:
21910 fprintf_unfiltered (f
, "constant of 16 bytes");
21912 case DW_FORM_ref_addr
:
21913 fprintf_unfiltered (f
, "ref address: ");
21914 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21916 case DW_FORM_GNU_ref_alt
:
21917 fprintf_unfiltered (f
, "alt ref address: ");
21918 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21924 case DW_FORM_ref_udata
:
21925 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21926 (long) (DW_UNSND (&die
->attrs
[i
])));
21928 case DW_FORM_data1
:
21929 case DW_FORM_data2
:
21930 case DW_FORM_data4
:
21931 case DW_FORM_data8
:
21932 case DW_FORM_udata
:
21933 case DW_FORM_sdata
:
21934 fprintf_unfiltered (f
, "constant: %s",
21935 pulongest (DW_UNSND (&die
->attrs
[i
])));
21937 case DW_FORM_sec_offset
:
21938 fprintf_unfiltered (f
, "section offset: %s",
21939 pulongest (DW_UNSND (&die
->attrs
[i
])));
21941 case DW_FORM_ref_sig8
:
21942 fprintf_unfiltered (f
, "signature: %s",
21943 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21945 case DW_FORM_string
:
21947 case DW_FORM_line_strp
:
21949 case DW_FORM_GNU_str_index
:
21950 case DW_FORM_GNU_strp_alt
:
21951 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21952 DW_STRING (&die
->attrs
[i
])
21953 ? DW_STRING (&die
->attrs
[i
]) : "",
21954 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21957 if (DW_UNSND (&die
->attrs
[i
]))
21958 fprintf_unfiltered (f
, "flag: TRUE");
21960 fprintf_unfiltered (f
, "flag: FALSE");
21962 case DW_FORM_flag_present
:
21963 fprintf_unfiltered (f
, "flag: TRUE");
21965 case DW_FORM_indirect
:
21966 /* The reader will have reduced the indirect form to
21967 the "base form" so this form should not occur. */
21968 fprintf_unfiltered (f
,
21969 "unexpected attribute form: DW_FORM_indirect");
21971 case DW_FORM_implicit_const
:
21972 fprintf_unfiltered (f
, "constant: %s",
21973 plongest (DW_SND (&die
->attrs
[i
])));
21976 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21977 die
->attrs
[i
].form
);
21980 fprintf_unfiltered (f
, "\n");
21985 dump_die_for_error (struct die_info
*die
)
21987 dump_die_shallow (gdb_stderr
, 0, die
);
21991 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21993 int indent
= level
* 4;
21995 gdb_assert (die
!= NULL
);
21997 if (level
>= max_level
)
22000 dump_die_shallow (f
, indent
, die
);
22002 if (die
->child
!= NULL
)
22004 print_spaces (indent
, f
);
22005 fprintf_unfiltered (f
, " Children:");
22006 if (level
+ 1 < max_level
)
22008 fprintf_unfiltered (f
, "\n");
22009 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22013 fprintf_unfiltered (f
,
22014 " [not printed, max nesting level reached]\n");
22018 if (die
->sibling
!= NULL
&& level
> 0)
22020 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22024 /* This is called from the pdie macro in gdbinit.in.
22025 It's not static so gcc will keep a copy callable from gdb. */
22028 dump_die (struct die_info
*die
, int max_level
)
22030 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22034 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22038 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22039 to_underlying (die
->sect_off
),
22045 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22049 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22051 if (attr
->form_is_ref ())
22052 return (sect_offset
) DW_UNSND (attr
);
22054 complaint (_("unsupported die ref attribute form: '%s'"),
22055 dwarf_form_name (attr
->form
));
22059 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22060 * the value held by the attribute is not constant. */
22063 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22065 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22066 return DW_SND (attr
);
22067 else if (attr
->form
== DW_FORM_udata
22068 || attr
->form
== DW_FORM_data1
22069 || attr
->form
== DW_FORM_data2
22070 || attr
->form
== DW_FORM_data4
22071 || attr
->form
== DW_FORM_data8
)
22072 return DW_UNSND (attr
);
22075 /* For DW_FORM_data16 see attribute::form_is_constant. */
22076 complaint (_("Attribute value is not a constant (%s)"),
22077 dwarf_form_name (attr
->form
));
22078 return default_value
;
22082 /* Follow reference or signature attribute ATTR of SRC_DIE.
22083 On entry *REF_CU is the CU of SRC_DIE.
22084 On exit *REF_CU is the CU of the result. */
22086 static struct die_info
*
22087 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22088 struct dwarf2_cu
**ref_cu
)
22090 struct die_info
*die
;
22092 if (attr
->form_is_ref ())
22093 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22094 else if (attr
->form
== DW_FORM_ref_sig8
)
22095 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22098 dump_die_for_error (src_die
);
22099 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22100 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22106 /* Follow reference OFFSET.
22107 On entry *REF_CU is the CU of the source die referencing OFFSET.
22108 On exit *REF_CU is the CU of the result.
22109 Returns NULL if OFFSET is invalid. */
22111 static struct die_info
*
22112 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22113 struct dwarf2_cu
**ref_cu
)
22115 struct die_info temp_die
;
22116 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22117 struct dwarf2_per_objfile
*dwarf2_per_objfile
22118 = cu
->per_cu
->dwarf2_per_objfile
;
22120 gdb_assert (cu
->per_cu
!= NULL
);
22124 if (cu
->per_cu
->is_debug_types
)
22126 /* .debug_types CUs cannot reference anything outside their CU.
22127 If they need to, they have to reference a signatured type via
22128 DW_FORM_ref_sig8. */
22129 if (!cu
->header
.offset_in_cu_p (sect_off
))
22132 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22133 || !cu
->header
.offset_in_cu_p (sect_off
))
22135 struct dwarf2_per_cu_data
*per_cu
;
22137 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22138 dwarf2_per_objfile
);
22140 /* If necessary, add it to the queue and load its DIEs. */
22141 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22142 load_full_comp_unit (per_cu
, false, cu
->language
);
22144 target_cu
= per_cu
->cu
;
22146 else if (cu
->dies
== NULL
)
22148 /* We're loading full DIEs during partial symbol reading. */
22149 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22150 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22153 *ref_cu
= target_cu
;
22154 temp_die
.sect_off
= sect_off
;
22156 if (target_cu
!= cu
)
22157 target_cu
->ancestor
= cu
;
22159 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22161 to_underlying (sect_off
));
22164 /* Follow reference attribute ATTR of SRC_DIE.
22165 On entry *REF_CU is the CU of SRC_DIE.
22166 On exit *REF_CU is the CU of the result. */
22168 static struct die_info
*
22169 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22170 struct dwarf2_cu
**ref_cu
)
22172 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22173 struct dwarf2_cu
*cu
= *ref_cu
;
22174 struct die_info
*die
;
22176 die
= follow_die_offset (sect_off
,
22177 (attr
->form
== DW_FORM_GNU_ref_alt
22178 || cu
->per_cu
->is_dwz
),
22181 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22182 "at %s [in module %s]"),
22183 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22184 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22191 struct dwarf2_locexpr_baton
22192 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22193 dwarf2_per_cu_data
*per_cu
,
22194 CORE_ADDR (*get_frame_pc
) (void *baton
),
22195 void *baton
, bool resolve_abstract_p
)
22197 struct dwarf2_cu
*cu
;
22198 struct die_info
*die
;
22199 struct attribute
*attr
;
22200 struct dwarf2_locexpr_baton retval
;
22201 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22202 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22204 if (per_cu
->cu
== NULL
)
22205 load_cu (per_cu
, false);
22209 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22210 Instead just throw an error, not much else we can do. */
22211 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22212 sect_offset_str (sect_off
), objfile_name (objfile
));
22215 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22217 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22218 sect_offset_str (sect_off
), objfile_name (objfile
));
22220 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22221 if (!attr
&& resolve_abstract_p
22222 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22223 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22225 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22226 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22227 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22229 for (const auto &cand_off
22230 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22232 struct dwarf2_cu
*cand_cu
= cu
;
22233 struct die_info
*cand
22234 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22237 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22240 CORE_ADDR pc_low
, pc_high
;
22241 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22242 if (pc_low
== ((CORE_ADDR
) -1))
22244 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22245 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22246 if (!(pc_low
<= pc
&& pc
< pc_high
))
22250 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22257 /* DWARF: "If there is no such attribute, then there is no effect.".
22258 DATA is ignored if SIZE is 0. */
22260 retval
.data
= NULL
;
22263 else if (attr
->form_is_section_offset ())
22265 struct dwarf2_loclist_baton loclist_baton
;
22266 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22269 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22271 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22273 retval
.size
= size
;
22277 if (!attr
->form_is_block ())
22278 error (_("Dwarf Error: DIE at %s referenced in module %s "
22279 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22280 sect_offset_str (sect_off
), objfile_name (objfile
));
22282 retval
.data
= DW_BLOCK (attr
)->data
;
22283 retval
.size
= DW_BLOCK (attr
)->size
;
22285 retval
.per_cu
= cu
->per_cu
;
22287 age_cached_comp_units (dwarf2_per_objfile
);
22294 struct dwarf2_locexpr_baton
22295 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22296 dwarf2_per_cu_data
*per_cu
,
22297 CORE_ADDR (*get_frame_pc
) (void *baton
),
22300 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22302 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22305 /* Write a constant of a given type as target-ordered bytes into
22308 static const gdb_byte
*
22309 write_constant_as_bytes (struct obstack
*obstack
,
22310 enum bfd_endian byte_order
,
22317 *len
= TYPE_LENGTH (type
);
22318 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22319 store_unsigned_integer (result
, *len
, byte_order
, value
);
22327 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22328 dwarf2_per_cu_data
*per_cu
,
22332 struct dwarf2_cu
*cu
;
22333 struct die_info
*die
;
22334 struct attribute
*attr
;
22335 const gdb_byte
*result
= NULL
;
22338 enum bfd_endian byte_order
;
22339 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22341 if (per_cu
->cu
== NULL
)
22342 load_cu (per_cu
, false);
22346 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22347 Instead just throw an error, not much else we can do. */
22348 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22349 sect_offset_str (sect_off
), objfile_name (objfile
));
22352 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22354 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22355 sect_offset_str (sect_off
), objfile_name (objfile
));
22357 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22361 byte_order
= (bfd_big_endian (objfile
->obfd
)
22362 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22364 switch (attr
->form
)
22367 case DW_FORM_addrx
:
22368 case DW_FORM_GNU_addr_index
:
22372 *len
= cu
->header
.addr_size
;
22373 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22374 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22378 case DW_FORM_string
:
22381 case DW_FORM_GNU_str_index
:
22382 case DW_FORM_GNU_strp_alt
:
22383 /* DW_STRING is already allocated on the objfile obstack, point
22385 result
= (const gdb_byte
*) DW_STRING (attr
);
22386 *len
= strlen (DW_STRING (attr
));
22388 case DW_FORM_block1
:
22389 case DW_FORM_block2
:
22390 case DW_FORM_block4
:
22391 case DW_FORM_block
:
22392 case DW_FORM_exprloc
:
22393 case DW_FORM_data16
:
22394 result
= DW_BLOCK (attr
)->data
;
22395 *len
= DW_BLOCK (attr
)->size
;
22398 /* The DW_AT_const_value attributes are supposed to carry the
22399 symbol's value "represented as it would be on the target
22400 architecture." By the time we get here, it's already been
22401 converted to host endianness, so we just need to sign- or
22402 zero-extend it as appropriate. */
22403 case DW_FORM_data1
:
22404 type
= die_type (die
, cu
);
22405 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22406 if (result
== NULL
)
22407 result
= write_constant_as_bytes (obstack
, byte_order
,
22410 case DW_FORM_data2
:
22411 type
= die_type (die
, cu
);
22412 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22413 if (result
== NULL
)
22414 result
= write_constant_as_bytes (obstack
, byte_order
,
22417 case DW_FORM_data4
:
22418 type
= die_type (die
, cu
);
22419 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22420 if (result
== NULL
)
22421 result
= write_constant_as_bytes (obstack
, byte_order
,
22424 case DW_FORM_data8
:
22425 type
= die_type (die
, cu
);
22426 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22427 if (result
== NULL
)
22428 result
= write_constant_as_bytes (obstack
, byte_order
,
22432 case DW_FORM_sdata
:
22433 case DW_FORM_implicit_const
:
22434 type
= die_type (die
, cu
);
22435 result
= write_constant_as_bytes (obstack
, byte_order
,
22436 type
, DW_SND (attr
), len
);
22439 case DW_FORM_udata
:
22440 type
= die_type (die
, cu
);
22441 result
= write_constant_as_bytes (obstack
, byte_order
,
22442 type
, DW_UNSND (attr
), len
);
22446 complaint (_("unsupported const value attribute form: '%s'"),
22447 dwarf_form_name (attr
->form
));
22457 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22458 dwarf2_per_cu_data
*per_cu
)
22460 struct dwarf2_cu
*cu
;
22461 struct die_info
*die
;
22463 if (per_cu
->cu
== NULL
)
22464 load_cu (per_cu
, false);
22469 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22473 return die_type (die
, cu
);
22479 dwarf2_get_die_type (cu_offset die_offset
,
22480 struct dwarf2_per_cu_data
*per_cu
)
22482 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22483 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22486 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22487 On entry *REF_CU is the CU of SRC_DIE.
22488 On exit *REF_CU is the CU of the result.
22489 Returns NULL if the referenced DIE isn't found. */
22491 static struct die_info
*
22492 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22493 struct dwarf2_cu
**ref_cu
)
22495 struct die_info temp_die
;
22496 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22497 struct die_info
*die
;
22499 /* While it might be nice to assert sig_type->type == NULL here,
22500 we can get here for DW_AT_imported_declaration where we need
22501 the DIE not the type. */
22503 /* If necessary, add it to the queue and load its DIEs. */
22505 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22506 read_signatured_type (sig_type
);
22508 sig_cu
= sig_type
->per_cu
.cu
;
22509 gdb_assert (sig_cu
!= NULL
);
22510 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22511 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22512 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22513 to_underlying (temp_die
.sect_off
));
22516 struct dwarf2_per_objfile
*dwarf2_per_objfile
22517 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22519 /* For .gdb_index version 7 keep track of included TUs.
22520 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22521 if (dwarf2_per_objfile
->index_table
!= NULL
22522 && dwarf2_per_objfile
->index_table
->version
<= 7)
22524 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22529 sig_cu
->ancestor
= cu
;
22537 /* Follow signatured type referenced by ATTR in SRC_DIE.
22538 On entry *REF_CU is the CU of SRC_DIE.
22539 On exit *REF_CU is the CU of the result.
22540 The result is the DIE of the type.
22541 If the referenced type cannot be found an error is thrown. */
22543 static struct die_info
*
22544 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22545 struct dwarf2_cu
**ref_cu
)
22547 ULONGEST signature
= DW_SIGNATURE (attr
);
22548 struct signatured_type
*sig_type
;
22549 struct die_info
*die
;
22551 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22553 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22554 /* sig_type will be NULL if the signatured type is missing from
22556 if (sig_type
== NULL
)
22558 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22559 " from DIE at %s [in module %s]"),
22560 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22561 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22564 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22567 dump_die_for_error (src_die
);
22568 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22569 " from DIE at %s [in module %s]"),
22570 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22571 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22577 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22578 reading in and processing the type unit if necessary. */
22580 static struct type
*
22581 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22582 struct dwarf2_cu
*cu
)
22584 struct dwarf2_per_objfile
*dwarf2_per_objfile
22585 = cu
->per_cu
->dwarf2_per_objfile
;
22586 struct signatured_type
*sig_type
;
22587 struct dwarf2_cu
*type_cu
;
22588 struct die_info
*type_die
;
22591 sig_type
= lookup_signatured_type (cu
, signature
);
22592 /* sig_type will be NULL if the signatured type is missing from
22594 if (sig_type
== NULL
)
22596 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22597 " from DIE at %s [in module %s]"),
22598 hex_string (signature
), sect_offset_str (die
->sect_off
),
22599 objfile_name (dwarf2_per_objfile
->objfile
));
22600 return build_error_marker_type (cu
, die
);
22603 /* If we already know the type we're done. */
22604 if (sig_type
->type
!= NULL
)
22605 return sig_type
->type
;
22608 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22609 if (type_die
!= NULL
)
22611 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22612 is created. This is important, for example, because for c++ classes
22613 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22614 type
= read_type_die (type_die
, type_cu
);
22617 complaint (_("Dwarf Error: Cannot build signatured type %s"
22618 " referenced from DIE at %s [in module %s]"),
22619 hex_string (signature
), sect_offset_str (die
->sect_off
),
22620 objfile_name (dwarf2_per_objfile
->objfile
));
22621 type
= build_error_marker_type (cu
, die
);
22626 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22627 " from DIE at %s [in module %s]"),
22628 hex_string (signature
), sect_offset_str (die
->sect_off
),
22629 objfile_name (dwarf2_per_objfile
->objfile
));
22630 type
= build_error_marker_type (cu
, die
);
22632 sig_type
->type
= type
;
22637 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22638 reading in and processing the type unit if necessary. */
22640 static struct type
*
22641 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22642 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22644 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22645 if (attr
->form_is_ref ())
22647 struct dwarf2_cu
*type_cu
= cu
;
22648 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22650 return read_type_die (type_die
, type_cu
);
22652 else if (attr
->form
== DW_FORM_ref_sig8
)
22654 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22658 struct dwarf2_per_objfile
*dwarf2_per_objfile
22659 = cu
->per_cu
->dwarf2_per_objfile
;
22661 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22662 " at %s [in module %s]"),
22663 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22664 objfile_name (dwarf2_per_objfile
->objfile
));
22665 return build_error_marker_type (cu
, die
);
22669 /* Load the DIEs associated with type unit PER_CU into memory. */
22672 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22674 struct signatured_type
*sig_type
;
22676 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22677 gdb_assert (! per_cu
->type_unit_group_p ());
22679 /* We have the per_cu, but we need the signatured_type.
22680 Fortunately this is an easy translation. */
22681 gdb_assert (per_cu
->is_debug_types
);
22682 sig_type
= (struct signatured_type
*) per_cu
;
22684 gdb_assert (per_cu
->cu
== NULL
);
22686 read_signatured_type (sig_type
);
22688 gdb_assert (per_cu
->cu
!= NULL
);
22691 /* Read in a signatured type and build its CU and DIEs.
22692 If the type is a stub for the real type in a DWO file,
22693 read in the real type from the DWO file as well. */
22696 read_signatured_type (struct signatured_type
*sig_type
)
22698 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22700 gdb_assert (per_cu
->is_debug_types
);
22701 gdb_assert (per_cu
->cu
== NULL
);
22703 cutu_reader
reader (per_cu
, NULL
, 0, false);
22705 if (!reader
.dummy_p
)
22707 struct dwarf2_cu
*cu
= reader
.cu
;
22708 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22710 gdb_assert (cu
->die_hash
== NULL
);
22712 htab_create_alloc_ex (cu
->header
.length
/ 12,
22716 &cu
->comp_unit_obstack
,
22717 hashtab_obstack_allocate
,
22718 dummy_obstack_deallocate
);
22720 if (reader
.comp_unit_die
->has_children
)
22721 reader
.comp_unit_die
->child
22722 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22723 reader
.comp_unit_die
);
22724 cu
->dies
= reader
.comp_unit_die
;
22725 /* comp_unit_die is not stored in die_hash, no need. */
22727 /* We try not to read any attributes in this function, because
22728 not all CUs needed for references have been loaded yet, and
22729 symbol table processing isn't initialized. But we have to
22730 set the CU language, or we won't be able to build types
22731 correctly. Similarly, if we do not read the producer, we can
22732 not apply producer-specific interpretation. */
22733 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22738 sig_type
->per_cu
.tu_read
= 1;
22741 /* Decode simple location descriptions.
22742 Given a pointer to a dwarf block that defines a location, compute
22743 the location and return the value.
22745 NOTE drow/2003-11-18: This function is called in two situations
22746 now: for the address of static or global variables (partial symbols
22747 only) and for offsets into structures which are expected to be
22748 (more or less) constant. The partial symbol case should go away,
22749 and only the constant case should remain. That will let this
22750 function complain more accurately. A few special modes are allowed
22751 without complaint for global variables (for instance, global
22752 register values and thread-local values).
22754 A location description containing no operations indicates that the
22755 object is optimized out. The return value is 0 for that case.
22756 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22757 callers will only want a very basic result and this can become a
22760 Note that stack[0] is unused except as a default error return. */
22763 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22765 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22767 size_t size
= blk
->size
;
22768 const gdb_byte
*data
= blk
->data
;
22769 CORE_ADDR stack
[64];
22771 unsigned int bytes_read
, unsnd
;
22777 stack
[++stacki
] = 0;
22816 stack
[++stacki
] = op
- DW_OP_lit0
;
22851 stack
[++stacki
] = op
- DW_OP_reg0
;
22853 dwarf2_complex_location_expr_complaint ();
22857 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22859 stack
[++stacki
] = unsnd
;
22861 dwarf2_complex_location_expr_complaint ();
22865 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22870 case DW_OP_const1u
:
22871 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22875 case DW_OP_const1s
:
22876 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22880 case DW_OP_const2u
:
22881 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22885 case DW_OP_const2s
:
22886 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22890 case DW_OP_const4u
:
22891 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22895 case DW_OP_const4s
:
22896 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22900 case DW_OP_const8u
:
22901 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22906 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22912 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22917 stack
[stacki
+ 1] = stack
[stacki
];
22922 stack
[stacki
- 1] += stack
[stacki
];
22926 case DW_OP_plus_uconst
:
22927 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22933 stack
[stacki
- 1] -= stack
[stacki
];
22938 /* If we're not the last op, then we definitely can't encode
22939 this using GDB's address_class enum. This is valid for partial
22940 global symbols, although the variable's address will be bogus
22943 dwarf2_complex_location_expr_complaint ();
22946 case DW_OP_GNU_push_tls_address
:
22947 case DW_OP_form_tls_address
:
22948 /* The top of the stack has the offset from the beginning
22949 of the thread control block at which the variable is located. */
22950 /* Nothing should follow this operator, so the top of stack would
22952 /* This is valid for partial global symbols, but the variable's
22953 address will be bogus in the psymtab. Make it always at least
22954 non-zero to not look as a variable garbage collected by linker
22955 which have DW_OP_addr 0. */
22957 dwarf2_complex_location_expr_complaint ();
22961 case DW_OP_GNU_uninit
:
22965 case DW_OP_GNU_addr_index
:
22966 case DW_OP_GNU_const_index
:
22967 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22974 const char *name
= get_DW_OP_name (op
);
22977 complaint (_("unsupported stack op: '%s'"),
22980 complaint (_("unsupported stack op: '%02x'"),
22984 return (stack
[stacki
]);
22987 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22988 outside of the allocated space. Also enforce minimum>0. */
22989 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22991 complaint (_("location description stack overflow"));
22997 complaint (_("location description stack underflow"));
23001 return (stack
[stacki
]);
23004 /* memory allocation interface */
23006 static struct dwarf_block
*
23007 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23009 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23012 static struct die_info
*
23013 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23015 struct die_info
*die
;
23016 size_t size
= sizeof (struct die_info
);
23019 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23021 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23022 memset (die
, 0, sizeof (struct die_info
));
23028 /* Macro support. */
23030 /* An overload of dwarf_decode_macros that finds the correct section
23031 and ensures it is read in before calling the other overload. */
23034 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23035 int section_is_gnu
)
23037 struct dwarf2_per_objfile
*dwarf2_per_objfile
23038 = cu
->per_cu
->dwarf2_per_objfile
;
23039 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23040 const struct line_header
*lh
= cu
->line_header
;
23041 unsigned int offset_size
= cu
->header
.offset_size
;
23042 struct dwarf2_section_info
*section
;
23043 const char *section_name
;
23045 if (cu
->dwo_unit
!= nullptr)
23047 if (section_is_gnu
)
23049 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23050 section_name
= ".debug_macro.dwo";
23054 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23055 section_name
= ".debug_macinfo.dwo";
23060 if (section_is_gnu
)
23062 section
= &dwarf2_per_objfile
->macro
;
23063 section_name
= ".debug_macro";
23067 section
= &dwarf2_per_objfile
->macinfo
;
23068 section_name
= ".debug_macinfo";
23072 section
->read (objfile
);
23073 if (section
->buffer
== nullptr)
23075 complaint (_("missing %s section"), section_name
);
23079 buildsym_compunit
*builder
= cu
->get_builder ();
23081 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23082 offset_size
, offset
, section_is_gnu
);
23085 /* Return the .debug_loc section to use for CU.
23086 For DWO files use .debug_loc.dwo. */
23088 static struct dwarf2_section_info
*
23089 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23091 struct dwarf2_per_objfile
*dwarf2_per_objfile
23092 = cu
->per_cu
->dwarf2_per_objfile
;
23096 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23098 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23100 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23101 : &dwarf2_per_objfile
->loc
);
23104 /* A helper function that fills in a dwarf2_loclist_baton. */
23107 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23108 struct dwarf2_loclist_baton
*baton
,
23109 const struct attribute
*attr
)
23111 struct dwarf2_per_objfile
*dwarf2_per_objfile
23112 = cu
->per_cu
->dwarf2_per_objfile
;
23113 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23115 section
->read (dwarf2_per_objfile
->objfile
);
23117 baton
->per_cu
= cu
->per_cu
;
23118 gdb_assert (baton
->per_cu
);
23119 /* We don't know how long the location list is, but make sure we
23120 don't run off the edge of the section. */
23121 baton
->size
= section
->size
- DW_UNSND (attr
);
23122 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23123 baton
->base_address
= cu
->base_address
;
23124 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23128 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23129 struct dwarf2_cu
*cu
, int is_block
)
23131 struct dwarf2_per_objfile
*dwarf2_per_objfile
23132 = cu
->per_cu
->dwarf2_per_objfile
;
23133 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23134 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23136 if (attr
->form_is_section_offset ()
23137 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23138 the section. If so, fall through to the complaint in the
23140 && DW_UNSND (attr
) < section
->get_size (objfile
))
23142 struct dwarf2_loclist_baton
*baton
;
23144 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23146 fill_in_loclist_baton (cu
, baton
, attr
);
23148 if (cu
->base_known
== 0)
23149 complaint (_("Location list used without "
23150 "specifying the CU base address."));
23152 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23153 ? dwarf2_loclist_block_index
23154 : dwarf2_loclist_index
);
23155 SYMBOL_LOCATION_BATON (sym
) = baton
;
23159 struct dwarf2_locexpr_baton
*baton
;
23161 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23162 baton
->per_cu
= cu
->per_cu
;
23163 gdb_assert (baton
->per_cu
);
23165 if (attr
->form_is_block ())
23167 /* Note that we're just copying the block's data pointer
23168 here, not the actual data. We're still pointing into the
23169 info_buffer for SYM's objfile; right now we never release
23170 that buffer, but when we do clean up properly this may
23172 baton
->size
= DW_BLOCK (attr
)->size
;
23173 baton
->data
= DW_BLOCK (attr
)->data
;
23177 dwarf2_invalid_attrib_class_complaint ("location description",
23178 sym
->natural_name ());
23182 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23183 ? dwarf2_locexpr_block_index
23184 : dwarf2_locexpr_index
);
23185 SYMBOL_LOCATION_BATON (sym
) = baton
;
23192 dwarf2_per_cu_data::objfile () const
23194 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23196 /* Return the master objfile, so that we can report and look up the
23197 correct file containing this variable. */
23198 if (objfile
->separate_debug_objfile_backlink
)
23199 objfile
= objfile
->separate_debug_objfile_backlink
;
23204 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23205 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23206 CU_HEADERP first. */
23208 static const struct comp_unit_head
*
23209 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23210 const struct dwarf2_per_cu_data
*per_cu
)
23212 const gdb_byte
*info_ptr
;
23215 return &per_cu
->cu
->header
;
23217 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23219 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23220 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23221 rcuh_kind::COMPILE
);
23229 dwarf2_per_cu_data::addr_size () const
23231 struct comp_unit_head cu_header_local
;
23232 const struct comp_unit_head
*cu_headerp
;
23234 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23236 return cu_headerp
->addr_size
;
23242 dwarf2_per_cu_data::offset_size () const
23244 struct comp_unit_head cu_header_local
;
23245 const struct comp_unit_head
*cu_headerp
;
23247 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23249 return cu_headerp
->offset_size
;
23255 dwarf2_per_cu_data::ref_addr_size () const
23257 struct comp_unit_head cu_header_local
;
23258 const struct comp_unit_head
*cu_headerp
;
23260 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23262 if (cu_headerp
->version
== 2)
23263 return cu_headerp
->addr_size
;
23265 return cu_headerp
->offset_size
;
23271 dwarf2_per_cu_data::text_offset () const
23273 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23275 return objfile
->text_section_offset ();
23281 dwarf2_per_cu_data::addr_type () const
23283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23284 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23285 struct type
*addr_type
= lookup_pointer_type (void_type
);
23286 int addr_size
= this->addr_size ();
23288 if (TYPE_LENGTH (addr_type
) == addr_size
)
23291 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23295 /* A helper function for dwarf2_find_containing_comp_unit that returns
23296 the index of the result, and that searches a vector. It will
23297 return a result even if the offset in question does not actually
23298 occur in any CU. This is separate so that it can be unit
23302 dwarf2_find_containing_comp_unit
23303 (sect_offset sect_off
,
23304 unsigned int offset_in_dwz
,
23305 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23310 high
= all_comp_units
.size () - 1;
23313 struct dwarf2_per_cu_data
*mid_cu
;
23314 int mid
= low
+ (high
- low
) / 2;
23316 mid_cu
= all_comp_units
[mid
];
23317 if (mid_cu
->is_dwz
> offset_in_dwz
23318 || (mid_cu
->is_dwz
== offset_in_dwz
23319 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23324 gdb_assert (low
== high
);
23328 /* Locate the .debug_info compilation unit from CU's objfile which contains
23329 the DIE at OFFSET. Raises an error on failure. */
23331 static struct dwarf2_per_cu_data
*
23332 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23333 unsigned int offset_in_dwz
,
23334 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23337 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23338 dwarf2_per_objfile
->all_comp_units
);
23339 struct dwarf2_per_cu_data
*this_cu
23340 = dwarf2_per_objfile
->all_comp_units
[low
];
23342 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23344 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23345 error (_("Dwarf Error: could not find partial DIE containing "
23346 "offset %s [in module %s]"),
23347 sect_offset_str (sect_off
),
23348 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23350 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23352 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23356 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
23357 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23358 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23359 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23366 namespace selftests
{
23367 namespace find_containing_comp_unit
{
23372 struct dwarf2_per_cu_data one
{};
23373 struct dwarf2_per_cu_data two
{};
23374 struct dwarf2_per_cu_data three
{};
23375 struct dwarf2_per_cu_data four
{};
23378 two
.sect_off
= sect_offset (one
.length
);
23383 four
.sect_off
= sect_offset (three
.length
);
23387 std::vector
<dwarf2_per_cu_data
*> units
;
23388 units
.push_back (&one
);
23389 units
.push_back (&two
);
23390 units
.push_back (&three
);
23391 units
.push_back (&four
);
23395 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23396 SELF_CHECK (units
[result
] == &one
);
23397 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23398 SELF_CHECK (units
[result
] == &one
);
23399 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23400 SELF_CHECK (units
[result
] == &two
);
23402 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23403 SELF_CHECK (units
[result
] == &three
);
23404 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23405 SELF_CHECK (units
[result
] == &three
);
23406 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23407 SELF_CHECK (units
[result
] == &four
);
23413 #endif /* GDB_SELF_TEST */
23415 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23417 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23418 : per_cu (per_cu_
),
23420 has_loclist (false),
23421 checked_producer (false),
23422 producer_is_gxx_lt_4_6 (false),
23423 producer_is_gcc_lt_4_3 (false),
23424 producer_is_icc (false),
23425 producer_is_icc_lt_14 (false),
23426 producer_is_codewarrior (false),
23427 processing_has_namespace_info (false)
23432 /* Destroy a dwarf2_cu. */
23434 dwarf2_cu::~dwarf2_cu ()
23439 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23442 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23443 enum language pretend_language
)
23445 struct attribute
*attr
;
23447 /* Set the language we're debugging. */
23448 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23449 if (attr
!= nullptr)
23450 set_cu_language (DW_UNSND (attr
), cu
);
23453 cu
->language
= pretend_language
;
23454 cu
->language_defn
= language_def (cu
->language
);
23457 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23460 /* Increase the age counter on each cached compilation unit, and free
23461 any that are too old. */
23464 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23466 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23468 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23469 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23470 while (per_cu
!= NULL
)
23472 per_cu
->cu
->last_used
++;
23473 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23474 dwarf2_mark (per_cu
->cu
);
23475 per_cu
= per_cu
->cu
->read_in_chain
;
23478 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23479 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23480 while (per_cu
!= NULL
)
23482 struct dwarf2_per_cu_data
*next_cu
;
23484 next_cu
= per_cu
->cu
->read_in_chain
;
23486 if (!per_cu
->cu
->mark
)
23489 *last_chain
= next_cu
;
23492 last_chain
= &per_cu
->cu
->read_in_chain
;
23498 /* Remove a single compilation unit from the cache. */
23501 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23503 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23504 struct dwarf2_per_objfile
*dwarf2_per_objfile
23505 = target_per_cu
->dwarf2_per_objfile
;
23507 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23508 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23509 while (per_cu
!= NULL
)
23511 struct dwarf2_per_cu_data
*next_cu
;
23513 next_cu
= per_cu
->cu
->read_in_chain
;
23515 if (per_cu
== target_per_cu
)
23519 *last_chain
= next_cu
;
23523 last_chain
= &per_cu
->cu
->read_in_chain
;
23529 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23530 We store these in a hash table separate from the DIEs, and preserve them
23531 when the DIEs are flushed out of cache.
23533 The CU "per_cu" pointer is needed because offset alone is not enough to
23534 uniquely identify the type. A file may have multiple .debug_types sections,
23535 or the type may come from a DWO file. Furthermore, while it's more logical
23536 to use per_cu->section+offset, with Fission the section with the data is in
23537 the DWO file but we don't know that section at the point we need it.
23538 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23539 because we can enter the lookup routine, get_die_type_at_offset, from
23540 outside this file, and thus won't necessarily have PER_CU->cu.
23541 Fortunately, PER_CU is stable for the life of the objfile. */
23543 struct dwarf2_per_cu_offset_and_type
23545 const struct dwarf2_per_cu_data
*per_cu
;
23546 sect_offset sect_off
;
23550 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23553 per_cu_offset_and_type_hash (const void *item
)
23555 const struct dwarf2_per_cu_offset_and_type
*ofs
23556 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23558 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23561 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23564 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23566 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23567 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23568 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23569 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23571 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23572 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23575 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23576 table if necessary. For convenience, return TYPE.
23578 The DIEs reading must have careful ordering to:
23579 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23580 reading current DIE.
23581 * Not trying to dereference contents of still incompletely read in types
23582 while reading in other DIEs.
23583 * Enable referencing still incompletely read in types just by a pointer to
23584 the type without accessing its fields.
23586 Therefore caller should follow these rules:
23587 * Try to fetch any prerequisite types we may need to build this DIE type
23588 before building the type and calling set_die_type.
23589 * After building type call set_die_type for current DIE as soon as
23590 possible before fetching more types to complete the current type.
23591 * Make the type as complete as possible before fetching more types. */
23593 static struct type
*
23594 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23596 struct dwarf2_per_objfile
*dwarf2_per_objfile
23597 = cu
->per_cu
->dwarf2_per_objfile
;
23598 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23599 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23600 struct attribute
*attr
;
23601 struct dynamic_prop prop
;
23603 /* For Ada types, make sure that the gnat-specific data is always
23604 initialized (if not already set). There are a few types where
23605 we should not be doing so, because the type-specific area is
23606 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23607 where the type-specific area is used to store the floatformat).
23608 But this is not a problem, because the gnat-specific information
23609 is actually not needed for these types. */
23610 if (need_gnat_info (cu
)
23611 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23612 && TYPE_CODE (type
) != TYPE_CODE_FLT
23613 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23614 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23615 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23616 && !HAVE_GNAT_AUX_INFO (type
))
23617 INIT_GNAT_SPECIFIC (type
);
23619 /* Read DW_AT_allocated and set in type. */
23620 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23621 if (attr
!= NULL
&& attr
->form_is_block ())
23623 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23624 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23625 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23627 else if (attr
!= NULL
)
23629 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23630 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23631 sect_offset_str (die
->sect_off
));
23634 /* Read DW_AT_associated and set in type. */
23635 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23636 if (attr
!= NULL
&& attr
->form_is_block ())
23638 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23639 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23640 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23642 else if (attr
!= NULL
)
23644 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23645 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23646 sect_offset_str (die
->sect_off
));
23649 /* Read DW_AT_data_location and set in type. */
23650 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23651 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23652 cu
->per_cu
->addr_type ()))
23653 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23655 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23656 dwarf2_per_objfile
->die_type_hash
23657 = htab_up (htab_create_alloc (127,
23658 per_cu_offset_and_type_hash
,
23659 per_cu_offset_and_type_eq
,
23660 NULL
, xcalloc
, xfree
));
23662 ofs
.per_cu
= cu
->per_cu
;
23663 ofs
.sect_off
= die
->sect_off
;
23665 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23666 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23668 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23669 sect_offset_str (die
->sect_off
));
23670 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23671 struct dwarf2_per_cu_offset_and_type
);
23676 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23677 or return NULL if the die does not have a saved type. */
23679 static struct type
*
23680 get_die_type_at_offset (sect_offset sect_off
,
23681 struct dwarf2_per_cu_data
*per_cu
)
23683 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23684 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23686 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23689 ofs
.per_cu
= per_cu
;
23690 ofs
.sect_off
= sect_off
;
23691 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23692 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23699 /* Look up the type for DIE in CU in die_type_hash,
23700 or return NULL if DIE does not have a saved type. */
23702 static struct type
*
23703 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23705 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23708 /* Add a dependence relationship from CU to REF_PER_CU. */
23711 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23712 struct dwarf2_per_cu_data
*ref_per_cu
)
23716 if (cu
->dependencies
== NULL
)
23718 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23719 NULL
, &cu
->comp_unit_obstack
,
23720 hashtab_obstack_allocate
,
23721 dummy_obstack_deallocate
);
23723 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23725 *slot
= ref_per_cu
;
23728 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23729 Set the mark field in every compilation unit in the
23730 cache that we must keep because we are keeping CU. */
23733 dwarf2_mark_helper (void **slot
, void *data
)
23735 struct dwarf2_per_cu_data
*per_cu
;
23737 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23739 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23740 reading of the chain. As such dependencies remain valid it is not much
23741 useful to track and undo them during QUIT cleanups. */
23742 if (per_cu
->cu
== NULL
)
23745 if (per_cu
->cu
->mark
)
23747 per_cu
->cu
->mark
= true;
23749 if (per_cu
->cu
->dependencies
!= NULL
)
23750 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23755 /* Set the mark field in CU and in every other compilation unit in the
23756 cache that we must keep because we are keeping CU. */
23759 dwarf2_mark (struct dwarf2_cu
*cu
)
23764 if (cu
->dependencies
!= NULL
)
23765 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23769 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23773 per_cu
->cu
->mark
= false;
23774 per_cu
= per_cu
->cu
->read_in_chain
;
23778 /* Trivial hash function for partial_die_info: the hash value of a DIE
23779 is its offset in .debug_info for this objfile. */
23782 partial_die_hash (const void *item
)
23784 const struct partial_die_info
*part_die
23785 = (const struct partial_die_info
*) item
;
23787 return to_underlying (part_die
->sect_off
);
23790 /* Trivial comparison function for partial_die_info structures: two DIEs
23791 are equal if they have the same offset. */
23794 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23796 const struct partial_die_info
*part_die_lhs
23797 = (const struct partial_die_info
*) item_lhs
;
23798 const struct partial_die_info
*part_die_rhs
23799 = (const struct partial_die_info
*) item_rhs
;
23801 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23804 struct cmd_list_element
*set_dwarf_cmdlist
;
23805 struct cmd_list_element
*show_dwarf_cmdlist
;
23808 set_dwarf_cmd (const char *args
, int from_tty
)
23810 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23815 show_dwarf_cmd (const char *args
, int from_tty
)
23817 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23821 show_check_physname (struct ui_file
*file
, int from_tty
,
23822 struct cmd_list_element
*c
, const char *value
)
23824 fprintf_filtered (file
,
23825 _("Whether to check \"physname\" is %s.\n"),
23829 void _initialize_dwarf2_read ();
23831 _initialize_dwarf2_read ()
23833 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23834 Set DWARF specific variables.\n\
23835 Configure DWARF variables such as the cache size."),
23836 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23837 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23839 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23840 Show DWARF specific variables.\n\
23841 Show DWARF variables such as the cache size."),
23842 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23843 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23845 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23846 &dwarf_max_cache_age
, _("\
23847 Set the upper bound on the age of cached DWARF compilation units."), _("\
23848 Show the upper bound on the age of cached DWARF compilation units."), _("\
23849 A higher limit means that cached compilation units will be stored\n\
23850 in memory longer, and more total memory will be used. Zero disables\n\
23851 caching, which can slow down startup."),
23853 show_dwarf_max_cache_age
,
23854 &set_dwarf_cmdlist
,
23855 &show_dwarf_cmdlist
);
23857 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23858 Set debugging of the DWARF reader."), _("\
23859 Show debugging of the DWARF reader."), _("\
23860 When enabled (non-zero), debugging messages are printed during DWARF\n\
23861 reading and symtab expansion. A value of 1 (one) provides basic\n\
23862 information. A value greater than 1 provides more verbose information."),
23865 &setdebuglist
, &showdebuglist
);
23867 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23868 Set debugging of the DWARF DIE reader."), _("\
23869 Show debugging of the DWARF DIE reader."), _("\
23870 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23871 The value is the maximum depth to print."),
23874 &setdebuglist
, &showdebuglist
);
23876 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23877 Set debugging of the dwarf line reader."), _("\
23878 Show debugging of the dwarf line reader."), _("\
23879 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23880 A value of 1 (one) provides basic information.\n\
23881 A value greater than 1 provides more verbose information."),
23884 &setdebuglist
, &showdebuglist
);
23886 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23887 Set cross-checking of \"physname\" code against demangler."), _("\
23888 Show cross-checking of \"physname\" code against demangler."), _("\
23889 When enabled, GDB's internal \"physname\" code is checked against\n\
23891 NULL
, show_check_physname
,
23892 &setdebuglist
, &showdebuglist
);
23894 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23895 no_class
, &use_deprecated_index_sections
, _("\
23896 Set whether to use deprecated gdb_index sections."), _("\
23897 Show whether to use deprecated gdb_index sections."), _("\
23898 When enabled, deprecated .gdb_index sections are used anyway.\n\
23899 Normally they are ignored either because of a missing feature or\n\
23900 performance issue.\n\
23901 Warning: This option must be enabled before gdb reads the file."),
23904 &setlist
, &showlist
);
23906 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23907 &dwarf2_locexpr_funcs
);
23908 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23909 &dwarf2_loclist_funcs
);
23911 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23912 &dwarf2_block_frame_base_locexpr_funcs
);
23913 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23914 &dwarf2_block_frame_base_loclist_funcs
);
23917 selftests::register_test ("dw2_expand_symtabs_matching",
23918 selftests::dw2_expand_symtabs_matching::run_test
);
23919 selftests::register_test ("dwarf2_find_containing_comp_unit",
23920 selftests::find_containing_comp_unit::run_test
);