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"
49 #include "gdb-demangle.h"
50 #include "filenames.h" /* for DOSish file names */
53 #include "complaints.h"
54 #include "dwarf2/expr.h"
55 #include "dwarf2/loc.h"
56 #include "cp-support.h"
62 #include "typeprint.h"
67 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb/gdb-index.h"
73 #include "namespace.h"
74 #include "gdbsupport/function-view.h"
75 #include "gdbsupport/gdb_optional.h"
76 #include "gdbsupport/underlying.h"
77 #include "gdbsupport/hash_enum.h"
78 #include "filename-seen-cache.h"
82 #include <unordered_map>
83 #include "gdbsupport/selftest.h"
84 #include "rust-lang.h"
85 #include "gdbsupport/pathstuff.h"
86 #include "count-one-bits.h"
87 #include "debuginfod-support.h"
89 /* When == 1, print basic high level tracing messages.
90 When > 1, be more verbose.
91 This is in contrast to the low level DIE reading of dwarf_die_debug. */
92 static unsigned int dwarf_read_debug
= 0;
94 /* When non-zero, dump DIEs after they are read in. */
95 static unsigned int dwarf_die_debug
= 0;
97 /* When non-zero, dump line number entries as they are read in. */
98 unsigned int dwarf_line_debug
= 0;
100 /* When true, cross-check physname against demangler. */
101 static bool check_physname
= false;
103 /* When true, do not reject deprecated .gdb_index sections. */
104 static bool use_deprecated_index_sections
= false;
106 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
108 /* The "aclass" indices for various kinds of computed DWARF symbols. */
110 static int dwarf2_locexpr_index
;
111 static int dwarf2_loclist_index
;
112 static int dwarf2_locexpr_block_index
;
113 static int dwarf2_loclist_block_index
;
115 /* An index into a (C++) symbol name component in a symbol name as
116 recorded in the mapped_index's symbol table. For each C++ symbol
117 in the symbol table, we record one entry for the start of each
118 component in the symbol in a table of name components, and then
119 sort the table, in order to be able to binary search symbol names,
120 ignoring leading namespaces, both completion and regular look up.
121 For example, for symbol "A::B::C", we'll have an entry that points
122 to "A::B::C", another that points to "B::C", and another for "C".
123 Note that function symbols in GDB index have no parameter
124 information, just the function/method names. You can convert a
125 name_component to a "const char *" using the
126 'mapped_index::symbol_name_at(offset_type)' method. */
128 struct name_component
130 /* Offset in the symbol name where the component starts. Stored as
131 a (32-bit) offset instead of a pointer to save memory and improve
132 locality on 64-bit architectures. */
133 offset_type name_offset
;
135 /* The symbol's index in the symbol and constant pool tables of a
140 /* Base class containing bits shared by both .gdb_index and
141 .debug_name indexes. */
143 struct mapped_index_base
145 mapped_index_base () = default;
146 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
148 /* The name_component table (a sorted vector). See name_component's
149 description above. */
150 std::vector
<name_component
> name_components
;
152 /* How NAME_COMPONENTS is sorted. */
153 enum case_sensitivity name_components_casing
;
155 /* Return the number of names in the symbol table. */
156 virtual size_t symbol_name_count () const = 0;
158 /* Get the name of the symbol at IDX in the symbol table. */
159 virtual const char *symbol_name_at (offset_type idx
) const = 0;
161 /* Return whether the name at IDX in the symbol table should be
163 virtual bool symbol_name_slot_invalid (offset_type idx
) const
168 /* Build the symbol name component sorted vector, if we haven't
170 void build_name_components ();
172 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
173 possible matches for LN_NO_PARAMS in the name component
175 std::pair
<std::vector
<name_component
>::const_iterator
,
176 std::vector
<name_component
>::const_iterator
>
177 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
178 enum language lang
) const;
180 /* Prevent deleting/destroying via a base class pointer. */
182 ~mapped_index_base() = default;
185 /* A description of the mapped index. The file format is described in
186 a comment by the code that writes the index. */
187 struct mapped_index final
: public mapped_index_base
189 /* A slot/bucket in the symbol table hash. */
190 struct symbol_table_slot
192 const offset_type name
;
193 const offset_type vec
;
196 /* Index data format version. */
199 /* The address table data. */
200 gdb::array_view
<const gdb_byte
> address_table
;
202 /* The symbol table, implemented as a hash table. */
203 gdb::array_view
<symbol_table_slot
> symbol_table
;
205 /* A pointer to the constant pool. */
206 const char *constant_pool
= nullptr;
208 bool symbol_name_slot_invalid (offset_type idx
) const override
210 const auto &bucket
= this->symbol_table
[idx
];
211 return bucket
.name
== 0 && bucket
.vec
== 0;
214 /* Convenience method to get at the name of the symbol at IDX in the
216 const char *symbol_name_at (offset_type idx
) const override
217 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
219 size_t symbol_name_count () const override
220 { return this->symbol_table
.size (); }
223 /* A description of the mapped .debug_names.
224 Uninitialized map has CU_COUNT 0. */
225 struct mapped_debug_names final
: public mapped_index_base
227 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
228 : dwarf2_per_objfile (dwarf2_per_objfile_
)
231 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
232 bfd_endian dwarf5_byte_order
;
233 bool dwarf5_is_dwarf64
;
234 bool augmentation_is_gdb
;
236 uint32_t cu_count
= 0;
237 uint32_t tu_count
, bucket_count
, name_count
;
238 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
239 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
240 const gdb_byte
*name_table_string_offs_reordered
;
241 const gdb_byte
*name_table_entry_offs_reordered
;
242 const gdb_byte
*entry_pool
;
249 /* Attribute name DW_IDX_*. */
252 /* Attribute form DW_FORM_*. */
255 /* Value if FORM is DW_FORM_implicit_const. */
256 LONGEST implicit_const
;
258 std::vector
<attr
> attr_vec
;
261 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
263 const char *namei_to_name (uint32_t namei
) const;
265 /* Implementation of the mapped_index_base virtual interface, for
266 the name_components cache. */
268 const char *symbol_name_at (offset_type idx
) const override
269 { return namei_to_name (idx
); }
271 size_t symbol_name_count () const override
272 { return this->name_count
; }
275 /* See dwarf2read.h. */
278 get_dwarf2_per_objfile (struct objfile
*objfile
)
280 return dwarf2_objfile_data_key
.get (objfile
);
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_loclists", ".zdebug_loclists" },
295 { ".debug_macinfo", ".zdebug_macinfo" },
296 { ".debug_macro", ".zdebug_macro" },
297 { ".debug_str", ".zdebug_str" },
298 { ".debug_str_offsets", ".zdebug_str_offsets" },
299 { ".debug_line_str", ".zdebug_line_str" },
300 { ".debug_ranges", ".zdebug_ranges" },
301 { ".debug_rnglists", ".zdebug_rnglists" },
302 { ".debug_types", ".zdebug_types" },
303 { ".debug_addr", ".zdebug_addr" },
304 { ".debug_frame", ".zdebug_frame" },
305 { ".eh_frame", NULL
},
306 { ".gdb_index", ".zgdb_index" },
307 { ".debug_names", ".zdebug_names" },
308 { ".debug_aranges", ".zdebug_aranges" },
312 /* List of DWO/DWP sections. */
314 static const struct dwop_section_names
316 struct dwarf2_section_names abbrev_dwo
;
317 struct dwarf2_section_names info_dwo
;
318 struct dwarf2_section_names line_dwo
;
319 struct dwarf2_section_names loc_dwo
;
320 struct dwarf2_section_names loclists_dwo
;
321 struct dwarf2_section_names macinfo_dwo
;
322 struct dwarf2_section_names macro_dwo
;
323 struct dwarf2_section_names str_dwo
;
324 struct dwarf2_section_names str_offsets_dwo
;
325 struct dwarf2_section_names types_dwo
;
326 struct dwarf2_section_names cu_index
;
327 struct dwarf2_section_names tu_index
;
331 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
332 { ".debug_info.dwo", ".zdebug_info.dwo" },
333 { ".debug_line.dwo", ".zdebug_line.dwo" },
334 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
335 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
336 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
337 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
338 { ".debug_str.dwo", ".zdebug_str.dwo" },
339 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
340 { ".debug_types.dwo", ".zdebug_types.dwo" },
341 { ".debug_cu_index", ".zdebug_cu_index" },
342 { ".debug_tu_index", ".zdebug_tu_index" },
345 /* local data types */
347 /* Type used for delaying computation of method physnames.
348 See comments for compute_delayed_physnames. */
349 struct delayed_method_info
351 /* The type to which the method is attached, i.e., its parent class. */
354 /* The index of the method in the type's function fieldlists. */
357 /* The index of the method in the fieldlist. */
360 /* The name of the DIE. */
363 /* The DIE associated with this method. */
364 struct die_info
*die
;
367 /* Internal state when decoding a particular compilation unit. */
370 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
373 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
375 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
376 Create the set of symtabs used by this TU, or if this TU is sharing
377 symtabs with another TU and the symtabs have already been created
378 then restore those symtabs in the line header.
379 We don't need the pc/line-number mapping for type units. */
380 void setup_type_unit_groups (struct die_info
*die
);
382 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
383 buildsym_compunit constructor. */
384 struct compunit_symtab
*start_symtab (const char *name
,
385 const char *comp_dir
,
388 /* Reset the builder. */
389 void reset_builder () { m_builder
.reset (); }
391 /* The header of the compilation unit. */
392 struct comp_unit_head header
{};
394 /* Base address of this compilation unit. */
395 CORE_ADDR base_address
= 0;
397 /* Non-zero if base_address has been set. */
400 /* The language we are debugging. */
401 enum language language
= language_unknown
;
402 const struct language_defn
*language_defn
= nullptr;
404 const char *producer
= nullptr;
407 /* The symtab builder for this CU. This is only non-NULL when full
408 symbols are being read. */
409 std::unique_ptr
<buildsym_compunit
> m_builder
;
412 /* The generic symbol table building routines have separate lists for
413 file scope symbols and all all other scopes (local scopes). So
414 we need to select the right one to pass to add_symbol_to_list().
415 We do it by keeping a pointer to the correct list in list_in_scope.
417 FIXME: The original dwarf code just treated the file scope as the
418 first local scope, and all other local scopes as nested local
419 scopes, and worked fine. Check to see if we really need to
420 distinguish these in buildsym.c. */
421 struct pending
**list_in_scope
= nullptr;
423 /* Hash table holding all the loaded partial DIEs
424 with partial_die->offset.SECT_OFF as hash. */
425 htab_t partial_dies
= nullptr;
427 /* Storage for things with the same lifetime as this read-in compilation
428 unit, including partial DIEs. */
429 auto_obstack comp_unit_obstack
;
431 /* When multiple dwarf2_cu structures are living in memory, this field
432 chains them all together, so that they can be released efficiently.
433 We will probably also want a generation counter so that most-recently-used
434 compilation units are cached... */
435 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
437 /* Backlink to our per_cu entry. */
438 struct dwarf2_per_cu_data
*per_cu
;
440 /* How many compilation units ago was this CU last referenced? */
443 /* A hash table of DIE cu_offset for following references with
444 die_info->offset.sect_off as hash. */
445 htab_t die_hash
= nullptr;
447 /* Full DIEs if read in. */
448 struct die_info
*dies
= nullptr;
450 /* A set of pointers to dwarf2_per_cu_data objects for compilation
451 units referenced by this one. Only set during full symbol processing;
452 partial symbol tables do not have dependencies. */
453 htab_t dependencies
= nullptr;
455 /* Header data from the line table, during full symbol processing. */
456 struct line_header
*line_header
= nullptr;
457 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
458 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
459 this is the DW_TAG_compile_unit die for this CU. We'll hold on
460 to the line header as long as this DIE is being processed. See
461 process_die_scope. */
462 die_info
*line_header_die_owner
= nullptr;
464 /* A list of methods which need to have physnames computed
465 after all type information has been read. */
466 std::vector
<delayed_method_info
> method_list
;
468 /* To be copied to symtab->call_site_htab. */
469 htab_t call_site_htab
= nullptr;
471 /* Non-NULL if this CU came from a DWO file.
472 There is an invariant here that is important to remember:
473 Except for attributes copied from the top level DIE in the "main"
474 (or "stub") file in preparation for reading the DWO file
475 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
476 Either there isn't a DWO file (in which case this is NULL and the point
477 is moot), or there is and either we're not going to read it (in which
478 case this is NULL) or there is and we are reading it (in which case this
480 struct dwo_unit
*dwo_unit
= nullptr;
482 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
483 Note this value comes from the Fission stub CU/TU's DIE. */
484 gdb::optional
<ULONGEST
> addr_base
;
486 /* The DW_AT_rnglists_base attribute if present.
487 Note this value comes from the Fission stub CU/TU's DIE.
488 Also note that the value is zero in the non-DWO case so this value can
489 be used without needing to know whether DWO files are in use or not.
490 N.B. This does not apply to DW_AT_ranges appearing in
491 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
492 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
493 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
494 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
495 ULONGEST ranges_base
= 0;
497 /* When reading debug info generated by older versions of rustc, we
498 have to rewrite some union types to be struct types with a
499 variant part. This rewriting must be done after the CU is fully
500 read in, because otherwise at the point of rewriting some struct
501 type might not have been fully processed. So, we keep a list of
502 all such types here and process them after expansion. */
503 std::vector
<struct type
*> rust_unions
;
505 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
506 files, the value is implicitly zero. For DWARF 5 version DWO files, the
507 value is often implicit and is the size of the header of
508 .debug_str_offsets section (8 or 4, depending on the address size). */
509 gdb::optional
<ULONGEST
> str_offsets_base
;
511 /* Mark used when releasing cached dies. */
514 /* This CU references .debug_loc. See the symtab->locations_valid field.
515 This test is imperfect as there may exist optimized debug code not using
516 any location list and still facing inlining issues if handled as
517 unoptimized code. For a future better test see GCC PR other/32998. */
518 bool has_loclist
: 1;
520 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
521 if all the producer_is_* fields are valid. This information is cached
522 because profiling CU expansion showed excessive time spent in
523 producer_is_gxx_lt_4_6. */
524 bool checked_producer
: 1;
525 bool producer_is_gxx_lt_4_6
: 1;
526 bool producer_is_gcc_lt_4_3
: 1;
527 bool producer_is_icc
: 1;
528 bool producer_is_icc_lt_14
: 1;
529 bool producer_is_codewarrior
: 1;
531 /* When true, the file that we're processing is known to have
532 debugging info for C++ namespaces. GCC 3.3.x did not produce
533 this information, but later versions do. */
535 bool processing_has_namespace_info
: 1;
537 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
539 /* If this CU was inherited by another CU (via specification,
540 abstract_origin, etc), this is the ancestor CU. */
543 /* Get the buildsym_compunit for this CU. */
544 buildsym_compunit
*get_builder ()
546 /* If this CU has a builder associated with it, use that. */
547 if (m_builder
!= nullptr)
548 return m_builder
.get ();
550 /* Otherwise, search ancestors for a valid builder. */
551 if (ancestor
!= nullptr)
552 return ancestor
->get_builder ();
558 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
559 This includes type_unit_group and quick_file_names. */
561 struct stmt_list_hash
563 /* The DWO unit this table is from or NULL if there is none. */
564 struct dwo_unit
*dwo_unit
;
566 /* Offset in .debug_line or .debug_line.dwo. */
567 sect_offset line_sect_off
;
570 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
571 an object of this type. */
573 struct type_unit_group
575 /* dwarf2read.c's main "handle" on a TU symtab.
576 To simplify things we create an artificial CU that "includes" all the
577 type units using this stmt_list so that the rest of the code still has
578 a "per_cu" handle on the symtab. */
579 struct dwarf2_per_cu_data per_cu
;
581 /* The TUs that share this DW_AT_stmt_list entry.
582 This is added to while parsing type units to build partial symtabs,
583 and is deleted afterwards and not used again. */
584 std::vector
<signatured_type
*> *tus
;
586 /* The compunit symtab.
587 Type units in a group needn't all be defined in the same source file,
588 so we create an essentially anonymous symtab as the compunit symtab. */
589 struct compunit_symtab
*compunit_symtab
;
591 /* The data used to construct the hash key. */
592 struct stmt_list_hash hash
;
594 /* The symbol tables for this TU (obtained from the files listed in
596 WARNING: The order of entries here must match the order of entries
597 in the line header. After the first TU using this type_unit_group, the
598 line header for the subsequent TUs is recreated from this. This is done
599 because we need to use the same symtabs for each TU using the same
600 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
601 there's no guarantee the line header doesn't have duplicate entries. */
602 struct symtab
**symtabs
;
605 /* These sections are what may appear in a (real or virtual) DWO file. */
609 struct dwarf2_section_info abbrev
;
610 struct dwarf2_section_info line
;
611 struct dwarf2_section_info loc
;
612 struct dwarf2_section_info loclists
;
613 struct dwarf2_section_info macinfo
;
614 struct dwarf2_section_info macro
;
615 struct dwarf2_section_info str
;
616 struct dwarf2_section_info str_offsets
;
617 /* In the case of a virtual DWO file, these two are unused. */
618 struct dwarf2_section_info info
;
619 std::vector
<dwarf2_section_info
> types
;
622 /* CUs/TUs in DWP/DWO files. */
626 /* Backlink to the containing struct dwo_file. */
627 struct dwo_file
*dwo_file
;
629 /* The "id" that distinguishes this CU/TU.
630 .debug_info calls this "dwo_id", .debug_types calls this "signature".
631 Since signatures came first, we stick with it for consistency. */
634 /* The section this CU/TU lives in, in the DWO file. */
635 struct dwarf2_section_info
*section
;
637 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
638 sect_offset sect_off
;
641 /* For types, offset in the type's DIE of the type defined by this TU. */
642 cu_offset type_offset_in_tu
;
645 /* include/dwarf2.h defines the DWP section codes.
646 It defines a max value but it doesn't define a min value, which we
647 use for error checking, so provide one. */
649 enum dwp_v2_section_ids
654 /* Data for one DWO file.
656 This includes virtual DWO files (a virtual DWO file is a DWO file as it
657 appears in a DWP file). DWP files don't really have DWO files per se -
658 comdat folding of types "loses" the DWO file they came from, and from
659 a high level view DWP files appear to contain a mass of random types.
660 However, to maintain consistency with the non-DWP case we pretend DWP
661 files contain virtual DWO files, and we assign each TU with one virtual
662 DWO file (generally based on the line and abbrev section offsets -
663 a heuristic that seems to work in practice). */
667 dwo_file () = default;
668 DISABLE_COPY_AND_ASSIGN (dwo_file
);
670 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
671 For virtual DWO files the name is constructed from the section offsets
672 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
673 from related CU+TUs. */
674 const char *dwo_name
= nullptr;
676 /* The DW_AT_comp_dir attribute. */
677 const char *comp_dir
= nullptr;
679 /* The bfd, when the file is open. Otherwise this is NULL.
680 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
681 gdb_bfd_ref_ptr dbfd
;
683 /* The sections that make up this DWO file.
684 Remember that for virtual DWO files in DWP V2, these are virtual
685 sections (for lack of a better name). */
686 struct dwo_sections sections
{};
688 /* The CUs in the file.
689 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
690 an extension to handle LLVM's Link Time Optimization output (where
691 multiple source files may be compiled into a single object/dwo pair). */
694 /* Table of TUs in the file.
695 Each element is a struct dwo_unit. */
699 /* These sections are what may appear in a DWP file. */
703 /* These are used by both DWP version 1 and 2. */
704 struct dwarf2_section_info str
;
705 struct dwarf2_section_info cu_index
;
706 struct dwarf2_section_info tu_index
;
708 /* These are only used by DWP version 2 files.
709 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
710 sections are referenced by section number, and are not recorded here.
711 In DWP version 2 there is at most one copy of all these sections, each
712 section being (effectively) comprised of the concatenation of all of the
713 individual sections that exist in the version 1 format.
714 To keep the code simple we treat each of these concatenated pieces as a
715 section itself (a virtual section?). */
716 struct dwarf2_section_info abbrev
;
717 struct dwarf2_section_info info
;
718 struct dwarf2_section_info line
;
719 struct dwarf2_section_info loc
;
720 struct dwarf2_section_info macinfo
;
721 struct dwarf2_section_info macro
;
722 struct dwarf2_section_info str_offsets
;
723 struct dwarf2_section_info types
;
726 /* These sections are what may appear in a virtual DWO file in DWP version 1.
727 A virtual DWO file is a DWO file as it appears in a DWP file. */
729 struct virtual_v1_dwo_sections
731 struct dwarf2_section_info abbrev
;
732 struct dwarf2_section_info line
;
733 struct dwarf2_section_info loc
;
734 struct dwarf2_section_info macinfo
;
735 struct dwarf2_section_info macro
;
736 struct dwarf2_section_info str_offsets
;
737 /* Each DWP hash table entry records one CU or one TU.
738 That is recorded here, and copied to dwo_unit.section. */
739 struct dwarf2_section_info info_or_types
;
742 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
743 In version 2, the sections of the DWO files are concatenated together
744 and stored in one section of that name. Thus each ELF section contains
745 several "virtual" sections. */
747 struct virtual_v2_dwo_sections
749 bfd_size_type abbrev_offset
;
750 bfd_size_type abbrev_size
;
752 bfd_size_type line_offset
;
753 bfd_size_type line_size
;
755 bfd_size_type loc_offset
;
756 bfd_size_type loc_size
;
758 bfd_size_type macinfo_offset
;
759 bfd_size_type macinfo_size
;
761 bfd_size_type macro_offset
;
762 bfd_size_type macro_size
;
764 bfd_size_type str_offsets_offset
;
765 bfd_size_type str_offsets_size
;
767 /* Each DWP hash table entry records one CU or one TU.
768 That is recorded here, and copied to dwo_unit.section. */
769 bfd_size_type info_or_types_offset
;
770 bfd_size_type info_or_types_size
;
773 /* Contents of DWP hash tables. */
775 struct dwp_hash_table
777 uint32_t version
, nr_columns
;
778 uint32_t nr_units
, nr_slots
;
779 const gdb_byte
*hash_table
, *unit_table
;
784 const gdb_byte
*indices
;
788 /* This is indexed by column number and gives the id of the section
790 #define MAX_NR_V2_DWO_SECTIONS \
791 (1 /* .debug_info or .debug_types */ \
792 + 1 /* .debug_abbrev */ \
793 + 1 /* .debug_line */ \
794 + 1 /* .debug_loc */ \
795 + 1 /* .debug_str_offsets */ \
796 + 1 /* .debug_macro or .debug_macinfo */)
797 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
798 const gdb_byte
*offsets
;
799 const gdb_byte
*sizes
;
804 /* Data for one DWP file. */
808 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
810 dbfd (std::move (abfd
))
814 /* Name of the file. */
817 /* File format version. */
821 gdb_bfd_ref_ptr dbfd
;
823 /* Section info for this file. */
824 struct dwp_sections sections
{};
826 /* Table of CUs in the file. */
827 const struct dwp_hash_table
*cus
= nullptr;
829 /* Table of TUs in the file. */
830 const struct dwp_hash_table
*tus
= nullptr;
832 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
836 /* Table to map ELF section numbers to their sections.
837 This is only needed for the DWP V1 file format. */
838 unsigned int num_sections
= 0;
839 asection
**elf_sections
= nullptr;
842 /* Struct used to pass misc. parameters to read_die_and_children, et
843 al. which are used for both .debug_info and .debug_types dies.
844 All parameters here are unchanging for the life of the call. This
845 struct exists to abstract away the constant parameters of die reading. */
847 struct die_reader_specs
849 /* The bfd of die_section. */
852 /* The CU of the DIE we are parsing. */
853 struct dwarf2_cu
*cu
;
855 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
856 struct dwo_file
*dwo_file
;
858 /* The section the die comes from.
859 This is either .debug_info or .debug_types, or the .dwo variants. */
860 struct dwarf2_section_info
*die_section
;
862 /* die_section->buffer. */
863 const gdb_byte
*buffer
;
865 /* The end of the buffer. */
866 const gdb_byte
*buffer_end
;
868 /* The abbreviation table to use when reading the DIEs. */
869 struct abbrev_table
*abbrev_table
;
872 /* A subclass of die_reader_specs that holds storage and has complex
873 constructor and destructor behavior. */
875 class cutu_reader
: public die_reader_specs
879 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
880 struct abbrev_table
*abbrev_table
,
884 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
885 struct dwarf2_cu
*parent_cu
= nullptr,
886 struct dwo_file
*dwo_file
= nullptr);
888 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
890 const gdb_byte
*info_ptr
= nullptr;
891 struct die_info
*comp_unit_die
= nullptr;
892 bool dummy_p
= false;
894 /* Release the new CU, putting it on the chain. This cannot be done
899 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
900 int use_existing_cu
);
902 struct dwarf2_per_cu_data
*m_this_cu
;
903 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
905 /* The ordinary abbreviation table. */
906 abbrev_table_up m_abbrev_table_holder
;
908 /* The DWO abbreviation table. */
909 abbrev_table_up m_dwo_abbrev_table
;
912 /* When we construct a partial symbol table entry we only
913 need this much information. */
914 struct partial_die_info
: public allocate_on_obstack
916 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
918 /* Disable assign but still keep copy ctor, which is needed
919 load_partial_dies. */
920 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
922 /* Adjust the partial die before generating a symbol for it. This
923 function may set the is_external flag or change the DIE's
925 void fixup (struct dwarf2_cu
*cu
);
927 /* Read a minimal amount of information into the minimal die
929 const gdb_byte
*read (const struct die_reader_specs
*reader
,
930 const struct abbrev_info
&abbrev
,
931 const gdb_byte
*info_ptr
);
933 /* Offset of this DIE. */
934 const sect_offset sect_off
;
936 /* DWARF-2 tag for this DIE. */
937 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
939 /* Assorted flags describing the data found in this DIE. */
940 const unsigned int has_children
: 1;
942 unsigned int is_external
: 1;
943 unsigned int is_declaration
: 1;
944 unsigned int has_type
: 1;
945 unsigned int has_specification
: 1;
946 unsigned int has_pc_info
: 1;
947 unsigned int may_be_inlined
: 1;
949 /* This DIE has been marked DW_AT_main_subprogram. */
950 unsigned int main_subprogram
: 1;
952 /* Flag set if the SCOPE field of this structure has been
954 unsigned int scope_set
: 1;
956 /* Flag set if the DIE has a byte_size attribute. */
957 unsigned int has_byte_size
: 1;
959 /* Flag set if the DIE has a DW_AT_const_value attribute. */
960 unsigned int has_const_value
: 1;
962 /* Flag set if any of the DIE's children are template arguments. */
963 unsigned int has_template_arguments
: 1;
965 /* Flag set if fixup has been called on this die. */
966 unsigned int fixup_called
: 1;
968 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
969 unsigned int is_dwz
: 1;
971 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
972 unsigned int spec_is_dwz
: 1;
974 /* The name of this DIE. Normally the value of DW_AT_name, but
975 sometimes a default name for unnamed DIEs. */
976 const char *name
= nullptr;
978 /* The linkage name, if present. */
979 const char *linkage_name
= nullptr;
981 /* The scope to prepend to our children. This is generally
982 allocated on the comp_unit_obstack, so will disappear
983 when this compilation unit leaves the cache. */
984 const char *scope
= nullptr;
986 /* Some data associated with the partial DIE. The tag determines
987 which field is live. */
990 /* The location description associated with this DIE, if any. */
991 struct dwarf_block
*locdesc
;
992 /* The offset of an import, for DW_TAG_imported_unit. */
993 sect_offset sect_off
;
996 /* If HAS_PC_INFO, the PC range associated with this DIE. */
998 CORE_ADDR highpc
= 0;
1000 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1001 DW_AT_sibling, if any. */
1002 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1003 could return DW_AT_sibling values to its caller load_partial_dies. */
1004 const gdb_byte
*sibling
= nullptr;
1006 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1007 DW_AT_specification (or DW_AT_abstract_origin or
1008 DW_AT_extension). */
1009 sect_offset spec_offset
{};
1011 /* Pointers to this DIE's parent, first child, and next sibling,
1013 struct partial_die_info
*die_parent
= nullptr;
1014 struct partial_die_info
*die_child
= nullptr;
1015 struct partial_die_info
*die_sibling
= nullptr;
1017 friend struct partial_die_info
*
1018 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1021 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1022 partial_die_info (sect_offset sect_off
)
1023 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1027 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1029 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1034 has_specification
= 0;
1037 main_subprogram
= 0;
1040 has_const_value
= 0;
1041 has_template_arguments
= 0;
1048 /* This data structure holds a complete die structure. */
1051 /* DWARF-2 tag for this DIE. */
1052 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1054 /* Number of attributes */
1055 unsigned char num_attrs
;
1057 /* True if we're presently building the full type name for the
1058 type derived from this DIE. */
1059 unsigned char building_fullname
: 1;
1061 /* True if this die is in process. PR 16581. */
1062 unsigned char in_process
: 1;
1064 /* True if this DIE has children. */
1065 unsigned char has_children
: 1;
1068 unsigned int abbrev
;
1070 /* Offset in .debug_info or .debug_types section. */
1071 sect_offset sect_off
;
1073 /* The dies in a compilation unit form an n-ary tree. PARENT
1074 points to this die's parent; CHILD points to the first child of
1075 this node; and all the children of a given node are chained
1076 together via their SIBLING fields. */
1077 struct die_info
*child
; /* Its first child, if any. */
1078 struct die_info
*sibling
; /* Its next sibling, if any. */
1079 struct die_info
*parent
; /* Its parent, if any. */
1081 /* An array of attributes, with NUM_ATTRS elements. There may be
1082 zero, but it's not common and zero-sized arrays are not
1083 sufficiently portable C. */
1084 struct attribute attrs
[1];
1087 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1088 but this would require a corresponding change in unpack_field_as_long
1090 static int bits_per_byte
= 8;
1092 /* When reading a variant or variant part, we track a bit more
1093 information about the field, and store it in an object of this
1096 struct variant_field
1098 /* If we see a DW_TAG_variant, then this will be the discriminant
1100 ULONGEST discriminant_value
;
1101 /* If we see a DW_TAG_variant, then this will be set if this is the
1103 bool default_branch
;
1104 /* While reading a DW_TAG_variant_part, this will be set if this
1105 field is the discriminant. */
1106 bool is_discriminant
;
1111 int accessibility
= 0;
1113 /* Extra information to describe a variant or variant part. */
1114 struct variant_field variant
{};
1115 struct field field
{};
1120 const char *name
= nullptr;
1121 std::vector
<struct fn_field
> fnfields
;
1124 /* The routines that read and process dies for a C struct or C++ class
1125 pass lists of data member fields and lists of member function fields
1126 in an instance of a field_info structure, as defined below. */
1129 /* List of data member and baseclasses fields. */
1130 std::vector
<struct nextfield
> fields
;
1131 std::vector
<struct nextfield
> baseclasses
;
1133 /* Set if the accessibility of one of the fields is not public. */
1134 int non_public_fields
= 0;
1136 /* Member function fieldlist array, contains name of possibly overloaded
1137 member function, number of overloaded member functions and a pointer
1138 to the head of the member function field chain. */
1139 std::vector
<struct fnfieldlist
> fnfieldlists
;
1141 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1142 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1143 std::vector
<struct decl_field
> typedef_field_list
;
1145 /* Nested types defined by this class and the number of elements in this
1147 std::vector
<struct decl_field
> nested_types_list
;
1149 /* Return the total number of fields (including baseclasses). */
1150 int nfields () const
1152 return fields
.size () + baseclasses
.size ();
1156 /* Loaded secondary compilation units are kept in memory until they
1157 have not been referenced for the processing of this many
1158 compilation units. Set this to zero to disable caching. Cache
1159 sizes of up to at least twenty will improve startup time for
1160 typical inter-CU-reference binaries, at an obvious memory cost. */
1161 static int dwarf_max_cache_age
= 5;
1163 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1164 struct cmd_list_element
*c
, const char *value
)
1166 fprintf_filtered (file
, _("The upper bound on the age of cached "
1167 "DWARF compilation units is %s.\n"),
1171 /* local function prototypes */
1173 static void dwarf2_find_base_address (struct die_info
*die
,
1174 struct dwarf2_cu
*cu
);
1176 static dwarf2_psymtab
*create_partial_symtab
1177 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1179 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1180 const gdb_byte
*info_ptr
,
1181 struct die_info
*type_unit_die
);
1183 static void dwarf2_build_psymtabs_hard
1184 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1186 static void scan_partial_symbols (struct partial_die_info
*,
1187 CORE_ADDR
*, CORE_ADDR
*,
1188 int, struct dwarf2_cu
*);
1190 static void add_partial_symbol (struct partial_die_info
*,
1191 struct dwarf2_cu
*);
1193 static void add_partial_namespace (struct partial_die_info
*pdi
,
1194 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1195 int set_addrmap
, struct dwarf2_cu
*cu
);
1197 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1198 CORE_ADDR
*highpc
, int set_addrmap
,
1199 struct dwarf2_cu
*cu
);
1201 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1202 struct dwarf2_cu
*cu
);
1204 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1205 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1206 int need_pc
, struct dwarf2_cu
*cu
);
1208 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1210 static struct partial_die_info
*load_partial_dies
1211 (const struct die_reader_specs
*, const gdb_byte
*, int);
1213 /* A pair of partial_die_info and compilation unit. */
1214 struct cu_partial_die_info
1216 /* The compilation unit of the partial_die_info. */
1217 struct dwarf2_cu
*cu
;
1218 /* A partial_die_info. */
1219 struct partial_die_info
*pdi
;
1221 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1227 cu_partial_die_info () = delete;
1230 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1231 struct dwarf2_cu
*);
1233 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1234 struct attribute
*, struct attr_abbrev
*,
1235 const gdb_byte
*, bool *need_reprocess
);
1237 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1238 struct attribute
*attr
);
1240 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1242 static LONGEST read_checked_initial_length_and_offset
1243 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1244 unsigned int *, unsigned int *);
1246 static sect_offset read_abbrev_offset
1247 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1248 struct dwarf2_section_info
*, sect_offset
);
1250 static const char *read_indirect_string
1251 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1252 const struct comp_unit_head
*, unsigned int *);
1254 static const char *read_indirect_line_string
1255 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1256 const struct comp_unit_head
*, unsigned int *);
1258 static const char *read_indirect_string_at_offset
1259 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1260 LONGEST str_offset
);
1262 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1266 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1267 ULONGEST str_index
);
1269 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1270 ULONGEST str_index
);
1272 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1274 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1275 struct dwarf2_cu
*);
1277 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1280 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1281 struct dwarf2_cu
*cu
);
1283 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1285 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1286 struct dwarf2_cu
*cu
);
1288 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1290 static struct die_info
*die_specification (struct die_info
*die
,
1291 struct dwarf2_cu
**);
1293 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1294 struct dwarf2_cu
*cu
);
1296 static void dwarf_decode_lines (struct line_header
*, const char *,
1297 struct dwarf2_cu
*, dwarf2_psymtab
*,
1298 CORE_ADDR
, int decode_mapping
);
1300 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1303 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1304 struct dwarf2_cu
*, struct symbol
* = NULL
);
1306 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1307 struct dwarf2_cu
*);
1309 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1312 struct obstack
*obstack
,
1313 struct dwarf2_cu
*cu
, LONGEST
*value
,
1314 const gdb_byte
**bytes
,
1315 struct dwarf2_locexpr_baton
**baton
);
1317 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1319 static int need_gnat_info (struct dwarf2_cu
*);
1321 static struct type
*die_descriptive_type (struct die_info
*,
1322 struct dwarf2_cu
*);
1324 static void set_descriptive_type (struct type
*, struct die_info
*,
1325 struct dwarf2_cu
*);
1327 static struct type
*die_containing_type (struct die_info
*,
1328 struct dwarf2_cu
*);
1330 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1331 struct dwarf2_cu
*);
1333 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1335 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1337 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1339 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1340 const char *suffix
, int physname
,
1341 struct dwarf2_cu
*cu
);
1343 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1345 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1347 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1349 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1351 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1353 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1355 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1356 struct dwarf2_cu
*, dwarf2_psymtab
*);
1358 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1359 values. Keep the items ordered with increasing constraints compliance. */
1362 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1363 PC_BOUNDS_NOT_PRESENT
,
1365 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1366 were present but they do not form a valid range of PC addresses. */
1369 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1372 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1376 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1377 CORE_ADDR
*, CORE_ADDR
*,
1381 static void get_scope_pc_bounds (struct die_info
*,
1382 CORE_ADDR
*, CORE_ADDR
*,
1383 struct dwarf2_cu
*);
1385 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1386 CORE_ADDR
, struct dwarf2_cu
*);
1388 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1389 struct dwarf2_cu
*);
1391 static void dwarf2_attach_fields_to_type (struct field_info
*,
1392 struct type
*, struct dwarf2_cu
*);
1394 static void dwarf2_add_member_fn (struct field_info
*,
1395 struct die_info
*, struct type
*,
1396 struct dwarf2_cu
*);
1398 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1400 struct dwarf2_cu
*);
1402 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1404 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1406 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1408 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1410 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1412 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1414 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1416 static struct type
*read_module_type (struct die_info
*die
,
1417 struct dwarf2_cu
*cu
);
1419 static const char *namespace_name (struct die_info
*die
,
1420 int *is_anonymous
, struct dwarf2_cu
*);
1422 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1424 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1426 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1427 struct dwarf2_cu
*);
1429 static struct die_info
*read_die_and_siblings_1
1430 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1433 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1434 const gdb_byte
*info_ptr
,
1435 const gdb_byte
**new_info_ptr
,
1436 struct die_info
*parent
);
1438 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1439 struct die_info
**, const gdb_byte
*,
1442 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1443 struct die_info
**, const gdb_byte
*);
1445 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1447 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1450 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1452 static const char *dwarf2_full_name (const char *name
,
1453 struct die_info
*die
,
1454 struct dwarf2_cu
*cu
);
1456 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1457 struct dwarf2_cu
*cu
);
1459 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1460 struct dwarf2_cu
**);
1462 static const char *dwarf_tag_name (unsigned int);
1464 static const char *dwarf_attr_name (unsigned int);
1466 static const char *dwarf_form_name (unsigned int);
1468 static const char *dwarf_bool_name (unsigned int);
1470 static const char *dwarf_type_encoding_name (unsigned int);
1472 static struct die_info
*sibling_die (struct die_info
*);
1474 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1476 static void dump_die_for_error (struct die_info
*);
1478 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1481 /*static*/ void dump_die (struct die_info
*, int max_level
);
1483 static void store_in_ref_table (struct die_info
*,
1484 struct dwarf2_cu
*);
1486 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1488 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1490 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1491 const struct attribute
*,
1492 struct dwarf2_cu
**);
1494 static struct die_info
*follow_die_ref (struct die_info
*,
1495 const struct attribute
*,
1496 struct dwarf2_cu
**);
1498 static struct die_info
*follow_die_sig (struct die_info
*,
1499 const struct attribute
*,
1500 struct dwarf2_cu
**);
1502 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1503 struct dwarf2_cu
*);
1505 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1506 const struct attribute
*,
1507 struct dwarf2_cu
*);
1509 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1511 static void read_signatured_type (struct signatured_type
*);
1513 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1514 struct die_info
*die
, struct dwarf2_cu
*cu
,
1515 struct dynamic_prop
*prop
, struct type
*type
);
1517 /* memory allocation interface */
1519 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1521 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1523 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1525 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1526 struct dwarf2_loclist_baton
*baton
,
1527 const struct attribute
*attr
);
1529 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1531 struct dwarf2_cu
*cu
,
1534 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1535 const gdb_byte
*info_ptr
,
1536 struct abbrev_info
*abbrev
);
1538 static hashval_t
partial_die_hash (const void *item
);
1540 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1542 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1543 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1544 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1546 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1547 struct die_info
*comp_unit_die
,
1548 enum language pretend_language
);
1550 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1552 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1554 static struct type
*set_die_type (struct die_info
*, struct type
*,
1555 struct dwarf2_cu
*);
1557 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1559 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1561 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1564 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1567 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1570 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1571 struct dwarf2_per_cu_data
*);
1573 static void dwarf2_mark (struct dwarf2_cu
*);
1575 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1577 static struct type
*get_die_type_at_offset (sect_offset
,
1578 struct dwarf2_per_cu_data
*);
1580 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1582 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1583 enum language pretend_language
);
1585 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1587 /* Class, the destructor of which frees all allocated queue entries. This
1588 will only have work to do if an error was thrown while processing the
1589 dwarf. If no error was thrown then the queue entries should have all
1590 been processed, and freed, as we went along. */
1592 class dwarf2_queue_guard
1595 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1596 : m_per_objfile (per_objfile
)
1600 /* Free any entries remaining on the queue. There should only be
1601 entries left if we hit an error while processing the dwarf. */
1602 ~dwarf2_queue_guard ()
1604 /* Ensure that no memory is allocated by the queue. */
1605 std::queue
<dwarf2_queue_item
> empty
;
1606 std::swap (m_per_objfile
->queue
, empty
);
1609 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1612 dwarf2_per_objfile
*m_per_objfile
;
1615 dwarf2_queue_item::~dwarf2_queue_item ()
1617 /* Anything still marked queued is likely to be in an
1618 inconsistent state, so discard it. */
1621 if (per_cu
->cu
!= NULL
)
1622 free_one_cached_comp_unit (per_cu
);
1627 /* The return type of find_file_and_directory. Note, the enclosed
1628 string pointers are only valid while this object is valid. */
1630 struct file_and_directory
1632 /* The filename. This is never NULL. */
1635 /* The compilation directory. NULL if not known. If we needed to
1636 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1637 points directly to the DW_AT_comp_dir string attribute owned by
1638 the obstack that owns the DIE. */
1639 const char *comp_dir
;
1641 /* If we needed to build a new string for comp_dir, this is what
1642 owns the storage. */
1643 std::string comp_dir_storage
;
1646 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1647 struct dwarf2_cu
*cu
);
1649 static htab_up
allocate_signatured_type_table ();
1651 static htab_up
allocate_dwo_unit_table ();
1653 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1654 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1655 struct dwp_file
*dwp_file
, const char *comp_dir
,
1656 ULONGEST signature
, int is_debug_types
);
1658 static struct dwp_file
*get_dwp_file
1659 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1661 static struct dwo_unit
*lookup_dwo_comp_unit
1662 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1664 static struct dwo_unit
*lookup_dwo_type_unit
1665 (struct signatured_type
*, const char *, const char *);
1667 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1669 /* A unique pointer to a dwo_file. */
1671 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1673 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1675 static void check_producer (struct dwarf2_cu
*cu
);
1677 static void free_line_header_voidp (void *arg
);
1679 /* Various complaints about symbol reading that don't abort the process. */
1682 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1684 complaint (_("statement list doesn't fit in .debug_line section"));
1688 dwarf2_debug_line_missing_file_complaint (void)
1690 complaint (_(".debug_line section has line data without a file"));
1694 dwarf2_debug_line_missing_end_sequence_complaint (void)
1696 complaint (_(".debug_line section has line "
1697 "program sequence without an end"));
1701 dwarf2_complex_location_expr_complaint (void)
1703 complaint (_("location expression too complex"));
1707 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1710 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1715 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1717 complaint (_("macro debug info contains a "
1718 "malformed macro definition:\n`%s'"),
1723 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1725 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1729 /* Hash function for line_header_hash. */
1732 line_header_hash (const struct line_header
*ofs
)
1734 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1737 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1740 line_header_hash_voidp (const void *item
)
1742 const struct line_header
*ofs
= (const struct line_header
*) item
;
1744 return line_header_hash (ofs
);
1747 /* Equality function for line_header_hash. */
1750 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1752 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1753 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1755 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1756 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1761 /* See declaration. */
1763 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1764 const dwarf2_debug_sections
*names
,
1766 : objfile (objfile_
),
1767 can_copy (can_copy_
)
1770 names
= &dwarf2_elf_names
;
1772 bfd
*obfd
= objfile
->obfd
;
1774 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1775 locate_sections (obfd
, sec
, *names
);
1778 dwarf2_per_objfile::~dwarf2_per_objfile ()
1780 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1781 free_cached_comp_units ();
1783 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1784 per_cu
->imported_symtabs_free ();
1786 for (signatured_type
*sig_type
: all_type_units
)
1787 sig_type
->per_cu
.imported_symtabs_free ();
1789 /* Everything else should be on the objfile obstack. */
1792 /* See declaration. */
1795 dwarf2_per_objfile::free_cached_comp_units ()
1797 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1798 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1799 while (per_cu
!= NULL
)
1801 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1804 *last_chain
= next_cu
;
1809 /* A helper class that calls free_cached_comp_units on
1812 class free_cached_comp_units
1816 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1817 : m_per_objfile (per_objfile
)
1821 ~free_cached_comp_units ()
1823 m_per_objfile
->free_cached_comp_units ();
1826 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1830 dwarf2_per_objfile
*m_per_objfile
;
1833 /* Try to locate the sections we need for DWARF 2 debugging
1834 information and return true if we have enough to do something.
1835 NAMES points to the dwarf2 section names, or is NULL if the standard
1836 ELF names are used. CAN_COPY is true for formats where symbol
1837 interposition is possible and so symbol values must follow copy
1838 relocation rules. */
1841 dwarf2_has_info (struct objfile
*objfile
,
1842 const struct dwarf2_debug_sections
*names
,
1845 if (objfile
->flags
& OBJF_READNEVER
)
1848 struct dwarf2_per_objfile
*dwarf2_per_objfile
1849 = get_dwarf2_per_objfile (objfile
);
1851 if (dwarf2_per_objfile
== NULL
)
1852 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1856 return (!dwarf2_per_objfile
->info
.is_virtual
1857 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1858 && !dwarf2_per_objfile
->abbrev
.is_virtual
1859 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1862 /* When loading sections, we look either for uncompressed section or for
1863 compressed section names. */
1866 section_is_p (const char *section_name
,
1867 const struct dwarf2_section_names
*names
)
1869 if (names
->normal
!= NULL
1870 && strcmp (section_name
, names
->normal
) == 0)
1872 if (names
->compressed
!= NULL
1873 && strcmp (section_name
, names
->compressed
) == 0)
1878 /* See declaration. */
1881 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1882 const dwarf2_debug_sections
&names
)
1884 flagword aflag
= bfd_section_flags (sectp
);
1886 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1889 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1890 > bfd_get_file_size (abfd
))
1892 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1893 warning (_("Discarding section %s which has a section size (%s"
1894 ") larger than the file size [in module %s]"),
1895 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1896 bfd_get_filename (abfd
));
1898 else if (section_is_p (sectp
->name
, &names
.info
))
1900 this->info
.s
.section
= sectp
;
1901 this->info
.size
= bfd_section_size (sectp
);
1903 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1905 this->abbrev
.s
.section
= sectp
;
1906 this->abbrev
.size
= bfd_section_size (sectp
);
1908 else if (section_is_p (sectp
->name
, &names
.line
))
1910 this->line
.s
.section
= sectp
;
1911 this->line
.size
= bfd_section_size (sectp
);
1913 else if (section_is_p (sectp
->name
, &names
.loc
))
1915 this->loc
.s
.section
= sectp
;
1916 this->loc
.size
= bfd_section_size (sectp
);
1918 else if (section_is_p (sectp
->name
, &names
.loclists
))
1920 this->loclists
.s
.section
= sectp
;
1921 this->loclists
.size
= bfd_section_size (sectp
);
1923 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1925 this->macinfo
.s
.section
= sectp
;
1926 this->macinfo
.size
= bfd_section_size (sectp
);
1928 else if (section_is_p (sectp
->name
, &names
.macro
))
1930 this->macro
.s
.section
= sectp
;
1931 this->macro
.size
= bfd_section_size (sectp
);
1933 else if (section_is_p (sectp
->name
, &names
.str
))
1935 this->str
.s
.section
= sectp
;
1936 this->str
.size
= bfd_section_size (sectp
);
1938 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1940 this->str_offsets
.s
.section
= sectp
;
1941 this->str_offsets
.size
= bfd_section_size (sectp
);
1943 else if (section_is_p (sectp
->name
, &names
.line_str
))
1945 this->line_str
.s
.section
= sectp
;
1946 this->line_str
.size
= bfd_section_size (sectp
);
1948 else if (section_is_p (sectp
->name
, &names
.addr
))
1950 this->addr
.s
.section
= sectp
;
1951 this->addr
.size
= bfd_section_size (sectp
);
1953 else if (section_is_p (sectp
->name
, &names
.frame
))
1955 this->frame
.s
.section
= sectp
;
1956 this->frame
.size
= bfd_section_size (sectp
);
1958 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1960 this->eh_frame
.s
.section
= sectp
;
1961 this->eh_frame
.size
= bfd_section_size (sectp
);
1963 else if (section_is_p (sectp
->name
, &names
.ranges
))
1965 this->ranges
.s
.section
= sectp
;
1966 this->ranges
.size
= bfd_section_size (sectp
);
1968 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1970 this->rnglists
.s
.section
= sectp
;
1971 this->rnglists
.size
= bfd_section_size (sectp
);
1973 else if (section_is_p (sectp
->name
, &names
.types
))
1975 struct dwarf2_section_info type_section
;
1977 memset (&type_section
, 0, sizeof (type_section
));
1978 type_section
.s
.section
= sectp
;
1979 type_section
.size
= bfd_section_size (sectp
);
1981 this->types
.push_back (type_section
);
1983 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1985 this->gdb_index
.s
.section
= sectp
;
1986 this->gdb_index
.size
= bfd_section_size (sectp
);
1988 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1990 this->debug_names
.s
.section
= sectp
;
1991 this->debug_names
.size
= bfd_section_size (sectp
);
1993 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1995 this->debug_aranges
.s
.section
= sectp
;
1996 this->debug_aranges
.size
= bfd_section_size (sectp
);
1999 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2000 && bfd_section_vma (sectp
) == 0)
2001 this->has_section_at_zero
= true;
2004 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2008 dwarf2_get_section_info (struct objfile
*objfile
,
2009 enum dwarf2_section_enum sect
,
2010 asection
**sectp
, const gdb_byte
**bufp
,
2011 bfd_size_type
*sizep
)
2013 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2014 struct dwarf2_section_info
*info
;
2016 /* We may see an objfile without any DWARF, in which case we just
2027 case DWARF2_DEBUG_FRAME
:
2028 info
= &data
->frame
;
2030 case DWARF2_EH_FRAME
:
2031 info
= &data
->eh_frame
;
2034 gdb_assert_not_reached ("unexpected section");
2037 info
->read (objfile
);
2039 *sectp
= info
->get_bfd_section ();
2040 *bufp
= info
->buffer
;
2041 *sizep
= info
->size
;
2044 /* A helper function to find the sections for a .dwz file. */
2047 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2049 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2051 /* Note that we only support the standard ELF names, because .dwz
2052 is ELF-only (at the time of writing). */
2053 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2055 dwz_file
->abbrev
.s
.section
= sectp
;
2056 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2058 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2060 dwz_file
->info
.s
.section
= sectp
;
2061 dwz_file
->info
.size
= bfd_section_size (sectp
);
2063 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2065 dwz_file
->str
.s
.section
= sectp
;
2066 dwz_file
->str
.size
= bfd_section_size (sectp
);
2068 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2070 dwz_file
->line
.s
.section
= sectp
;
2071 dwz_file
->line
.size
= bfd_section_size (sectp
);
2073 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2075 dwz_file
->macro
.s
.section
= sectp
;
2076 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2078 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2080 dwz_file
->gdb_index
.s
.section
= sectp
;
2081 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2083 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2085 dwz_file
->debug_names
.s
.section
= sectp
;
2086 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2090 /* See dwarf2read.h. */
2093 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2095 const char *filename
;
2096 bfd_size_type buildid_len_arg
;
2100 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2101 return dwarf2_per_objfile
->dwz_file
.get ();
2103 bfd_set_error (bfd_error_no_error
);
2104 gdb::unique_xmalloc_ptr
<char> data
2105 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2106 &buildid_len_arg
, &buildid
));
2109 if (bfd_get_error () == bfd_error_no_error
)
2111 error (_("could not read '.gnu_debugaltlink' section: %s"),
2112 bfd_errmsg (bfd_get_error ()));
2115 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2117 buildid_len
= (size_t) buildid_len_arg
;
2119 filename
= data
.get ();
2121 std::string abs_storage
;
2122 if (!IS_ABSOLUTE_PATH (filename
))
2124 gdb::unique_xmalloc_ptr
<char> abs
2125 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2127 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2128 filename
= abs_storage
.c_str ();
2131 /* First try the file name given in the section. If that doesn't
2132 work, try to use the build-id instead. */
2133 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2134 if (dwz_bfd
!= NULL
)
2136 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2137 dwz_bfd
.reset (nullptr);
2140 if (dwz_bfd
== NULL
)
2141 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2143 if (dwz_bfd
== nullptr)
2145 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2146 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2148 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2155 /* File successfully retrieved from server. */
2156 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2158 if (dwz_bfd
== nullptr)
2159 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2160 alt_filename
.get ());
2161 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2162 dwz_bfd
.reset (nullptr);
2166 if (dwz_bfd
== NULL
)
2167 error (_("could not find '.gnu_debugaltlink' file for %s"),
2168 objfile_name (dwarf2_per_objfile
->objfile
));
2170 std::unique_ptr
<struct dwz_file
> result
2171 (new struct dwz_file (std::move (dwz_bfd
)));
2173 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2176 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2177 result
->dwz_bfd
.get ());
2178 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2179 return dwarf2_per_objfile
->dwz_file
.get ();
2182 /* DWARF quick_symbols_functions support. */
2184 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2185 unique line tables, so we maintain a separate table of all .debug_line
2186 derived entries to support the sharing.
2187 All the quick functions need is the list of file names. We discard the
2188 line_header when we're done and don't need to record it here. */
2189 struct quick_file_names
2191 /* The data used to construct the hash key. */
2192 struct stmt_list_hash hash
;
2194 /* The number of entries in file_names, real_names. */
2195 unsigned int num_file_names
;
2197 /* The file names from the line table, after being run through
2199 const char **file_names
;
2201 /* The file names from the line table after being run through
2202 gdb_realpath. These are computed lazily. */
2203 const char **real_names
;
2206 /* When using the index (and thus not using psymtabs), each CU has an
2207 object of this type. This is used to hold information needed by
2208 the various "quick" methods. */
2209 struct dwarf2_per_cu_quick_data
2211 /* The file table. This can be NULL if there was no file table
2212 or it's currently not read in.
2213 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2214 struct quick_file_names
*file_names
;
2216 /* The corresponding symbol table. This is NULL if symbols for this
2217 CU have not yet been read. */
2218 struct compunit_symtab
*compunit_symtab
;
2220 /* A temporary mark bit used when iterating over all CUs in
2221 expand_symtabs_matching. */
2222 unsigned int mark
: 1;
2224 /* True if we've tried to read the file table and found there isn't one.
2225 There will be no point in trying to read it again next time. */
2226 unsigned int no_file_data
: 1;
2229 /* Utility hash function for a stmt_list_hash. */
2232 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2236 if (stmt_list_hash
->dwo_unit
!= NULL
)
2237 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2238 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2242 /* Utility equality function for a stmt_list_hash. */
2245 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2246 const struct stmt_list_hash
*rhs
)
2248 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2250 if (lhs
->dwo_unit
!= NULL
2251 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2254 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2257 /* Hash function for a quick_file_names. */
2260 hash_file_name_entry (const void *e
)
2262 const struct quick_file_names
*file_data
2263 = (const struct quick_file_names
*) e
;
2265 return hash_stmt_list_entry (&file_data
->hash
);
2268 /* Equality function for a quick_file_names. */
2271 eq_file_name_entry (const void *a
, const void *b
)
2273 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2274 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2276 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2279 /* Delete function for a quick_file_names. */
2282 delete_file_name_entry (void *e
)
2284 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2287 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2289 xfree ((void*) file_data
->file_names
[i
]);
2290 if (file_data
->real_names
)
2291 xfree ((void*) file_data
->real_names
[i
]);
2294 /* The space for the struct itself lives on objfile_obstack,
2295 so we don't free it here. */
2298 /* Create a quick_file_names hash table. */
2301 create_quick_file_names_table (unsigned int nr_initial_entries
)
2303 return htab_up (htab_create_alloc (nr_initial_entries
,
2304 hash_file_name_entry
, eq_file_name_entry
,
2305 delete_file_name_entry
, xcalloc
, xfree
));
2308 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2309 have to be created afterwards. You should call age_cached_comp_units after
2310 processing PER_CU->CU. dw2_setup must have been already called. */
2313 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2315 if (per_cu
->is_debug_types
)
2316 load_full_type_unit (per_cu
);
2318 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2320 if (per_cu
->cu
== NULL
)
2321 return; /* Dummy CU. */
2323 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2326 /* Read in the symbols for PER_CU. */
2329 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2331 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2333 /* Skip type_unit_groups, reading the type units they contain
2334 is handled elsewhere. */
2335 if (per_cu
->type_unit_group_p ())
2338 /* The destructor of dwarf2_queue_guard frees any entries left on
2339 the queue. After this point we're guaranteed to leave this function
2340 with the dwarf queue empty. */
2341 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2343 if (dwarf2_per_objfile
->using_index
2344 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2345 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2347 queue_comp_unit (per_cu
, language_minimal
);
2348 load_cu (per_cu
, skip_partial
);
2350 /* If we just loaded a CU from a DWO, and we're working with an index
2351 that may badly handle TUs, load all the TUs in that DWO as well.
2352 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2353 if (!per_cu
->is_debug_types
2354 && per_cu
->cu
!= NULL
2355 && per_cu
->cu
->dwo_unit
!= NULL
2356 && dwarf2_per_objfile
->index_table
!= NULL
2357 && dwarf2_per_objfile
->index_table
->version
<= 7
2358 /* DWP files aren't supported yet. */
2359 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2360 queue_and_load_all_dwo_tus (per_cu
);
2363 process_queue (dwarf2_per_objfile
);
2365 /* Age the cache, releasing compilation units that have not
2366 been used recently. */
2367 age_cached_comp_units (dwarf2_per_objfile
);
2370 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2371 the objfile from which this CU came. Returns the resulting symbol
2374 static struct compunit_symtab
*
2375 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2377 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2379 gdb_assert (dwarf2_per_objfile
->using_index
);
2380 if (!per_cu
->v
.quick
->compunit_symtab
)
2382 free_cached_comp_units
freer (dwarf2_per_objfile
);
2383 scoped_restore decrementer
= increment_reading_symtab ();
2384 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2385 process_cu_includes (dwarf2_per_objfile
);
2388 return per_cu
->v
.quick
->compunit_symtab
;
2391 /* See declaration. */
2393 dwarf2_per_cu_data
*
2394 dwarf2_per_objfile::get_cutu (int index
)
2396 if (index
>= this->all_comp_units
.size ())
2398 index
-= this->all_comp_units
.size ();
2399 gdb_assert (index
< this->all_type_units
.size ());
2400 return &this->all_type_units
[index
]->per_cu
;
2403 return this->all_comp_units
[index
];
2406 /* See declaration. */
2408 dwarf2_per_cu_data
*
2409 dwarf2_per_objfile::get_cu (int index
)
2411 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2413 return this->all_comp_units
[index
];
2416 /* See declaration. */
2419 dwarf2_per_objfile::get_tu (int index
)
2421 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2423 return this->all_type_units
[index
];
2426 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2427 objfile_obstack, and constructed with the specified field
2430 static dwarf2_per_cu_data
*
2431 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2432 struct dwarf2_section_info
*section
,
2434 sect_offset sect_off
, ULONGEST length
)
2436 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2437 dwarf2_per_cu_data
*the_cu
2438 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2439 struct dwarf2_per_cu_data
);
2440 the_cu
->sect_off
= sect_off
;
2441 the_cu
->length
= length
;
2442 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2443 the_cu
->section
= section
;
2444 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2445 struct dwarf2_per_cu_quick_data
);
2446 the_cu
->is_dwz
= is_dwz
;
2450 /* A helper for create_cus_from_index that handles a given list of
2454 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2455 const gdb_byte
*cu_list
, offset_type n_elements
,
2456 struct dwarf2_section_info
*section
,
2459 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2461 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2463 sect_offset sect_off
2464 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2465 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2468 dwarf2_per_cu_data
*per_cu
2469 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2471 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2475 /* Read the CU list from the mapped index, and use it to create all
2476 the CU objects for this objfile. */
2479 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2480 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2481 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2483 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2484 dwarf2_per_objfile
->all_comp_units
.reserve
2485 ((cu_list_elements
+ dwz_elements
) / 2);
2487 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2488 &dwarf2_per_objfile
->info
, 0);
2490 if (dwz_elements
== 0)
2493 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2494 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2498 /* Create the signatured type hash table from the index. */
2501 create_signatured_type_table_from_index
2502 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2503 struct dwarf2_section_info
*section
,
2504 const gdb_byte
*bytes
,
2505 offset_type elements
)
2507 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2509 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2510 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2512 htab_up sig_types_hash
= allocate_signatured_type_table ();
2514 for (offset_type i
= 0; i
< elements
; i
+= 3)
2516 struct signatured_type
*sig_type
;
2519 cu_offset type_offset_in_tu
;
2521 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2522 sect_offset sect_off
2523 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2525 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2527 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2530 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2531 struct signatured_type
);
2532 sig_type
->signature
= signature
;
2533 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2534 sig_type
->per_cu
.is_debug_types
= 1;
2535 sig_type
->per_cu
.section
= section
;
2536 sig_type
->per_cu
.sect_off
= sect_off
;
2537 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2538 sig_type
->per_cu
.v
.quick
2539 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2540 struct dwarf2_per_cu_quick_data
);
2542 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2545 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2548 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2551 /* Create the signatured type hash table from .debug_names. */
2554 create_signatured_type_table_from_debug_names
2555 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2556 const mapped_debug_names
&map
,
2557 struct dwarf2_section_info
*section
,
2558 struct dwarf2_section_info
*abbrev_section
)
2560 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2562 section
->read (objfile
);
2563 abbrev_section
->read (objfile
);
2565 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2566 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2568 htab_up sig_types_hash
= allocate_signatured_type_table ();
2570 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2572 struct signatured_type
*sig_type
;
2575 sect_offset sect_off
2576 = (sect_offset
) (extract_unsigned_integer
2577 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2579 map
.dwarf5_byte_order
));
2581 comp_unit_head cu_header
;
2582 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2584 section
->buffer
+ to_underlying (sect_off
),
2587 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2588 struct signatured_type
);
2589 sig_type
->signature
= cu_header
.signature
;
2590 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2591 sig_type
->per_cu
.is_debug_types
= 1;
2592 sig_type
->per_cu
.section
= section
;
2593 sig_type
->per_cu
.sect_off
= sect_off
;
2594 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2595 sig_type
->per_cu
.v
.quick
2596 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2597 struct dwarf2_per_cu_quick_data
);
2599 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2602 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2605 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2608 /* Read the address map data from the mapped index, and use it to
2609 populate the objfile's psymtabs_addrmap. */
2612 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2613 struct mapped_index
*index
)
2615 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2616 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2617 const gdb_byte
*iter
, *end
;
2618 struct addrmap
*mutable_map
;
2621 auto_obstack temp_obstack
;
2623 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2625 iter
= index
->address_table
.data ();
2626 end
= iter
+ index
->address_table
.size ();
2628 baseaddr
= objfile
->text_section_offset ();
2632 ULONGEST hi
, lo
, cu_index
;
2633 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2635 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2637 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2642 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2643 hex_string (lo
), hex_string (hi
));
2647 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2649 complaint (_(".gdb_index address table has invalid CU number %u"),
2650 (unsigned) cu_index
);
2654 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2655 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2656 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2657 dwarf2_per_objfile
->get_cu (cu_index
));
2660 objfile
->partial_symtabs
->psymtabs_addrmap
2661 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2664 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2665 populate the objfile's psymtabs_addrmap. */
2668 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2669 struct dwarf2_section_info
*section
)
2671 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2672 bfd
*abfd
= objfile
->obfd
;
2673 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2674 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2676 auto_obstack temp_obstack
;
2677 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2679 std::unordered_map
<sect_offset
,
2680 dwarf2_per_cu_data
*,
2681 gdb::hash_enum
<sect_offset
>>
2682 debug_info_offset_to_per_cu
;
2683 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2685 const auto insertpair
2686 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2687 if (!insertpair
.second
)
2689 warning (_("Section .debug_aranges in %s has duplicate "
2690 "debug_info_offset %s, ignoring .debug_aranges."),
2691 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2696 section
->read (objfile
);
2698 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2700 const gdb_byte
*addr
= section
->buffer
;
2702 while (addr
< section
->buffer
+ section
->size
)
2704 const gdb_byte
*const entry_addr
= addr
;
2705 unsigned int bytes_read
;
2707 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2711 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2712 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2713 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2714 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2716 warning (_("Section .debug_aranges in %s entry at offset %s "
2717 "length %s exceeds section length %s, "
2718 "ignoring .debug_aranges."),
2719 objfile_name (objfile
),
2720 plongest (entry_addr
- section
->buffer
),
2721 plongest (bytes_read
+ entry_length
),
2722 pulongest (section
->size
));
2726 /* The version number. */
2727 const uint16_t version
= read_2_bytes (abfd
, addr
);
2731 warning (_("Section .debug_aranges in %s entry at offset %s "
2732 "has unsupported version %d, ignoring .debug_aranges."),
2733 objfile_name (objfile
),
2734 plongest (entry_addr
- section
->buffer
), version
);
2738 const uint64_t debug_info_offset
2739 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2740 addr
+= offset_size
;
2741 const auto per_cu_it
2742 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2743 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2745 warning (_("Section .debug_aranges in %s entry at offset %s "
2746 "debug_info_offset %s does not exists, "
2747 "ignoring .debug_aranges."),
2748 objfile_name (objfile
),
2749 plongest (entry_addr
- section
->buffer
),
2750 pulongest (debug_info_offset
));
2753 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2755 const uint8_t address_size
= *addr
++;
2756 if (address_size
< 1 || address_size
> 8)
2758 warning (_("Section .debug_aranges in %s entry at offset %s "
2759 "address_size %u is invalid, ignoring .debug_aranges."),
2760 objfile_name (objfile
),
2761 plongest (entry_addr
- section
->buffer
), address_size
);
2765 const uint8_t segment_selector_size
= *addr
++;
2766 if (segment_selector_size
!= 0)
2768 warning (_("Section .debug_aranges in %s entry at offset %s "
2769 "segment_selector_size %u is not supported, "
2770 "ignoring .debug_aranges."),
2771 objfile_name (objfile
),
2772 plongest (entry_addr
- section
->buffer
),
2773 segment_selector_size
);
2777 /* Must pad to an alignment boundary that is twice the address
2778 size. It is undocumented by the DWARF standard but GCC does
2780 for (size_t padding
= ((-(addr
- section
->buffer
))
2781 & (2 * address_size
- 1));
2782 padding
> 0; padding
--)
2785 warning (_("Section .debug_aranges in %s entry at offset %s "
2786 "padding is not zero, ignoring .debug_aranges."),
2787 objfile_name (objfile
),
2788 plongest (entry_addr
- section
->buffer
));
2794 if (addr
+ 2 * address_size
> entry_end
)
2796 warning (_("Section .debug_aranges in %s entry at offset %s "
2797 "address list is not properly terminated, "
2798 "ignoring .debug_aranges."),
2799 objfile_name (objfile
),
2800 plongest (entry_addr
- section
->buffer
));
2803 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2805 addr
+= address_size
;
2806 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2808 addr
+= address_size
;
2809 if (start
== 0 && length
== 0)
2811 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2813 /* Symbol was eliminated due to a COMDAT group. */
2816 ULONGEST end
= start
+ length
;
2817 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2819 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2821 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2825 objfile
->partial_symtabs
->psymtabs_addrmap
2826 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2829 /* Find a slot in the mapped index INDEX for the object named NAME.
2830 If NAME is found, set *VEC_OUT to point to the CU vector in the
2831 constant pool and return true. If NAME cannot be found, return
2835 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2836 offset_type
**vec_out
)
2839 offset_type slot
, step
;
2840 int (*cmp
) (const char *, const char *);
2842 gdb::unique_xmalloc_ptr
<char> without_params
;
2843 if (current_language
->la_language
== language_cplus
2844 || current_language
->la_language
== language_fortran
2845 || current_language
->la_language
== language_d
)
2847 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2850 if (strchr (name
, '(') != NULL
)
2852 without_params
= cp_remove_params (name
);
2854 if (without_params
!= NULL
)
2855 name
= without_params
.get ();
2859 /* Index version 4 did not support case insensitive searches. But the
2860 indices for case insensitive languages are built in lowercase, therefore
2861 simulate our NAME being searched is also lowercased. */
2862 hash
= mapped_index_string_hash ((index
->version
== 4
2863 && case_sensitivity
== case_sensitive_off
2864 ? 5 : index
->version
),
2867 slot
= hash
& (index
->symbol_table
.size () - 1);
2868 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2869 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2875 const auto &bucket
= index
->symbol_table
[slot
];
2876 if (bucket
.name
== 0 && bucket
.vec
== 0)
2879 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2880 if (!cmp (name
, str
))
2882 *vec_out
= (offset_type
*) (index
->constant_pool
2883 + MAYBE_SWAP (bucket
.vec
));
2887 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2891 /* A helper function that reads the .gdb_index from BUFFER and fills
2892 in MAP. FILENAME is the name of the file containing the data;
2893 it is used for error reporting. DEPRECATED_OK is true if it is
2894 ok to use deprecated sections.
2896 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2897 out parameters that are filled in with information about the CU and
2898 TU lists in the section.
2900 Returns true if all went well, false otherwise. */
2903 read_gdb_index_from_buffer (struct objfile
*objfile
,
2904 const char *filename
,
2906 gdb::array_view
<const gdb_byte
> buffer
,
2907 struct mapped_index
*map
,
2908 const gdb_byte
**cu_list
,
2909 offset_type
*cu_list_elements
,
2910 const gdb_byte
**types_list
,
2911 offset_type
*types_list_elements
)
2913 const gdb_byte
*addr
= &buffer
[0];
2915 /* Version check. */
2916 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2917 /* Versions earlier than 3 emitted every copy of a psymbol. This
2918 causes the index to behave very poorly for certain requests. Version 3
2919 contained incomplete addrmap. So, it seems better to just ignore such
2923 static int warning_printed
= 0;
2924 if (!warning_printed
)
2926 warning (_("Skipping obsolete .gdb_index section in %s."),
2928 warning_printed
= 1;
2932 /* Index version 4 uses a different hash function than index version
2935 Versions earlier than 6 did not emit psymbols for inlined
2936 functions. Using these files will cause GDB not to be able to
2937 set breakpoints on inlined functions by name, so we ignore these
2938 indices unless the user has done
2939 "set use-deprecated-index-sections on". */
2940 if (version
< 6 && !deprecated_ok
)
2942 static int warning_printed
= 0;
2943 if (!warning_printed
)
2946 Skipping deprecated .gdb_index section in %s.\n\
2947 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2948 to use the section anyway."),
2950 warning_printed
= 1;
2954 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2955 of the TU (for symbols coming from TUs),
2956 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2957 Plus gold-generated indices can have duplicate entries for global symbols,
2958 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2959 These are just performance bugs, and we can't distinguish gdb-generated
2960 indices from gold-generated ones, so issue no warning here. */
2962 /* Indexes with higher version than the one supported by GDB may be no
2963 longer backward compatible. */
2967 map
->version
= version
;
2969 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2972 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2973 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2977 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2978 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2979 - MAYBE_SWAP (metadata
[i
]))
2983 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2984 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2986 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2989 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2990 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2992 = gdb::array_view
<mapped_index::symbol_table_slot
>
2993 ((mapped_index::symbol_table_slot
*) symbol_table
,
2994 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2997 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3002 /* Callback types for dwarf2_read_gdb_index. */
3004 typedef gdb::function_view
3005 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3006 get_gdb_index_contents_ftype
;
3007 typedef gdb::function_view
3008 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3009 get_gdb_index_contents_dwz_ftype
;
3011 /* Read .gdb_index. If everything went ok, initialize the "quick"
3012 elements of all the CUs and return 1. Otherwise, return 0. */
3015 dwarf2_read_gdb_index
3016 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3017 get_gdb_index_contents_ftype get_gdb_index_contents
,
3018 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3020 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3021 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3022 struct dwz_file
*dwz
;
3023 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3025 gdb::array_view
<const gdb_byte
> main_index_contents
3026 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3028 if (main_index_contents
.empty ())
3031 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3032 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3033 use_deprecated_index_sections
,
3034 main_index_contents
, map
.get (), &cu_list
,
3035 &cu_list_elements
, &types_list
,
3036 &types_list_elements
))
3039 /* Don't use the index if it's empty. */
3040 if (map
->symbol_table
.empty ())
3043 /* If there is a .dwz file, read it so we can get its CU list as
3045 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3048 struct mapped_index dwz_map
;
3049 const gdb_byte
*dwz_types_ignore
;
3050 offset_type dwz_types_elements_ignore
;
3052 gdb::array_view
<const gdb_byte
> dwz_index_content
3053 = get_gdb_index_contents_dwz (objfile
, dwz
);
3055 if (dwz_index_content
.empty ())
3058 if (!read_gdb_index_from_buffer (objfile
,
3059 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3060 1, dwz_index_content
, &dwz_map
,
3061 &dwz_list
, &dwz_list_elements
,
3063 &dwz_types_elements_ignore
))
3065 warning (_("could not read '.gdb_index' section from %s; skipping"),
3066 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3071 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3072 dwz_list
, dwz_list_elements
);
3074 if (types_list_elements
)
3076 /* We can only handle a single .debug_types when we have an
3078 if (dwarf2_per_objfile
->types
.size () != 1)
3081 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3083 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3084 types_list
, types_list_elements
);
3087 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3089 dwarf2_per_objfile
->index_table
= std::move (map
);
3090 dwarf2_per_objfile
->using_index
= 1;
3091 dwarf2_per_objfile
->quick_file_names_table
=
3092 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3097 /* die_reader_func for dw2_get_file_names. */
3100 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3101 const gdb_byte
*info_ptr
,
3102 struct die_info
*comp_unit_die
)
3104 struct dwarf2_cu
*cu
= reader
->cu
;
3105 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3106 struct dwarf2_per_objfile
*dwarf2_per_objfile
3107 = cu
->per_cu
->dwarf2_per_objfile
;
3108 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3109 struct dwarf2_per_cu_data
*lh_cu
;
3110 struct attribute
*attr
;
3112 struct quick_file_names
*qfn
;
3114 gdb_assert (! this_cu
->is_debug_types
);
3116 /* Our callers never want to match partial units -- instead they
3117 will match the enclosing full CU. */
3118 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3120 this_cu
->v
.quick
->no_file_data
= 1;
3128 sect_offset line_offset
{};
3130 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3131 if (attr
!= nullptr)
3133 struct quick_file_names find_entry
;
3135 line_offset
= (sect_offset
) DW_UNSND (attr
);
3137 /* We may have already read in this line header (TU line header sharing).
3138 If we have we're done. */
3139 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3140 find_entry
.hash
.line_sect_off
= line_offset
;
3141 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3142 &find_entry
, INSERT
);
3145 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3149 lh
= dwarf_decode_line_header (line_offset
, cu
);
3153 lh_cu
->v
.quick
->no_file_data
= 1;
3157 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3158 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3159 qfn
->hash
.line_sect_off
= line_offset
;
3160 gdb_assert (slot
!= NULL
);
3163 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3166 if (strcmp (fnd
.name
, "<unknown>") != 0)
3169 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3171 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3173 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3174 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3175 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3176 fnd
.comp_dir
).release ();
3177 qfn
->real_names
= NULL
;
3179 lh_cu
->v
.quick
->file_names
= qfn
;
3182 /* A helper for the "quick" functions which attempts to read the line
3183 table for THIS_CU. */
3185 static struct quick_file_names
*
3186 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3188 /* This should never be called for TUs. */
3189 gdb_assert (! this_cu
->is_debug_types
);
3190 /* Nor type unit groups. */
3191 gdb_assert (! this_cu
->type_unit_group_p ());
3193 if (this_cu
->v
.quick
->file_names
!= NULL
)
3194 return this_cu
->v
.quick
->file_names
;
3195 /* If we know there is no line data, no point in looking again. */
3196 if (this_cu
->v
.quick
->no_file_data
)
3199 cutu_reader
reader (this_cu
);
3200 if (!reader
.dummy_p
)
3201 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3203 if (this_cu
->v
.quick
->no_file_data
)
3205 return this_cu
->v
.quick
->file_names
;
3208 /* A helper for the "quick" functions which computes and caches the
3209 real path for a given file name from the line table. */
3212 dw2_get_real_path (struct objfile
*objfile
,
3213 struct quick_file_names
*qfn
, int index
)
3215 if (qfn
->real_names
== NULL
)
3216 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3217 qfn
->num_file_names
, const char *);
3219 if (qfn
->real_names
[index
] == NULL
)
3220 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3222 return qfn
->real_names
[index
];
3225 static struct symtab
*
3226 dw2_find_last_source_symtab (struct objfile
*objfile
)
3228 struct dwarf2_per_objfile
*dwarf2_per_objfile
3229 = get_dwarf2_per_objfile (objfile
);
3230 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3231 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3236 return compunit_primary_filetab (cust
);
3239 /* Traversal function for dw2_forget_cached_source_info. */
3242 dw2_free_cached_file_names (void **slot
, void *info
)
3244 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3246 if (file_data
->real_names
)
3250 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3252 xfree ((void*) file_data
->real_names
[i
]);
3253 file_data
->real_names
[i
] = NULL
;
3261 dw2_forget_cached_source_info (struct objfile
*objfile
)
3263 struct dwarf2_per_objfile
*dwarf2_per_objfile
3264 = get_dwarf2_per_objfile (objfile
);
3266 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3267 dw2_free_cached_file_names
, NULL
);
3270 /* Helper function for dw2_map_symtabs_matching_filename that expands
3271 the symtabs and calls the iterator. */
3274 dw2_map_expand_apply (struct objfile
*objfile
,
3275 struct dwarf2_per_cu_data
*per_cu
,
3276 const char *name
, const char *real_path
,
3277 gdb::function_view
<bool (symtab
*)> callback
)
3279 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3281 /* Don't visit already-expanded CUs. */
3282 if (per_cu
->v
.quick
->compunit_symtab
)
3285 /* This may expand more than one symtab, and we want to iterate over
3287 dw2_instantiate_symtab (per_cu
, false);
3289 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3290 last_made
, callback
);
3293 /* Implementation of the map_symtabs_matching_filename method. */
3296 dw2_map_symtabs_matching_filename
3297 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3298 gdb::function_view
<bool (symtab
*)> callback
)
3300 const char *name_basename
= lbasename (name
);
3301 struct dwarf2_per_objfile
*dwarf2_per_objfile
3302 = get_dwarf2_per_objfile (objfile
);
3304 /* The rule is CUs specify all the files, including those used by
3305 any TU, so there's no need to scan TUs here. */
3307 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3309 /* We only need to look at symtabs not already expanded. */
3310 if (per_cu
->v
.quick
->compunit_symtab
)
3313 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3314 if (file_data
== NULL
)
3317 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3319 const char *this_name
= file_data
->file_names
[j
];
3320 const char *this_real_name
;
3322 if (compare_filenames_for_search (this_name
, name
))
3324 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3330 /* Before we invoke realpath, which can get expensive when many
3331 files are involved, do a quick comparison of the basenames. */
3332 if (! basenames_may_differ
3333 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3336 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3337 if (compare_filenames_for_search (this_real_name
, name
))
3339 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3345 if (real_path
!= NULL
)
3347 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3348 gdb_assert (IS_ABSOLUTE_PATH (name
));
3349 if (this_real_name
!= NULL
3350 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3352 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3364 /* Struct used to manage iterating over all CUs looking for a symbol. */
3366 struct dw2_symtab_iterator
3368 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3369 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3370 /* If set, only look for symbols that match that block. Valid values are
3371 GLOBAL_BLOCK and STATIC_BLOCK. */
3372 gdb::optional
<block_enum
> block_index
;
3373 /* The kind of symbol we're looking for. */
3375 /* The list of CUs from the index entry of the symbol,
3376 or NULL if not found. */
3378 /* The next element in VEC to look at. */
3380 /* The number of elements in VEC, or zero if there is no match. */
3382 /* Have we seen a global version of the symbol?
3383 If so we can ignore all further global instances.
3384 This is to work around gold/15646, inefficient gold-generated
3389 /* Initialize the index symtab iterator ITER. */
3392 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3393 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3394 gdb::optional
<block_enum
> block_index
,
3398 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3399 iter
->block_index
= block_index
;
3400 iter
->domain
= domain
;
3402 iter
->global_seen
= 0;
3404 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3406 /* index is NULL if OBJF_READNOW. */
3407 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3408 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3416 /* Return the next matching CU or NULL if there are no more. */
3418 static struct dwarf2_per_cu_data
*
3419 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3421 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3423 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3425 offset_type cu_index_and_attrs
=
3426 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3427 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3428 gdb_index_symbol_kind symbol_kind
=
3429 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3430 /* Only check the symbol attributes if they're present.
3431 Indices prior to version 7 don't record them,
3432 and indices >= 7 may elide them for certain symbols
3433 (gold does this). */
3435 (dwarf2_per_objfile
->index_table
->version
>= 7
3436 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3438 /* Don't crash on bad data. */
3439 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3440 + dwarf2_per_objfile
->all_type_units
.size ()))
3442 complaint (_(".gdb_index entry has bad CU index"
3444 objfile_name (dwarf2_per_objfile
->objfile
));
3448 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3450 /* Skip if already read in. */
3451 if (per_cu
->v
.quick
->compunit_symtab
)
3454 /* Check static vs global. */
3457 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3459 if (iter
->block_index
.has_value ())
3461 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3463 if (is_static
!= want_static
)
3467 /* Work around gold/15646. */
3468 if (!is_static
&& iter
->global_seen
)
3471 iter
->global_seen
= 1;
3474 /* Only check the symbol's kind if it has one. */
3477 switch (iter
->domain
)
3480 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3481 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3482 /* Some types are also in VAR_DOMAIN. */
3483 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3487 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3491 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3495 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3510 static struct compunit_symtab
*
3511 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3512 const char *name
, domain_enum domain
)
3514 struct compunit_symtab
*stab_best
= NULL
;
3515 struct dwarf2_per_objfile
*dwarf2_per_objfile
3516 = get_dwarf2_per_objfile (objfile
);
3518 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3520 struct dw2_symtab_iterator iter
;
3521 struct dwarf2_per_cu_data
*per_cu
;
3523 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3525 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3527 struct symbol
*sym
, *with_opaque
= NULL
;
3528 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3529 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3530 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3532 sym
= block_find_symbol (block
, name
, domain
,
3533 block_find_non_opaque_type_preferred
,
3536 /* Some caution must be observed with overloaded functions
3537 and methods, since the index will not contain any overload
3538 information (but NAME might contain it). */
3541 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3543 if (with_opaque
!= NULL
3544 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3547 /* Keep looking through other CUs. */
3554 dw2_print_stats (struct objfile
*objfile
)
3556 struct dwarf2_per_objfile
*dwarf2_per_objfile
3557 = get_dwarf2_per_objfile (objfile
);
3558 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3559 + dwarf2_per_objfile
->all_type_units
.size ());
3562 for (int i
= 0; i
< total
; ++i
)
3564 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3566 if (!per_cu
->v
.quick
->compunit_symtab
)
3569 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3570 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3573 /* This dumps minimal information about the index.
3574 It is called via "mt print objfiles".
3575 One use is to verify .gdb_index has been loaded by the
3576 gdb.dwarf2/gdb-index.exp testcase. */
3579 dw2_dump (struct objfile
*objfile
)
3581 struct dwarf2_per_objfile
*dwarf2_per_objfile
3582 = get_dwarf2_per_objfile (objfile
);
3584 gdb_assert (dwarf2_per_objfile
->using_index
);
3585 printf_filtered (".gdb_index:");
3586 if (dwarf2_per_objfile
->index_table
!= NULL
)
3588 printf_filtered (" version %d\n",
3589 dwarf2_per_objfile
->index_table
->version
);
3592 printf_filtered (" faked for \"readnow\"\n");
3593 printf_filtered ("\n");
3597 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3598 const char *func_name
)
3600 struct dwarf2_per_objfile
*dwarf2_per_objfile
3601 = get_dwarf2_per_objfile (objfile
);
3603 struct dw2_symtab_iterator iter
;
3604 struct dwarf2_per_cu_data
*per_cu
;
3606 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3608 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3609 dw2_instantiate_symtab (per_cu
, false);
3614 dw2_expand_all_symtabs (struct objfile
*objfile
)
3616 struct dwarf2_per_objfile
*dwarf2_per_objfile
3617 = get_dwarf2_per_objfile (objfile
);
3618 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3619 + dwarf2_per_objfile
->all_type_units
.size ());
3621 for (int i
= 0; i
< total_units
; ++i
)
3623 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3625 /* We don't want to directly expand a partial CU, because if we
3626 read it with the wrong language, then assertion failures can
3627 be triggered later on. See PR symtab/23010. So, tell
3628 dw2_instantiate_symtab to skip partial CUs -- any important
3629 partial CU will be read via DW_TAG_imported_unit anyway. */
3630 dw2_instantiate_symtab (per_cu
, true);
3635 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3636 const char *fullname
)
3638 struct dwarf2_per_objfile
*dwarf2_per_objfile
3639 = get_dwarf2_per_objfile (objfile
);
3641 /* We don't need to consider type units here.
3642 This is only called for examining code, e.g. expand_line_sal.
3643 There can be an order of magnitude (or more) more type units
3644 than comp units, and we avoid them if we can. */
3646 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3648 /* We only need to look at symtabs not already expanded. */
3649 if (per_cu
->v
.quick
->compunit_symtab
)
3652 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3653 if (file_data
== NULL
)
3656 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3658 const char *this_fullname
= file_data
->file_names
[j
];
3660 if (filename_cmp (this_fullname
, fullname
) == 0)
3662 dw2_instantiate_symtab (per_cu
, false);
3670 dw2_map_matching_symbols
3671 (struct objfile
*objfile
,
3672 const lookup_name_info
&name
, domain_enum domain
,
3674 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3675 symbol_compare_ftype
*ordered_compare
)
3677 /* Currently unimplemented; used for Ada. The function can be called if the
3678 current language is Ada for a non-Ada objfile using GNU index. As Ada
3679 does not look for non-Ada symbols this function should just return. */
3682 /* Starting from a search name, return the string that finds the upper
3683 bound of all strings that start with SEARCH_NAME in a sorted name
3684 list. Returns the empty string to indicate that the upper bound is
3685 the end of the list. */
3688 make_sort_after_prefix_name (const char *search_name
)
3690 /* When looking to complete "func", we find the upper bound of all
3691 symbols that start with "func" by looking for where we'd insert
3692 the closest string that would follow "func" in lexicographical
3693 order. Usually, that's "func"-with-last-character-incremented,
3694 i.e. "fund". Mind non-ASCII characters, though. Usually those
3695 will be UTF-8 multi-byte sequences, but we can't be certain.
3696 Especially mind the 0xff character, which is a valid character in
3697 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3698 rule out compilers allowing it in identifiers. Note that
3699 conveniently, strcmp/strcasecmp are specified to compare
3700 characters interpreted as unsigned char. So what we do is treat
3701 the whole string as a base 256 number composed of a sequence of
3702 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3703 to 0, and carries 1 to the following more-significant position.
3704 If the very first character in SEARCH_NAME ends up incremented
3705 and carries/overflows, then the upper bound is the end of the
3706 list. The string after the empty string is also the empty
3709 Some examples of this operation:
3711 SEARCH_NAME => "+1" RESULT
3715 "\xff" "a" "\xff" => "\xff" "b"
3720 Then, with these symbols for example:
3726 completing "func" looks for symbols between "func" and
3727 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3728 which finds "func" and "func1", but not "fund".
3732 funcÿ (Latin1 'ÿ' [0xff])
3736 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3737 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3741 ÿÿ (Latin1 'ÿ' [0xff])
3744 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3745 the end of the list.
3747 std::string after
= search_name
;
3748 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3750 if (!after
.empty ())
3751 after
.back () = (unsigned char) after
.back () + 1;
3755 /* See declaration. */
3757 std::pair
<std::vector
<name_component
>::const_iterator
,
3758 std::vector
<name_component
>::const_iterator
>
3759 mapped_index_base::find_name_components_bounds
3760 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3763 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3765 const char *lang_name
3766 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3768 /* Comparison function object for lower_bound that matches against a
3769 given symbol name. */
3770 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3773 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3774 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3775 return name_cmp (elem_name
, name
) < 0;
3778 /* Comparison function object for upper_bound that matches against a
3779 given symbol name. */
3780 auto lookup_compare_upper
= [&] (const char *name
,
3781 const name_component
&elem
)
3783 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3784 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3785 return name_cmp (name
, elem_name
) < 0;
3788 auto begin
= this->name_components
.begin ();
3789 auto end
= this->name_components
.end ();
3791 /* Find the lower bound. */
3794 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3797 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3800 /* Find the upper bound. */
3803 if (lookup_name_without_params
.completion_mode ())
3805 /* In completion mode, we want UPPER to point past all
3806 symbols names that have the same prefix. I.e., with
3807 these symbols, and completing "func":
3809 function << lower bound
3811 other_function << upper bound
3813 We find the upper bound by looking for the insertion
3814 point of "func"-with-last-character-incremented,
3816 std::string after
= make_sort_after_prefix_name (lang_name
);
3819 return std::lower_bound (lower
, end
, after
.c_str (),
3820 lookup_compare_lower
);
3823 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3826 return {lower
, upper
};
3829 /* See declaration. */
3832 mapped_index_base::build_name_components ()
3834 if (!this->name_components
.empty ())
3837 this->name_components_casing
= case_sensitivity
;
3839 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3841 /* The code below only knows how to break apart components of C++
3842 symbol names (and other languages that use '::' as
3843 namespace/module separator) and Ada symbol names. */
3844 auto count
= this->symbol_name_count ();
3845 for (offset_type idx
= 0; idx
< count
; idx
++)
3847 if (this->symbol_name_slot_invalid (idx
))
3850 const char *name
= this->symbol_name_at (idx
);
3852 /* Add each name component to the name component table. */
3853 unsigned int previous_len
= 0;
3855 if (strstr (name
, "::") != nullptr)
3857 for (unsigned int current_len
= cp_find_first_component (name
);
3858 name
[current_len
] != '\0';
3859 current_len
+= cp_find_first_component (name
+ current_len
))
3861 gdb_assert (name
[current_len
] == ':');
3862 this->name_components
.push_back ({previous_len
, idx
});
3863 /* Skip the '::'. */
3865 previous_len
= current_len
;
3870 /* Handle the Ada encoded (aka mangled) form here. */
3871 for (const char *iter
= strstr (name
, "__");
3873 iter
= strstr (iter
, "__"))
3875 this->name_components
.push_back ({previous_len
, idx
});
3877 previous_len
= iter
- name
;
3881 this->name_components
.push_back ({previous_len
, idx
});
3884 /* Sort name_components elements by name. */
3885 auto name_comp_compare
= [&] (const name_component
&left
,
3886 const name_component
&right
)
3888 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3889 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3891 const char *left_name
= left_qualified
+ left
.name_offset
;
3892 const char *right_name
= right_qualified
+ right
.name_offset
;
3894 return name_cmp (left_name
, right_name
) < 0;
3897 std::sort (this->name_components
.begin (),
3898 this->name_components
.end (),
3902 /* Helper for dw2_expand_symtabs_matching that works with a
3903 mapped_index_base instead of the containing objfile. This is split
3904 to a separate function in order to be able to unit test the
3905 name_components matching using a mock mapped_index_base. For each
3906 symbol name that matches, calls MATCH_CALLBACK, passing it the
3907 symbol's index in the mapped_index_base symbol table. */
3910 dw2_expand_symtabs_matching_symbol
3911 (mapped_index_base
&index
,
3912 const lookup_name_info
&lookup_name_in
,
3913 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3914 enum search_domain kind
,
3915 gdb::function_view
<bool (offset_type
)> match_callback
)
3917 lookup_name_info lookup_name_without_params
3918 = lookup_name_in
.make_ignore_params ();
3920 /* Build the symbol name component sorted vector, if we haven't
3922 index
.build_name_components ();
3924 /* The same symbol may appear more than once in the range though.
3925 E.g., if we're looking for symbols that complete "w", and we have
3926 a symbol named "w1::w2", we'll find the two name components for
3927 that same symbol in the range. To be sure we only call the
3928 callback once per symbol, we first collect the symbol name
3929 indexes that matched in a temporary vector and ignore
3931 std::vector
<offset_type
> matches
;
3933 struct name_and_matcher
3935 symbol_name_matcher_ftype
*matcher
;
3936 const std::string
&name
;
3938 bool operator== (const name_and_matcher
&other
) const
3940 return matcher
== other
.matcher
&& name
== other
.name
;
3944 /* A vector holding all the different symbol name matchers, for all
3946 std::vector
<name_and_matcher
> matchers
;
3948 for (int i
= 0; i
< nr_languages
; i
++)
3950 enum language lang_e
= (enum language
) i
;
3952 const language_defn
*lang
= language_def (lang_e
);
3953 symbol_name_matcher_ftype
*name_matcher
3954 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3956 name_and_matcher key
{
3958 lookup_name_without_params
.language_lookup_name (lang_e
)
3961 /* Don't insert the same comparison routine more than once.
3962 Note that we do this linear walk. This is not a problem in
3963 practice because the number of supported languages is
3965 if (std::find (matchers
.begin (), matchers
.end (), key
)
3968 matchers
.push_back (std::move (key
));
3971 = index
.find_name_components_bounds (lookup_name_without_params
,
3974 /* Now for each symbol name in range, check to see if we have a name
3975 match, and if so, call the MATCH_CALLBACK callback. */
3977 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3979 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3981 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3982 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3985 matches
.push_back (bounds
.first
->idx
);
3989 std::sort (matches
.begin (), matches
.end ());
3991 /* Finally call the callback, once per match. */
3993 for (offset_type idx
: matches
)
3997 if (!match_callback (idx
))
4003 /* Above we use a type wider than idx's for 'prev', since 0 and
4004 (offset_type)-1 are both possible values. */
4005 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4010 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4012 /* A mock .gdb_index/.debug_names-like name index table, enough to
4013 exercise dw2_expand_symtabs_matching_symbol, which works with the
4014 mapped_index_base interface. Builds an index from the symbol list
4015 passed as parameter to the constructor. */
4016 class mock_mapped_index
: public mapped_index_base
4019 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4020 : m_symbol_table (symbols
)
4023 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4025 /* Return the number of names in the symbol table. */
4026 size_t symbol_name_count () const override
4028 return m_symbol_table
.size ();
4031 /* Get the name of the symbol at IDX in the symbol table. */
4032 const char *symbol_name_at (offset_type idx
) const override
4034 return m_symbol_table
[idx
];
4038 gdb::array_view
<const char *> m_symbol_table
;
4041 /* Convenience function that converts a NULL pointer to a "<null>"
4042 string, to pass to print routines. */
4045 string_or_null (const char *str
)
4047 return str
!= NULL
? str
: "<null>";
4050 /* Check if a lookup_name_info built from
4051 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4052 index. EXPECTED_LIST is the list of expected matches, in expected
4053 matching order. If no match expected, then an empty list is
4054 specified. Returns true on success. On failure prints a warning
4055 indicating the file:line that failed, and returns false. */
4058 check_match (const char *file
, int line
,
4059 mock_mapped_index
&mock_index
,
4060 const char *name
, symbol_name_match_type match_type
,
4061 bool completion_mode
,
4062 std::initializer_list
<const char *> expected_list
)
4064 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4066 bool matched
= true;
4068 auto mismatch
= [&] (const char *expected_str
,
4071 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4072 "expected=\"%s\", got=\"%s\"\n"),
4074 (match_type
== symbol_name_match_type::FULL
4076 name
, string_or_null (expected_str
), string_or_null (got
));
4080 auto expected_it
= expected_list
.begin ();
4081 auto expected_end
= expected_list
.end ();
4083 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4085 [&] (offset_type idx
)
4087 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4088 const char *expected_str
4089 = expected_it
== expected_end
? NULL
: *expected_it
++;
4091 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4092 mismatch (expected_str
, matched_name
);
4096 const char *expected_str
4097 = expected_it
== expected_end
? NULL
: *expected_it
++;
4098 if (expected_str
!= NULL
)
4099 mismatch (expected_str
, NULL
);
4104 /* The symbols added to the mock mapped_index for testing (in
4106 static const char *test_symbols
[] = {
4115 "ns2::tmpl<int>::foo2",
4116 "(anonymous namespace)::A::B::C",
4118 /* These are used to check that the increment-last-char in the
4119 matching algorithm for completion doesn't match "t1_fund" when
4120 completing "t1_func". */
4126 /* A UTF-8 name with multi-byte sequences to make sure that
4127 cp-name-parser understands this as a single identifier ("função"
4128 is "function" in PT). */
4131 /* \377 (0xff) is Latin1 'ÿ'. */
4134 /* \377 (0xff) is Latin1 'ÿ'. */
4138 /* A name with all sorts of complications. Starts with "z" to make
4139 it easier for the completion tests below. */
4140 #define Z_SYM_NAME \
4141 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4142 "::tuple<(anonymous namespace)::ui*, " \
4143 "std::default_delete<(anonymous namespace)::ui>, void>"
4148 /* Returns true if the mapped_index_base::find_name_component_bounds
4149 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4150 in completion mode. */
4153 check_find_bounds_finds (mapped_index_base
&index
,
4154 const char *search_name
,
4155 gdb::array_view
<const char *> expected_syms
)
4157 lookup_name_info
lookup_name (search_name
,
4158 symbol_name_match_type::FULL
, true);
4160 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4163 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4164 if (distance
!= expected_syms
.size ())
4167 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4169 auto nc_elem
= bounds
.first
+ exp_elem
;
4170 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4171 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4178 /* Test the lower-level mapped_index::find_name_component_bounds
4182 test_mapped_index_find_name_component_bounds ()
4184 mock_mapped_index
mock_index (test_symbols
);
4186 mock_index
.build_name_components ();
4188 /* Test the lower-level mapped_index::find_name_component_bounds
4189 method in completion mode. */
4191 static const char *expected_syms
[] = {
4196 SELF_CHECK (check_find_bounds_finds (mock_index
,
4197 "t1_func", expected_syms
));
4200 /* Check that the increment-last-char in the name matching algorithm
4201 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4203 static const char *expected_syms1
[] = {
4207 SELF_CHECK (check_find_bounds_finds (mock_index
,
4208 "\377", expected_syms1
));
4210 static const char *expected_syms2
[] = {
4213 SELF_CHECK (check_find_bounds_finds (mock_index
,
4214 "\377\377", expected_syms2
));
4218 /* Test dw2_expand_symtabs_matching_symbol. */
4221 test_dw2_expand_symtabs_matching_symbol ()
4223 mock_mapped_index
mock_index (test_symbols
);
4225 /* We let all tests run until the end even if some fails, for debug
4227 bool any_mismatch
= false;
4229 /* Create the expected symbols list (an initializer_list). Needed
4230 because lists have commas, and we need to pass them to CHECK,
4231 which is a macro. */
4232 #define EXPECT(...) { __VA_ARGS__ }
4234 /* Wrapper for check_match that passes down the current
4235 __FILE__/__LINE__. */
4236 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4237 any_mismatch |= !check_match (__FILE__, __LINE__, \
4239 NAME, MATCH_TYPE, COMPLETION_MODE, \
4242 /* Identity checks. */
4243 for (const char *sym
: test_symbols
)
4245 /* Should be able to match all existing symbols. */
4246 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4249 /* Should be able to match all existing symbols with
4251 std::string with_params
= std::string (sym
) + "(int)";
4252 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4255 /* Should be able to match all existing symbols with
4256 parameters and qualifiers. */
4257 with_params
= std::string (sym
) + " ( int ) const";
4258 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4261 /* This should really find sym, but cp-name-parser.y doesn't
4262 know about lvalue/rvalue qualifiers yet. */
4263 with_params
= std::string (sym
) + " ( int ) &&";
4264 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4268 /* Check that the name matching algorithm for completion doesn't get
4269 confused with Latin1 'ÿ' / 0xff. */
4271 static const char str
[] = "\377";
4272 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4273 EXPECT ("\377", "\377\377123"));
4276 /* Check that the increment-last-char in the matching algorithm for
4277 completion doesn't match "t1_fund" when completing "t1_func". */
4279 static const char str
[] = "t1_func";
4280 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4281 EXPECT ("t1_func", "t1_func1"));
4284 /* Check that completion mode works at each prefix of the expected
4287 static const char str
[] = "function(int)";
4288 size_t len
= strlen (str
);
4291 for (size_t i
= 1; i
< len
; i
++)
4293 lookup
.assign (str
, i
);
4294 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4295 EXPECT ("function"));
4299 /* While "w" is a prefix of both components, the match function
4300 should still only be called once. */
4302 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4304 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4308 /* Same, with a "complicated" symbol. */
4310 static const char str
[] = Z_SYM_NAME
;
4311 size_t len
= strlen (str
);
4314 for (size_t i
= 1; i
< len
; i
++)
4316 lookup
.assign (str
, i
);
4317 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4318 EXPECT (Z_SYM_NAME
));
4322 /* In FULL mode, an incomplete symbol doesn't match. */
4324 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4328 /* A complete symbol with parameters matches any overload, since the
4329 index has no overload info. */
4331 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4332 EXPECT ("std::zfunction", "std::zfunction2"));
4333 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4334 EXPECT ("std::zfunction", "std::zfunction2"));
4335 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4336 EXPECT ("std::zfunction", "std::zfunction2"));
4339 /* Check that whitespace is ignored appropriately. A symbol with a
4340 template argument list. */
4342 static const char expected
[] = "ns::foo<int>";
4343 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4345 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4349 /* Check that whitespace is ignored appropriately. A symbol with a
4350 template argument list that includes a pointer. */
4352 static const char expected
[] = "ns::foo<char*>";
4353 /* Try both completion and non-completion modes. */
4354 static const bool completion_mode
[2] = {false, true};
4355 for (size_t i
= 0; i
< 2; i
++)
4357 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4358 completion_mode
[i
], EXPECT (expected
));
4359 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4360 completion_mode
[i
], EXPECT (expected
));
4362 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4363 completion_mode
[i
], EXPECT (expected
));
4364 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4365 completion_mode
[i
], EXPECT (expected
));
4370 /* Check method qualifiers are ignored. */
4371 static const char expected
[] = "ns::foo<char*>";
4372 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4373 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4374 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4375 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4376 CHECK_MATCH ("foo < char * > ( int ) const",
4377 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4378 CHECK_MATCH ("foo < char * > ( int ) &&",
4379 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4382 /* Test lookup names that don't match anything. */
4384 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4387 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4391 /* Some wild matching tests, exercising "(anonymous namespace)",
4392 which should not be confused with a parameter list. */
4394 static const char *syms
[] = {
4398 "A :: B :: C ( int )",
4403 for (const char *s
: syms
)
4405 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4406 EXPECT ("(anonymous namespace)::A::B::C"));
4411 static const char expected
[] = "ns2::tmpl<int>::foo2";
4412 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4414 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4418 SELF_CHECK (!any_mismatch
);
4427 test_mapped_index_find_name_component_bounds ();
4428 test_dw2_expand_symtabs_matching_symbol ();
4431 }} // namespace selftests::dw2_expand_symtabs_matching
4433 #endif /* GDB_SELF_TEST */
4435 /* If FILE_MATCHER is NULL or if PER_CU has
4436 dwarf2_per_cu_quick_data::MARK set (see
4437 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4438 EXPANSION_NOTIFY on it. */
4441 dw2_expand_symtabs_matching_one
4442 (struct dwarf2_per_cu_data
*per_cu
,
4443 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4444 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4446 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4448 bool symtab_was_null
4449 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4451 dw2_instantiate_symtab (per_cu
, false);
4453 if (expansion_notify
!= NULL
4455 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4456 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4460 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4461 matched, to expand corresponding CUs that were marked. IDX is the
4462 index of the symbol name that matched. */
4465 dw2_expand_marked_cus
4466 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4467 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4468 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4471 offset_type
*vec
, vec_len
, vec_idx
;
4472 bool global_seen
= false;
4473 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4475 vec
= (offset_type
*) (index
.constant_pool
4476 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4477 vec_len
= MAYBE_SWAP (vec
[0]);
4478 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4480 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4481 /* This value is only valid for index versions >= 7. */
4482 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4483 gdb_index_symbol_kind symbol_kind
=
4484 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4485 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4486 /* Only check the symbol attributes if they're present.
4487 Indices prior to version 7 don't record them,
4488 and indices >= 7 may elide them for certain symbols
4489 (gold does this). */
4492 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4494 /* Work around gold/15646. */
4497 if (!is_static
&& global_seen
)
4503 /* Only check the symbol's kind if it has one. */
4508 case VARIABLES_DOMAIN
:
4509 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4512 case FUNCTIONS_DOMAIN
:
4513 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4517 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4520 case MODULES_DOMAIN
:
4521 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4529 /* Don't crash on bad data. */
4530 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4531 + dwarf2_per_objfile
->all_type_units
.size ()))
4533 complaint (_(".gdb_index entry has bad CU index"
4535 objfile_name (dwarf2_per_objfile
->objfile
));
4539 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4540 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4545 /* If FILE_MATCHER is non-NULL, set all the
4546 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4547 that match FILE_MATCHER. */
4550 dw_expand_symtabs_matching_file_matcher
4551 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4552 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4554 if (file_matcher
== NULL
)
4557 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4559 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4561 NULL
, xcalloc
, xfree
));
4562 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4564 NULL
, xcalloc
, xfree
));
4566 /* The rule is CUs specify all the files, including those used by
4567 any TU, so there's no need to scan TUs here. */
4569 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4573 per_cu
->v
.quick
->mark
= 0;
4575 /* We only need to look at symtabs not already expanded. */
4576 if (per_cu
->v
.quick
->compunit_symtab
)
4579 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4580 if (file_data
== NULL
)
4583 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4585 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4587 per_cu
->v
.quick
->mark
= 1;
4591 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4593 const char *this_real_name
;
4595 if (file_matcher (file_data
->file_names
[j
], false))
4597 per_cu
->v
.quick
->mark
= 1;
4601 /* Before we invoke realpath, which can get expensive when many
4602 files are involved, do a quick comparison of the basenames. */
4603 if (!basenames_may_differ
4604 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4608 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4609 if (file_matcher (this_real_name
, false))
4611 per_cu
->v
.quick
->mark
= 1;
4616 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4617 ? visited_found
.get ()
4618 : visited_not_found
.get (),
4625 dw2_expand_symtabs_matching
4626 (struct objfile
*objfile
,
4627 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4628 const lookup_name_info
&lookup_name
,
4629 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4630 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4631 enum search_domain kind
)
4633 struct dwarf2_per_objfile
*dwarf2_per_objfile
4634 = get_dwarf2_per_objfile (objfile
);
4636 /* index_table is NULL if OBJF_READNOW. */
4637 if (!dwarf2_per_objfile
->index_table
)
4640 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4642 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4644 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4646 kind
, [&] (offset_type idx
)
4648 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4649 expansion_notify
, kind
);
4654 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4657 static struct compunit_symtab
*
4658 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4663 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4664 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4667 if (cust
->includes
== NULL
)
4670 for (i
= 0; cust
->includes
[i
]; ++i
)
4672 struct compunit_symtab
*s
= cust
->includes
[i
];
4674 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4682 static struct compunit_symtab
*
4683 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4684 struct bound_minimal_symbol msymbol
,
4686 struct obj_section
*section
,
4689 struct dwarf2_per_cu_data
*data
;
4690 struct compunit_symtab
*result
;
4692 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4695 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4696 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4697 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4701 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4702 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4703 paddress (get_objfile_arch (objfile
), pc
));
4706 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4709 gdb_assert (result
!= NULL
);
4714 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4715 void *data
, int need_fullname
)
4717 struct dwarf2_per_objfile
*dwarf2_per_objfile
4718 = get_dwarf2_per_objfile (objfile
);
4720 if (!dwarf2_per_objfile
->filenames_cache
)
4722 dwarf2_per_objfile
->filenames_cache
.emplace ();
4724 htab_up
visited (htab_create_alloc (10,
4725 htab_hash_pointer
, htab_eq_pointer
,
4726 NULL
, xcalloc
, xfree
));
4728 /* The rule is CUs specify all the files, including those used
4729 by any TU, so there's no need to scan TUs here. We can
4730 ignore file names coming from already-expanded CUs. */
4732 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4734 if (per_cu
->v
.quick
->compunit_symtab
)
4736 void **slot
= htab_find_slot (visited
.get (),
4737 per_cu
->v
.quick
->file_names
,
4740 *slot
= per_cu
->v
.quick
->file_names
;
4744 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4746 /* We only need to look at symtabs not already expanded. */
4747 if (per_cu
->v
.quick
->compunit_symtab
)
4750 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4751 if (file_data
== NULL
)
4754 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4757 /* Already visited. */
4762 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4764 const char *filename
= file_data
->file_names
[j
];
4765 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4770 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4772 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4775 this_real_name
= gdb_realpath (filename
);
4776 (*fun
) (filename
, this_real_name
.get (), data
);
4781 dw2_has_symbols (struct objfile
*objfile
)
4786 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4789 dw2_find_last_source_symtab
,
4790 dw2_forget_cached_source_info
,
4791 dw2_map_symtabs_matching_filename
,
4795 dw2_expand_symtabs_for_function
,
4796 dw2_expand_all_symtabs
,
4797 dw2_expand_symtabs_with_fullname
,
4798 dw2_map_matching_symbols
,
4799 dw2_expand_symtabs_matching
,
4800 dw2_find_pc_sect_compunit_symtab
,
4802 dw2_map_symbol_filenames
4805 /* DWARF-5 debug_names reader. */
4807 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4808 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4810 /* A helper function that reads the .debug_names section in SECTION
4811 and fills in MAP. FILENAME is the name of the file containing the
4812 section; it is used for error reporting.
4814 Returns true if all went well, false otherwise. */
4817 read_debug_names_from_section (struct objfile
*objfile
,
4818 const char *filename
,
4819 struct dwarf2_section_info
*section
,
4820 mapped_debug_names
&map
)
4822 if (section
->empty ())
4825 /* Older elfutils strip versions could keep the section in the main
4826 executable while splitting it for the separate debug info file. */
4827 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4830 section
->read (objfile
);
4832 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4834 const gdb_byte
*addr
= section
->buffer
;
4836 bfd
*const abfd
= section
->get_bfd_owner ();
4838 unsigned int bytes_read
;
4839 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4842 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4843 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4844 if (bytes_read
+ length
!= section
->size
)
4846 /* There may be multiple per-CU indices. */
4847 warning (_("Section .debug_names in %s length %s does not match "
4848 "section length %s, ignoring .debug_names."),
4849 filename
, plongest (bytes_read
+ length
),
4850 pulongest (section
->size
));
4854 /* The version number. */
4855 uint16_t version
= read_2_bytes (abfd
, addr
);
4859 warning (_("Section .debug_names in %s has unsupported version %d, "
4860 "ignoring .debug_names."),
4866 uint16_t padding
= read_2_bytes (abfd
, addr
);
4870 warning (_("Section .debug_names in %s has unsupported padding %d, "
4871 "ignoring .debug_names."),
4876 /* comp_unit_count - The number of CUs in the CU list. */
4877 map
.cu_count
= read_4_bytes (abfd
, addr
);
4880 /* local_type_unit_count - The number of TUs in the local TU
4882 map
.tu_count
= read_4_bytes (abfd
, addr
);
4885 /* foreign_type_unit_count - The number of TUs in the foreign TU
4887 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4889 if (foreign_tu_count
!= 0)
4891 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4892 "ignoring .debug_names."),
4893 filename
, static_cast<unsigned long> (foreign_tu_count
));
4897 /* bucket_count - The number of hash buckets in the hash lookup
4899 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4902 /* name_count - The number of unique names in the index. */
4903 map
.name_count
= read_4_bytes (abfd
, addr
);
4906 /* abbrev_table_size - The size in bytes of the abbreviations
4908 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4911 /* augmentation_string_size - The size in bytes of the augmentation
4912 string. This value is rounded up to a multiple of 4. */
4913 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4915 map
.augmentation_is_gdb
= ((augmentation_string_size
4916 == sizeof (dwarf5_augmentation
))
4917 && memcmp (addr
, dwarf5_augmentation
,
4918 sizeof (dwarf5_augmentation
)) == 0);
4919 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4920 addr
+= augmentation_string_size
;
4923 map
.cu_table_reordered
= addr
;
4924 addr
+= map
.cu_count
* map
.offset_size
;
4926 /* List of Local TUs */
4927 map
.tu_table_reordered
= addr
;
4928 addr
+= map
.tu_count
* map
.offset_size
;
4930 /* Hash Lookup Table */
4931 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4932 addr
+= map
.bucket_count
* 4;
4933 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4934 addr
+= map
.name_count
* 4;
4937 map
.name_table_string_offs_reordered
= addr
;
4938 addr
+= map
.name_count
* map
.offset_size
;
4939 map
.name_table_entry_offs_reordered
= addr
;
4940 addr
+= map
.name_count
* map
.offset_size
;
4942 const gdb_byte
*abbrev_table_start
= addr
;
4945 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4950 const auto insertpair
4951 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4952 if (!insertpair
.second
)
4954 warning (_("Section .debug_names in %s has duplicate index %s, "
4955 "ignoring .debug_names."),
4956 filename
, pulongest (index_num
));
4959 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4960 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4965 mapped_debug_names::index_val::attr attr
;
4966 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4968 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4970 if (attr
.form
== DW_FORM_implicit_const
)
4972 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4976 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4978 indexval
.attr_vec
.push_back (std::move (attr
));
4981 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4983 warning (_("Section .debug_names in %s has abbreviation_table "
4984 "of size %s vs. written as %u, ignoring .debug_names."),
4985 filename
, plongest (addr
- abbrev_table_start
),
4989 map
.entry_pool
= addr
;
4994 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4998 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4999 const mapped_debug_names
&map
,
5000 dwarf2_section_info
§ion
,
5003 sect_offset sect_off_prev
;
5004 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5006 sect_offset sect_off_next
;
5007 if (i
< map
.cu_count
)
5010 = (sect_offset
) (extract_unsigned_integer
5011 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5013 map
.dwarf5_byte_order
));
5016 sect_off_next
= (sect_offset
) section
.size
;
5019 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5020 dwarf2_per_cu_data
*per_cu
5021 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5022 sect_off_prev
, length
);
5023 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5025 sect_off_prev
= sect_off_next
;
5029 /* Read the CU list from the mapped index, and use it to create all
5030 the CU objects for this dwarf2_per_objfile. */
5033 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5034 const mapped_debug_names
&map
,
5035 const mapped_debug_names
&dwz_map
)
5037 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5038 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5040 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5041 dwarf2_per_objfile
->info
,
5042 false /* is_dwz */);
5044 if (dwz_map
.cu_count
== 0)
5047 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5048 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5052 /* Read .debug_names. If everything went ok, initialize the "quick"
5053 elements of all the CUs and return true. Otherwise, return false. */
5056 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5058 std::unique_ptr
<mapped_debug_names
> map
5059 (new mapped_debug_names (dwarf2_per_objfile
));
5060 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5061 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5063 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5064 &dwarf2_per_objfile
->debug_names
,
5068 /* Don't use the index if it's empty. */
5069 if (map
->name_count
== 0)
5072 /* If there is a .dwz file, read it so we can get its CU list as
5074 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5077 if (!read_debug_names_from_section (objfile
,
5078 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5079 &dwz
->debug_names
, dwz_map
))
5081 warning (_("could not read '.debug_names' section from %s; skipping"),
5082 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5087 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5089 if (map
->tu_count
!= 0)
5091 /* We can only handle a single .debug_types when we have an
5093 if (dwarf2_per_objfile
->types
.size () != 1)
5096 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5098 create_signatured_type_table_from_debug_names
5099 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5102 create_addrmap_from_aranges (dwarf2_per_objfile
,
5103 &dwarf2_per_objfile
->debug_aranges
);
5105 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5106 dwarf2_per_objfile
->using_index
= 1;
5107 dwarf2_per_objfile
->quick_file_names_table
=
5108 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5113 /* Type used to manage iterating over all CUs looking for a symbol for
5116 class dw2_debug_names_iterator
5119 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5120 gdb::optional
<block_enum
> block_index
,
5123 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5124 m_addr (find_vec_in_debug_names (map
, name
))
5127 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5128 search_domain search
, uint32_t namei
)
5131 m_addr (find_vec_in_debug_names (map
, namei
))
5134 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5135 block_enum block_index
, domain_enum domain
,
5137 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5138 m_addr (find_vec_in_debug_names (map
, namei
))
5141 /* Return the next matching CU or NULL if there are no more. */
5142 dwarf2_per_cu_data
*next ();
5145 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5147 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5150 /* The internalized form of .debug_names. */
5151 const mapped_debug_names
&m_map
;
5153 /* If set, only look for symbols that match that block. Valid values are
5154 GLOBAL_BLOCK and STATIC_BLOCK. */
5155 const gdb::optional
<block_enum
> m_block_index
;
5157 /* The kind of symbol we're looking for. */
5158 const domain_enum m_domain
= UNDEF_DOMAIN
;
5159 const search_domain m_search
= ALL_DOMAIN
;
5161 /* The list of CUs from the index entry of the symbol, or NULL if
5163 const gdb_byte
*m_addr
;
5167 mapped_debug_names::namei_to_name (uint32_t namei
) const
5169 const ULONGEST namei_string_offs
5170 = extract_unsigned_integer ((name_table_string_offs_reordered
5171 + namei
* offset_size
),
5174 return read_indirect_string_at_offset
5175 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5178 /* Find a slot in .debug_names for the object named NAME. If NAME is
5179 found, return pointer to its pool data. If NAME cannot be found,
5183 dw2_debug_names_iterator::find_vec_in_debug_names
5184 (const mapped_debug_names
&map
, const char *name
)
5186 int (*cmp
) (const char *, const char *);
5188 gdb::unique_xmalloc_ptr
<char> without_params
;
5189 if (current_language
->la_language
== language_cplus
5190 || current_language
->la_language
== language_fortran
5191 || current_language
->la_language
== language_d
)
5193 /* NAME is already canonical. Drop any qualifiers as
5194 .debug_names does not contain any. */
5196 if (strchr (name
, '(') != NULL
)
5198 without_params
= cp_remove_params (name
);
5199 if (without_params
!= NULL
)
5200 name
= without_params
.get ();
5204 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5206 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5208 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5209 (map
.bucket_table_reordered
5210 + (full_hash
% map
.bucket_count
)), 4,
5211 map
.dwarf5_byte_order
);
5215 if (namei
>= map
.name_count
)
5217 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5219 namei
, map
.name_count
,
5220 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5226 const uint32_t namei_full_hash
5227 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5228 (map
.hash_table_reordered
+ namei
), 4,
5229 map
.dwarf5_byte_order
);
5230 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5233 if (full_hash
== namei_full_hash
)
5235 const char *const namei_string
= map
.namei_to_name (namei
);
5237 #if 0 /* An expensive sanity check. */
5238 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5240 complaint (_("Wrong .debug_names hash for string at index %u "
5242 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5247 if (cmp (namei_string
, name
) == 0)
5249 const ULONGEST namei_entry_offs
5250 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5251 + namei
* map
.offset_size
),
5252 map
.offset_size
, map
.dwarf5_byte_order
);
5253 return map
.entry_pool
+ namei_entry_offs
;
5258 if (namei
>= map
.name_count
)
5264 dw2_debug_names_iterator::find_vec_in_debug_names
5265 (const mapped_debug_names
&map
, uint32_t namei
)
5267 if (namei
>= map
.name_count
)
5269 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5271 namei
, map
.name_count
,
5272 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5276 const ULONGEST namei_entry_offs
5277 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5278 + namei
* map
.offset_size
),
5279 map
.offset_size
, map
.dwarf5_byte_order
);
5280 return map
.entry_pool
+ namei_entry_offs
;
5283 /* See dw2_debug_names_iterator. */
5285 dwarf2_per_cu_data
*
5286 dw2_debug_names_iterator::next ()
5291 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5292 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5293 bfd
*const abfd
= objfile
->obfd
;
5297 unsigned int bytes_read
;
5298 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5299 m_addr
+= bytes_read
;
5303 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5304 if (indexval_it
== m_map
.abbrev_map
.cend ())
5306 complaint (_("Wrong .debug_names undefined abbrev code %s "
5308 pulongest (abbrev
), objfile_name (objfile
));
5311 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5312 enum class symbol_linkage
{
5316 } symbol_linkage_
= symbol_linkage::unknown
;
5317 dwarf2_per_cu_data
*per_cu
= NULL
;
5318 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5323 case DW_FORM_implicit_const
:
5324 ull
= attr
.implicit_const
;
5326 case DW_FORM_flag_present
:
5330 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5331 m_addr
+= bytes_read
;
5334 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5335 dwarf_form_name (attr
.form
),
5336 objfile_name (objfile
));
5339 switch (attr
.dw_idx
)
5341 case DW_IDX_compile_unit
:
5342 /* Don't crash on bad data. */
5343 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5345 complaint (_(".debug_names entry has bad CU index %s"
5348 objfile_name (dwarf2_per_objfile
->objfile
));
5351 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5353 case DW_IDX_type_unit
:
5354 /* Don't crash on bad data. */
5355 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5357 complaint (_(".debug_names entry has bad TU index %s"
5360 objfile_name (dwarf2_per_objfile
->objfile
));
5363 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5365 case DW_IDX_GNU_internal
:
5366 if (!m_map
.augmentation_is_gdb
)
5368 symbol_linkage_
= symbol_linkage::static_
;
5370 case DW_IDX_GNU_external
:
5371 if (!m_map
.augmentation_is_gdb
)
5373 symbol_linkage_
= symbol_linkage::extern_
;
5378 /* Skip if already read in. */
5379 if (per_cu
->v
.quick
->compunit_symtab
)
5382 /* Check static vs global. */
5383 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5385 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5386 const bool symbol_is_static
=
5387 symbol_linkage_
== symbol_linkage::static_
;
5388 if (want_static
!= symbol_is_static
)
5392 /* Match dw2_symtab_iter_next, symbol_kind
5393 and debug_names::psymbol_tag. */
5397 switch (indexval
.dwarf_tag
)
5399 case DW_TAG_variable
:
5400 case DW_TAG_subprogram
:
5401 /* Some types are also in VAR_DOMAIN. */
5402 case DW_TAG_typedef
:
5403 case DW_TAG_structure_type
:
5410 switch (indexval
.dwarf_tag
)
5412 case DW_TAG_typedef
:
5413 case DW_TAG_structure_type
:
5420 switch (indexval
.dwarf_tag
)
5423 case DW_TAG_variable
:
5430 switch (indexval
.dwarf_tag
)
5442 /* Match dw2_expand_symtabs_matching, symbol_kind and
5443 debug_names::psymbol_tag. */
5446 case VARIABLES_DOMAIN
:
5447 switch (indexval
.dwarf_tag
)
5449 case DW_TAG_variable
:
5455 case FUNCTIONS_DOMAIN
:
5456 switch (indexval
.dwarf_tag
)
5458 case DW_TAG_subprogram
:
5465 switch (indexval
.dwarf_tag
)
5467 case DW_TAG_typedef
:
5468 case DW_TAG_structure_type
:
5474 case MODULES_DOMAIN
:
5475 switch (indexval
.dwarf_tag
)
5489 static struct compunit_symtab
*
5490 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5491 const char *name
, domain_enum domain
)
5493 struct dwarf2_per_objfile
*dwarf2_per_objfile
5494 = get_dwarf2_per_objfile (objfile
);
5496 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5499 /* index is NULL if OBJF_READNOW. */
5502 const auto &map
= *mapp
;
5504 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5506 struct compunit_symtab
*stab_best
= NULL
;
5507 struct dwarf2_per_cu_data
*per_cu
;
5508 while ((per_cu
= iter
.next ()) != NULL
)
5510 struct symbol
*sym
, *with_opaque
= NULL
;
5511 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5512 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5513 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5515 sym
= block_find_symbol (block
, name
, domain
,
5516 block_find_non_opaque_type_preferred
,
5519 /* Some caution must be observed with overloaded functions and
5520 methods, since the index will not contain any overload
5521 information (but NAME might contain it). */
5524 && strcmp_iw (sym
->search_name (), name
) == 0)
5526 if (with_opaque
!= NULL
5527 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5530 /* Keep looking through other CUs. */
5536 /* This dumps minimal information about .debug_names. It is called
5537 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5538 uses this to verify that .debug_names has been loaded. */
5541 dw2_debug_names_dump (struct objfile
*objfile
)
5543 struct dwarf2_per_objfile
*dwarf2_per_objfile
5544 = get_dwarf2_per_objfile (objfile
);
5546 gdb_assert (dwarf2_per_objfile
->using_index
);
5547 printf_filtered (".debug_names:");
5548 if (dwarf2_per_objfile
->debug_names_table
)
5549 printf_filtered (" exists\n");
5551 printf_filtered (" faked for \"readnow\"\n");
5552 printf_filtered ("\n");
5556 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5557 const char *func_name
)
5559 struct dwarf2_per_objfile
*dwarf2_per_objfile
5560 = get_dwarf2_per_objfile (objfile
);
5562 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5563 if (dwarf2_per_objfile
->debug_names_table
)
5565 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5567 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5569 struct dwarf2_per_cu_data
*per_cu
;
5570 while ((per_cu
= iter
.next ()) != NULL
)
5571 dw2_instantiate_symtab (per_cu
, false);
5576 dw2_debug_names_map_matching_symbols
5577 (struct objfile
*objfile
,
5578 const lookup_name_info
&name
, domain_enum domain
,
5580 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5581 symbol_compare_ftype
*ordered_compare
)
5583 struct dwarf2_per_objfile
*dwarf2_per_objfile
5584 = get_dwarf2_per_objfile (objfile
);
5586 /* debug_names_table is NULL if OBJF_READNOW. */
5587 if (!dwarf2_per_objfile
->debug_names_table
)
5590 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5591 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5593 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5594 auto matcher
= [&] (const char *symname
)
5596 if (ordered_compare
== nullptr)
5598 return ordered_compare (symname
, match_name
) == 0;
5601 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5602 [&] (offset_type namei
)
5604 /* The name was matched, now expand corresponding CUs that were
5606 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5608 struct dwarf2_per_cu_data
*per_cu
;
5609 while ((per_cu
= iter
.next ()) != NULL
)
5610 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5614 /* It's a shame we couldn't do this inside the
5615 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5616 that have already been expanded. Instead, this loop matches what
5617 the psymtab code does. */
5618 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5620 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5621 if (cust
!= nullptr)
5623 const struct block
*block
5624 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5625 if (!iterate_over_symbols_terminated (block
, name
,
5633 dw2_debug_names_expand_symtabs_matching
5634 (struct objfile
*objfile
,
5635 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5636 const lookup_name_info
&lookup_name
,
5637 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5638 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5639 enum search_domain kind
)
5641 struct dwarf2_per_objfile
*dwarf2_per_objfile
5642 = get_dwarf2_per_objfile (objfile
);
5644 /* debug_names_table is NULL if OBJF_READNOW. */
5645 if (!dwarf2_per_objfile
->debug_names_table
)
5648 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5650 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5652 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5654 kind
, [&] (offset_type namei
)
5656 /* The name was matched, now expand corresponding CUs that were
5658 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5660 struct dwarf2_per_cu_data
*per_cu
;
5661 while ((per_cu
= iter
.next ()) != NULL
)
5662 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5668 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5671 dw2_find_last_source_symtab
,
5672 dw2_forget_cached_source_info
,
5673 dw2_map_symtabs_matching_filename
,
5674 dw2_debug_names_lookup_symbol
,
5676 dw2_debug_names_dump
,
5677 dw2_debug_names_expand_symtabs_for_function
,
5678 dw2_expand_all_symtabs
,
5679 dw2_expand_symtabs_with_fullname
,
5680 dw2_debug_names_map_matching_symbols
,
5681 dw2_debug_names_expand_symtabs_matching
,
5682 dw2_find_pc_sect_compunit_symtab
,
5684 dw2_map_symbol_filenames
5687 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5688 to either a dwarf2_per_objfile or dwz_file object. */
5690 template <typename T
>
5691 static gdb::array_view
<const gdb_byte
>
5692 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5694 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5696 if (section
->empty ())
5699 /* Older elfutils strip versions could keep the section in the main
5700 executable while splitting it for the separate debug info file. */
5701 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5704 section
->read (obj
);
5706 /* dwarf2_section_info::size is a bfd_size_type, while
5707 gdb::array_view works with size_t. On 32-bit hosts, with
5708 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5709 is 32-bit. So we need an explicit narrowing conversion here.
5710 This is fine, because it's impossible to allocate or mmap an
5711 array/buffer larger than what size_t can represent. */
5712 return gdb::make_array_view (section
->buffer
, section
->size
);
5715 /* Lookup the index cache for the contents of the index associated to
5718 static gdb::array_view
<const gdb_byte
>
5719 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5721 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5722 if (build_id
== nullptr)
5725 return global_index_cache
.lookup_gdb_index (build_id
,
5726 &dwarf2_obj
->index_cache_res
);
5729 /* Same as the above, but for DWZ. */
5731 static gdb::array_view
<const gdb_byte
>
5732 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5734 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5735 if (build_id
== nullptr)
5738 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5741 /* See symfile.h. */
5744 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5746 struct dwarf2_per_objfile
*dwarf2_per_objfile
5747 = get_dwarf2_per_objfile (objfile
);
5749 /* If we're about to read full symbols, don't bother with the
5750 indices. In this case we also don't care if some other debug
5751 format is making psymtabs, because they are all about to be
5753 if ((objfile
->flags
& OBJF_READNOW
))
5755 dwarf2_per_objfile
->using_index
= 1;
5756 create_all_comp_units (dwarf2_per_objfile
);
5757 create_all_type_units (dwarf2_per_objfile
);
5758 dwarf2_per_objfile
->quick_file_names_table
5759 = create_quick_file_names_table
5760 (dwarf2_per_objfile
->all_comp_units
.size ());
5762 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5763 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5765 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5767 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5768 struct dwarf2_per_cu_quick_data
);
5771 /* Return 1 so that gdb sees the "quick" functions. However,
5772 these functions will be no-ops because we will have expanded
5774 *index_kind
= dw_index_kind::GDB_INDEX
;
5778 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5780 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5784 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5785 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5786 get_gdb_index_contents_from_section
<dwz_file
>))
5788 *index_kind
= dw_index_kind::GDB_INDEX
;
5792 /* ... otherwise, try to find the index in the index cache. */
5793 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5794 get_gdb_index_contents_from_cache
,
5795 get_gdb_index_contents_from_cache_dwz
))
5797 global_index_cache
.hit ();
5798 *index_kind
= dw_index_kind::GDB_INDEX
;
5802 global_index_cache
.miss ();
5808 /* Build a partial symbol table. */
5811 dwarf2_build_psymtabs (struct objfile
*objfile
)
5813 struct dwarf2_per_objfile
*dwarf2_per_objfile
5814 = get_dwarf2_per_objfile (objfile
);
5816 init_psymbol_list (objfile
, 1024);
5820 /* This isn't really ideal: all the data we allocate on the
5821 objfile's obstack is still uselessly kept around. However,
5822 freeing it seems unsafe. */
5823 psymtab_discarder
psymtabs (objfile
);
5824 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5827 /* (maybe) store an index in the cache. */
5828 global_index_cache
.store (dwarf2_per_objfile
);
5830 catch (const gdb_exception_error
&except
)
5832 exception_print (gdb_stderr
, except
);
5836 /* Find the base address of the compilation unit for range lists and
5837 location lists. It will normally be specified by DW_AT_low_pc.
5838 In DWARF-3 draft 4, the base address could be overridden by
5839 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5840 compilation units with discontinuous ranges. */
5843 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5845 struct attribute
*attr
;
5848 cu
->base_address
= 0;
5850 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5851 if (attr
!= nullptr)
5853 cu
->base_address
= attr
->value_as_address ();
5858 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5859 if (attr
!= nullptr)
5861 cu
->base_address
= attr
->value_as_address ();
5867 /* Helper function that returns the proper abbrev section for
5870 static struct dwarf2_section_info
*
5871 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5873 struct dwarf2_section_info
*abbrev
;
5874 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5876 if (this_cu
->is_dwz
)
5877 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5879 abbrev
= &dwarf2_per_objfile
->abbrev
;
5884 /* Fetch the abbreviation table offset from a comp or type unit header. */
5887 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5888 struct dwarf2_section_info
*section
,
5889 sect_offset sect_off
)
5891 bfd
*abfd
= section
->get_bfd_owner ();
5892 const gdb_byte
*info_ptr
;
5893 unsigned int initial_length_size
, offset_size
;
5896 section
->read (dwarf2_per_objfile
->objfile
);
5897 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5898 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5899 offset_size
= initial_length_size
== 4 ? 4 : 8;
5900 info_ptr
+= initial_length_size
;
5902 version
= read_2_bytes (abfd
, info_ptr
);
5906 /* Skip unit type and address size. */
5910 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5913 /* A partial symtab that is used only for include files. */
5914 struct dwarf2_include_psymtab
: public partial_symtab
5916 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5917 : partial_symtab (filename
, objfile
)
5921 void read_symtab (struct objfile
*objfile
) override
5923 expand_psymtab (objfile
);
5926 void expand_psymtab (struct objfile
*objfile
) override
5930 /* It's an include file, no symbols to read for it.
5931 Everything is in the parent symtab. */
5932 read_dependencies (objfile
);
5936 bool readin_p () const override
5941 struct compunit_symtab
*get_compunit_symtab () const override
5948 bool m_readin
= false;
5951 /* Allocate a new partial symtab for file named NAME and mark this new
5952 partial symtab as being an include of PST. */
5955 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5956 struct objfile
*objfile
)
5958 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5960 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5962 /* It shares objfile->objfile_obstack. */
5963 subpst
->dirname
= pst
->dirname
;
5966 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5967 subpst
->dependencies
[0] = pst
;
5968 subpst
->number_of_dependencies
= 1;
5971 /* Read the Line Number Program data and extract the list of files
5972 included by the source file represented by PST. Build an include
5973 partial symtab for each of these included files. */
5976 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5977 struct die_info
*die
,
5978 dwarf2_psymtab
*pst
)
5981 struct attribute
*attr
;
5983 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5984 if (attr
!= nullptr)
5985 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5987 return; /* No linetable, so no includes. */
5989 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5990 that we pass in the raw text_low here; that is ok because we're
5991 only decoding the line table to make include partial symtabs, and
5992 so the addresses aren't really used. */
5993 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5994 pst
->raw_text_low (), 1);
5998 hash_signatured_type (const void *item
)
6000 const struct signatured_type
*sig_type
6001 = (const struct signatured_type
*) item
;
6003 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6004 return sig_type
->signature
;
6008 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6010 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6011 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6013 return lhs
->signature
== rhs
->signature
;
6016 /* Allocate a hash table for signatured types. */
6019 allocate_signatured_type_table ()
6021 return htab_up (htab_create_alloc (41,
6022 hash_signatured_type
,
6024 NULL
, xcalloc
, xfree
));
6027 /* A helper function to add a signatured type CU to a table. */
6030 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6032 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6033 std::vector
<signatured_type
*> *all_type_units
6034 = (std::vector
<signatured_type
*> *) datum
;
6036 all_type_units
->push_back (sigt
);
6041 /* A helper for create_debug_types_hash_table. Read types from SECTION
6042 and fill them into TYPES_HTAB. It will process only type units,
6043 therefore DW_UT_type. */
6046 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6047 struct dwo_file
*dwo_file
,
6048 dwarf2_section_info
*section
, htab_up
&types_htab
,
6049 rcuh_kind section_kind
)
6051 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6052 struct dwarf2_section_info
*abbrev_section
;
6054 const gdb_byte
*info_ptr
, *end_ptr
;
6056 abbrev_section
= (dwo_file
!= NULL
6057 ? &dwo_file
->sections
.abbrev
6058 : &dwarf2_per_objfile
->abbrev
);
6060 if (dwarf_read_debug
)
6061 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6062 section
->get_name (),
6063 abbrev_section
->get_file_name ());
6065 section
->read (objfile
);
6066 info_ptr
= section
->buffer
;
6068 if (info_ptr
== NULL
)
6071 /* We can't set abfd until now because the section may be empty or
6072 not present, in which case the bfd is unknown. */
6073 abfd
= section
->get_bfd_owner ();
6075 /* We don't use cutu_reader here because we don't need to read
6076 any dies: the signature is in the header. */
6078 end_ptr
= info_ptr
+ section
->size
;
6079 while (info_ptr
< end_ptr
)
6081 struct signatured_type
*sig_type
;
6082 struct dwo_unit
*dwo_tu
;
6084 const gdb_byte
*ptr
= info_ptr
;
6085 struct comp_unit_head header
;
6086 unsigned int length
;
6088 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6090 /* Initialize it due to a false compiler warning. */
6091 header
.signature
= -1;
6092 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6094 /* We need to read the type's signature in order to build the hash
6095 table, but we don't need anything else just yet. */
6097 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6098 abbrev_section
, ptr
, section_kind
);
6100 length
= header
.get_length ();
6102 /* Skip dummy type units. */
6103 if (ptr
>= info_ptr
+ length
6104 || peek_abbrev_code (abfd
, ptr
) == 0
6105 || header
.unit_type
!= DW_UT_type
)
6111 if (types_htab
== NULL
)
6114 types_htab
= allocate_dwo_unit_table ();
6116 types_htab
= allocate_signatured_type_table ();
6122 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6124 dwo_tu
->dwo_file
= dwo_file
;
6125 dwo_tu
->signature
= header
.signature
;
6126 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6127 dwo_tu
->section
= section
;
6128 dwo_tu
->sect_off
= sect_off
;
6129 dwo_tu
->length
= length
;
6133 /* N.B.: type_offset is not usable if this type uses a DWO file.
6134 The real type_offset is in the DWO file. */
6136 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6137 struct signatured_type
);
6138 sig_type
->signature
= header
.signature
;
6139 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6140 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6141 sig_type
->per_cu
.is_debug_types
= 1;
6142 sig_type
->per_cu
.section
= section
;
6143 sig_type
->per_cu
.sect_off
= sect_off
;
6144 sig_type
->per_cu
.length
= length
;
6147 slot
= htab_find_slot (types_htab
.get (),
6148 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6150 gdb_assert (slot
!= NULL
);
6153 sect_offset dup_sect_off
;
6157 const struct dwo_unit
*dup_tu
6158 = (const struct dwo_unit
*) *slot
;
6160 dup_sect_off
= dup_tu
->sect_off
;
6164 const struct signatured_type
*dup_tu
6165 = (const struct signatured_type
*) *slot
;
6167 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6170 complaint (_("debug type entry at offset %s is duplicate to"
6171 " the entry at offset %s, signature %s"),
6172 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6173 hex_string (header
.signature
));
6175 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6177 if (dwarf_read_debug
> 1)
6178 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6179 sect_offset_str (sect_off
),
6180 hex_string (header
.signature
));
6186 /* Create the hash table of all entries in the .debug_types
6187 (or .debug_types.dwo) section(s).
6188 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6189 otherwise it is NULL.
6191 The result is a pointer to the hash table or NULL if there are no types.
6193 Note: This function processes DWO files only, not DWP files. */
6196 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6197 struct dwo_file
*dwo_file
,
6198 gdb::array_view
<dwarf2_section_info
> type_sections
,
6199 htab_up
&types_htab
)
6201 for (dwarf2_section_info
§ion
: type_sections
)
6202 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6203 types_htab
, rcuh_kind::TYPE
);
6206 /* Create the hash table of all entries in the .debug_types section,
6207 and initialize all_type_units.
6208 The result is zero if there is an error (e.g. missing .debug_types section),
6209 otherwise non-zero. */
6212 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6216 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6217 &dwarf2_per_objfile
->info
, types_htab
,
6218 rcuh_kind::COMPILE
);
6219 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6220 dwarf2_per_objfile
->types
, types_htab
);
6221 if (types_htab
== NULL
)
6223 dwarf2_per_objfile
->signatured_types
= NULL
;
6227 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6229 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6230 dwarf2_per_objfile
->all_type_units
.reserve
6231 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6233 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6234 add_signatured_type_cu_to_table
,
6235 &dwarf2_per_objfile
->all_type_units
);
6240 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6241 If SLOT is non-NULL, it is the entry to use in the hash table.
6242 Otherwise we find one. */
6244 static struct signatured_type
*
6245 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6248 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6250 if (dwarf2_per_objfile
->all_type_units
.size ()
6251 == dwarf2_per_objfile
->all_type_units
.capacity ())
6252 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6254 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6255 struct signatured_type
);
6257 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6258 sig_type
->signature
= sig
;
6259 sig_type
->per_cu
.is_debug_types
= 1;
6260 if (dwarf2_per_objfile
->using_index
)
6262 sig_type
->per_cu
.v
.quick
=
6263 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6264 struct dwarf2_per_cu_quick_data
);
6269 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6272 gdb_assert (*slot
== NULL
);
6274 /* The rest of sig_type must be filled in by the caller. */
6278 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6279 Fill in SIG_ENTRY with DWO_ENTRY. */
6282 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6283 struct signatured_type
*sig_entry
,
6284 struct dwo_unit
*dwo_entry
)
6286 /* Make sure we're not clobbering something we don't expect to. */
6287 gdb_assert (! sig_entry
->per_cu
.queued
);
6288 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6289 if (dwarf2_per_objfile
->using_index
)
6291 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6292 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6295 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6296 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6297 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6298 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6299 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6301 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6302 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6303 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6304 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6305 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6306 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6307 sig_entry
->dwo_unit
= dwo_entry
;
6310 /* Subroutine of lookup_signatured_type.
6311 If we haven't read the TU yet, create the signatured_type data structure
6312 for a TU to be read in directly from a DWO file, bypassing the stub.
6313 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6314 using .gdb_index, then when reading a CU we want to stay in the DWO file
6315 containing that CU. Otherwise we could end up reading several other DWO
6316 files (due to comdat folding) to process the transitive closure of all the
6317 mentioned TUs, and that can be slow. The current DWO file will have every
6318 type signature that it needs.
6319 We only do this for .gdb_index because in the psymtab case we already have
6320 to read all the DWOs to build the type unit groups. */
6322 static struct signatured_type
*
6323 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6325 struct dwarf2_per_objfile
*dwarf2_per_objfile
6326 = cu
->per_cu
->dwarf2_per_objfile
;
6327 struct dwo_file
*dwo_file
;
6328 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6329 struct signatured_type find_sig_entry
, *sig_entry
;
6332 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6334 /* If TU skeletons have been removed then we may not have read in any
6336 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6337 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6339 /* We only ever need to read in one copy of a signatured type.
6340 Use the global signatured_types array to do our own comdat-folding
6341 of types. If this is the first time we're reading this TU, and
6342 the TU has an entry in .gdb_index, replace the recorded data from
6343 .gdb_index with this TU. */
6345 find_sig_entry
.signature
= sig
;
6346 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6347 &find_sig_entry
, INSERT
);
6348 sig_entry
= (struct signatured_type
*) *slot
;
6350 /* We can get here with the TU already read, *or* in the process of being
6351 read. Don't reassign the global entry to point to this DWO if that's
6352 the case. Also note that if the TU is already being read, it may not
6353 have come from a DWO, the program may be a mix of Fission-compiled
6354 code and non-Fission-compiled code. */
6356 /* Have we already tried to read this TU?
6357 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6358 needn't exist in the global table yet). */
6359 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6362 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6363 dwo_unit of the TU itself. */
6364 dwo_file
= cu
->dwo_unit
->dwo_file
;
6366 /* Ok, this is the first time we're reading this TU. */
6367 if (dwo_file
->tus
== NULL
)
6369 find_dwo_entry
.signature
= sig
;
6370 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6372 if (dwo_entry
== NULL
)
6375 /* If the global table doesn't have an entry for this TU, add one. */
6376 if (sig_entry
== NULL
)
6377 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6379 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6380 sig_entry
->per_cu
.tu_read
= 1;
6384 /* Subroutine of lookup_signatured_type.
6385 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6386 then try the DWP file. If the TU stub (skeleton) has been removed then
6387 it won't be in .gdb_index. */
6389 static struct signatured_type
*
6390 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6392 struct dwarf2_per_objfile
*dwarf2_per_objfile
6393 = cu
->per_cu
->dwarf2_per_objfile
;
6394 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6395 struct dwo_unit
*dwo_entry
;
6396 struct signatured_type find_sig_entry
, *sig_entry
;
6399 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6400 gdb_assert (dwp_file
!= NULL
);
6402 /* If TU skeletons have been removed then we may not have read in any
6404 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6405 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6407 find_sig_entry
.signature
= sig
;
6408 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6409 &find_sig_entry
, INSERT
);
6410 sig_entry
= (struct signatured_type
*) *slot
;
6412 /* Have we already tried to read this TU?
6413 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6414 needn't exist in the global table yet). */
6415 if (sig_entry
!= NULL
)
6418 if (dwp_file
->tus
== NULL
)
6420 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6421 sig
, 1 /* is_debug_types */);
6422 if (dwo_entry
== NULL
)
6425 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6426 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6431 /* Lookup a signature based type for DW_FORM_ref_sig8.
6432 Returns NULL if signature SIG is not present in the table.
6433 It is up to the caller to complain about this. */
6435 static struct signatured_type
*
6436 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6438 struct dwarf2_per_objfile
*dwarf2_per_objfile
6439 = cu
->per_cu
->dwarf2_per_objfile
;
6442 && dwarf2_per_objfile
->using_index
)
6444 /* We're in a DWO/DWP file, and we're using .gdb_index.
6445 These cases require special processing. */
6446 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6447 return lookup_dwo_signatured_type (cu
, sig
);
6449 return lookup_dwp_signatured_type (cu
, sig
);
6453 struct signatured_type find_entry
, *entry
;
6455 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6457 find_entry
.signature
= sig
;
6458 entry
= ((struct signatured_type
*)
6459 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6465 /* Return the address base of the compile unit, which, if exists, is stored
6466 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6467 static gdb::optional
<ULONGEST
>
6468 lookup_addr_base (struct die_info
*comp_unit_die
)
6470 struct attribute
*attr
;
6471 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6472 if (attr
== nullptr)
6473 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6474 if (attr
== nullptr)
6475 return gdb::optional
<ULONGEST
> ();
6476 return DW_UNSND (attr
);
6479 /* Return range lists base of the compile unit, which, if exists, is stored
6480 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6482 lookup_ranges_base (struct die_info
*comp_unit_die
)
6484 struct attribute
*attr
;
6485 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6486 if (attr
== nullptr)
6487 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6488 if (attr
== nullptr)
6490 return DW_UNSND (attr
);
6493 /* Low level DIE reading support. */
6495 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6498 init_cu_die_reader (struct die_reader_specs
*reader
,
6499 struct dwarf2_cu
*cu
,
6500 struct dwarf2_section_info
*section
,
6501 struct dwo_file
*dwo_file
,
6502 struct abbrev_table
*abbrev_table
)
6504 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6505 reader
->abfd
= section
->get_bfd_owner ();
6507 reader
->dwo_file
= dwo_file
;
6508 reader
->die_section
= section
;
6509 reader
->buffer
= section
->buffer
;
6510 reader
->buffer_end
= section
->buffer
+ section
->size
;
6511 reader
->abbrev_table
= abbrev_table
;
6514 /* Subroutine of cutu_reader to simplify it.
6515 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6516 There's just a lot of work to do, and cutu_reader is big enough
6519 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6520 from it to the DIE in the DWO. If NULL we are skipping the stub.
6521 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6522 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6523 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6524 STUB_COMP_DIR may be non-NULL.
6525 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6526 are filled in with the info of the DIE from the DWO file.
6527 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6528 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6529 kept around for at least as long as *RESULT_READER.
6531 The result is non-zero if a valid (non-dummy) DIE was found. */
6534 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6535 struct dwo_unit
*dwo_unit
,
6536 struct die_info
*stub_comp_unit_die
,
6537 const char *stub_comp_dir
,
6538 struct die_reader_specs
*result_reader
,
6539 const gdb_byte
**result_info_ptr
,
6540 struct die_info
**result_comp_unit_die
,
6541 abbrev_table_up
*result_dwo_abbrev_table
)
6543 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6545 struct dwarf2_cu
*cu
= this_cu
->cu
;
6547 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6548 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6549 int i
,num_extra_attrs
;
6550 struct dwarf2_section_info
*dwo_abbrev_section
;
6551 struct die_info
*comp_unit_die
;
6553 /* At most one of these may be provided. */
6554 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6556 /* These attributes aren't processed until later:
6557 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6558 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6559 referenced later. However, these attributes are found in the stub
6560 which we won't have later. In order to not impose this complication
6561 on the rest of the code, we read them here and copy them to the
6570 if (stub_comp_unit_die
!= NULL
)
6572 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6574 if (! this_cu
->is_debug_types
)
6575 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6576 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6577 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6578 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6579 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6581 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6583 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6584 here (if needed). We need the value before we can process
6586 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6588 else if (stub_comp_dir
!= NULL
)
6590 /* Reconstruct the comp_dir attribute to simplify the code below. */
6591 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6592 comp_dir
->name
= DW_AT_comp_dir
;
6593 comp_dir
->form
= DW_FORM_string
;
6594 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6595 DW_STRING (comp_dir
) = stub_comp_dir
;
6598 /* Set up for reading the DWO CU/TU. */
6599 cu
->dwo_unit
= dwo_unit
;
6600 dwarf2_section_info
*section
= dwo_unit
->section
;
6601 section
->read (objfile
);
6602 abfd
= section
->get_bfd_owner ();
6603 begin_info_ptr
= info_ptr
= (section
->buffer
6604 + to_underlying (dwo_unit
->sect_off
));
6605 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6607 if (this_cu
->is_debug_types
)
6609 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6611 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6612 &cu
->header
, section
,
6614 info_ptr
, rcuh_kind::TYPE
);
6615 /* This is not an assert because it can be caused by bad debug info. */
6616 if (sig_type
->signature
!= cu
->header
.signature
)
6618 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6619 " TU at offset %s [in module %s]"),
6620 hex_string (sig_type
->signature
),
6621 hex_string (cu
->header
.signature
),
6622 sect_offset_str (dwo_unit
->sect_off
),
6623 bfd_get_filename (abfd
));
6625 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6626 /* For DWOs coming from DWP files, we don't know the CU length
6627 nor the type's offset in the TU until now. */
6628 dwo_unit
->length
= cu
->header
.get_length ();
6629 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6631 /* Establish the type offset that can be used to lookup the type.
6632 For DWO files, we don't know it until now. */
6633 sig_type
->type_offset_in_section
6634 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6638 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6639 &cu
->header
, section
,
6641 info_ptr
, rcuh_kind::COMPILE
);
6642 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6643 /* For DWOs coming from DWP files, we don't know the CU length
6645 dwo_unit
->length
= cu
->header
.get_length ();
6648 *result_dwo_abbrev_table
6649 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6650 cu
->header
.abbrev_sect_off
);
6651 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6652 result_dwo_abbrev_table
->get ());
6654 /* Read in the die, but leave space to copy over the attributes
6655 from the stub. This has the benefit of simplifying the rest of
6656 the code - all the work to maintain the illusion of a single
6657 DW_TAG_{compile,type}_unit DIE is done here. */
6658 num_extra_attrs
= ((stmt_list
!= NULL
)
6662 + (comp_dir
!= NULL
));
6663 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6666 /* Copy over the attributes from the stub to the DIE we just read in. */
6667 comp_unit_die
= *result_comp_unit_die
;
6668 i
= comp_unit_die
->num_attrs
;
6669 if (stmt_list
!= NULL
)
6670 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6672 comp_unit_die
->attrs
[i
++] = *low_pc
;
6673 if (high_pc
!= NULL
)
6674 comp_unit_die
->attrs
[i
++] = *high_pc
;
6676 comp_unit_die
->attrs
[i
++] = *ranges
;
6677 if (comp_dir
!= NULL
)
6678 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6679 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6681 if (dwarf_die_debug
)
6683 fprintf_unfiltered (gdb_stdlog
,
6684 "Read die from %s@0x%x of %s:\n",
6685 section
->get_name (),
6686 (unsigned) (begin_info_ptr
- section
->buffer
),
6687 bfd_get_filename (abfd
));
6688 dump_die (comp_unit_die
, dwarf_die_debug
);
6691 /* Skip dummy compilation units. */
6692 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6693 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6696 *result_info_ptr
= info_ptr
;
6700 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6701 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6702 signature is part of the header. */
6703 static gdb::optional
<ULONGEST
>
6704 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6706 if (cu
->header
.version
>= 5)
6707 return cu
->header
.signature
;
6708 struct attribute
*attr
;
6709 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6710 if (attr
== nullptr)
6711 return gdb::optional
<ULONGEST
> ();
6712 return DW_UNSND (attr
);
6715 /* Subroutine of cutu_reader to simplify it.
6716 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6717 Returns NULL if the specified DWO unit cannot be found. */
6719 static struct dwo_unit
*
6720 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6721 struct die_info
*comp_unit_die
,
6722 const char *dwo_name
)
6724 struct dwarf2_cu
*cu
= this_cu
->cu
;
6725 struct dwo_unit
*dwo_unit
;
6726 const char *comp_dir
;
6728 gdb_assert (cu
!= NULL
);
6730 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6731 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6732 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6734 if (this_cu
->is_debug_types
)
6736 struct signatured_type
*sig_type
;
6738 /* Since this_cu is the first member of struct signatured_type,
6739 we can go from a pointer to one to a pointer to the other. */
6740 sig_type
= (struct signatured_type
*) this_cu
;
6741 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6745 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6746 if (!signature
.has_value ())
6747 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6749 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6750 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6757 /* Subroutine of cutu_reader to simplify it.
6758 See it for a description of the parameters.
6759 Read a TU directly from a DWO file, bypassing the stub. */
6762 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6763 int use_existing_cu
)
6765 struct signatured_type
*sig_type
;
6767 /* Verify we can do the following downcast, and that we have the
6769 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6770 sig_type
= (struct signatured_type
*) this_cu
;
6771 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6773 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6775 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6776 /* There's no need to do the rereading_dwo_cu handling that
6777 cutu_reader does since we don't read the stub. */
6781 /* If !use_existing_cu, this_cu->cu must be NULL. */
6782 gdb_assert (this_cu
->cu
== NULL
);
6783 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6786 /* A future optimization, if needed, would be to use an existing
6787 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6788 could share abbrev tables. */
6790 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6791 NULL
/* stub_comp_unit_die */,
6792 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6795 &m_dwo_abbrev_table
) == 0)
6802 /* Initialize a CU (or TU) and read its DIEs.
6803 If the CU defers to a DWO file, read the DWO file as well.
6805 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6806 Otherwise the table specified in the comp unit header is read in and used.
6807 This is an optimization for when we already have the abbrev table.
6809 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6810 Otherwise, a new CU is allocated with xmalloc. */
6812 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6813 struct abbrev_table
*abbrev_table
,
6814 int use_existing_cu
,
6816 : die_reader_specs
{},
6819 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6820 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6821 struct dwarf2_section_info
*section
= this_cu
->section
;
6822 bfd
*abfd
= section
->get_bfd_owner ();
6823 struct dwarf2_cu
*cu
;
6824 const gdb_byte
*begin_info_ptr
;
6825 struct signatured_type
*sig_type
= NULL
;
6826 struct dwarf2_section_info
*abbrev_section
;
6827 /* Non-zero if CU currently points to a DWO file and we need to
6828 reread it. When this happens we need to reread the skeleton die
6829 before we can reread the DWO file (this only applies to CUs, not TUs). */
6830 int rereading_dwo_cu
= 0;
6832 if (dwarf_die_debug
)
6833 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6834 this_cu
->is_debug_types
? "type" : "comp",
6835 sect_offset_str (this_cu
->sect_off
));
6837 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6838 file (instead of going through the stub), short-circuit all of this. */
6839 if (this_cu
->reading_dwo_directly
)
6841 /* Narrow down the scope of possibilities to have to understand. */
6842 gdb_assert (this_cu
->is_debug_types
);
6843 gdb_assert (abbrev_table
== NULL
);
6844 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6848 /* This is cheap if the section is already read in. */
6849 section
->read (objfile
);
6851 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6853 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6855 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6858 /* If this CU is from a DWO file we need to start over, we need to
6859 refetch the attributes from the skeleton CU.
6860 This could be optimized by retrieving those attributes from when we
6861 were here the first time: the previous comp_unit_die was stored in
6862 comp_unit_obstack. But there's no data yet that we need this
6864 if (cu
->dwo_unit
!= NULL
)
6865 rereading_dwo_cu
= 1;
6869 /* If !use_existing_cu, this_cu->cu must be NULL. */
6870 gdb_assert (this_cu
->cu
== NULL
);
6871 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6872 cu
= m_new_cu
.get ();
6875 /* Get the header. */
6876 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6878 /* We already have the header, there's no need to read it in again. */
6879 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6883 if (this_cu
->is_debug_types
)
6885 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6886 &cu
->header
, section
,
6887 abbrev_section
, info_ptr
,
6890 /* Since per_cu is the first member of struct signatured_type,
6891 we can go from a pointer to one to a pointer to the other. */
6892 sig_type
= (struct signatured_type
*) this_cu
;
6893 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6894 gdb_assert (sig_type
->type_offset_in_tu
6895 == cu
->header
.type_cu_offset_in_tu
);
6896 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6898 /* LENGTH has not been set yet for type units if we're
6899 using .gdb_index. */
6900 this_cu
->length
= cu
->header
.get_length ();
6902 /* Establish the type offset that can be used to lookup the type. */
6903 sig_type
->type_offset_in_section
=
6904 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6906 this_cu
->dwarf_version
= cu
->header
.version
;
6910 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6911 &cu
->header
, section
,
6914 rcuh_kind::COMPILE
);
6916 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6917 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6918 this_cu
->dwarf_version
= cu
->header
.version
;
6922 /* Skip dummy compilation units. */
6923 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6924 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6930 /* If we don't have them yet, read the abbrevs for this compilation unit.
6931 And if we need to read them now, make sure they're freed when we're
6933 if (abbrev_table
!= NULL
)
6934 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6937 m_abbrev_table_holder
6938 = abbrev_table::read (objfile
, abbrev_section
,
6939 cu
->header
.abbrev_sect_off
);
6940 abbrev_table
= m_abbrev_table_holder
.get ();
6943 /* Read the top level CU/TU die. */
6944 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6945 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6947 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6953 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6954 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6955 table from the DWO file and pass the ownership over to us. It will be
6956 referenced from READER, so we must make sure to free it after we're done
6959 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6960 DWO CU, that this test will fail (the attribute will not be present). */
6961 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6962 if (dwo_name
!= nullptr)
6964 struct dwo_unit
*dwo_unit
;
6965 struct die_info
*dwo_comp_unit_die
;
6967 if (comp_unit_die
->has_children
)
6969 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6970 " has children (offset %s) [in module %s]"),
6971 sect_offset_str (this_cu
->sect_off
),
6972 bfd_get_filename (abfd
));
6974 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6975 if (dwo_unit
!= NULL
)
6977 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6978 comp_unit_die
, NULL
,
6981 &m_dwo_abbrev_table
) == 0)
6987 comp_unit_die
= dwo_comp_unit_die
;
6991 /* Yikes, we couldn't find the rest of the DIE, we only have
6992 the stub. A complaint has already been logged. There's
6993 not much more we can do except pass on the stub DIE to
6994 die_reader_func. We don't want to throw an error on bad
7001 cutu_reader::keep ()
7003 /* Done, clean up. */
7004 gdb_assert (!dummy_p
);
7005 if (m_new_cu
!= NULL
)
7007 struct dwarf2_per_objfile
*dwarf2_per_objfile
7008 = m_this_cu
->dwarf2_per_objfile
;
7009 /* Link this CU into read_in_chain. */
7010 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7011 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7012 /* The chain owns it now. */
7013 m_new_cu
.release ();
7017 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7018 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7019 assumed to have already done the lookup to find the DWO file).
7021 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7022 THIS_CU->is_debug_types, but nothing else.
7024 We fill in THIS_CU->length.
7026 THIS_CU->cu is always freed when done.
7027 This is done in order to not leave THIS_CU->cu in a state where we have
7028 to care whether it refers to the "main" CU or the DWO CU.
7030 When parent_cu is passed, it is used to provide a default value for
7031 str_offsets_base and addr_base from the parent. */
7033 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7034 struct dwarf2_cu
*parent_cu
,
7035 struct dwo_file
*dwo_file
)
7036 : die_reader_specs
{},
7039 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7040 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7041 struct dwarf2_section_info
*section
= this_cu
->section
;
7042 bfd
*abfd
= section
->get_bfd_owner ();
7043 struct dwarf2_section_info
*abbrev_section
;
7044 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7046 if (dwarf_die_debug
)
7047 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7048 this_cu
->is_debug_types
? "type" : "comp",
7049 sect_offset_str (this_cu
->sect_off
));
7051 gdb_assert (this_cu
->cu
== NULL
);
7053 abbrev_section
= (dwo_file
!= NULL
7054 ? &dwo_file
->sections
.abbrev
7055 : get_abbrev_section_for_cu (this_cu
));
7057 /* This is cheap if the section is already read in. */
7058 section
->read (objfile
);
7060 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7062 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7063 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7064 &m_new_cu
->header
, section
,
7065 abbrev_section
, info_ptr
,
7066 (this_cu
->is_debug_types
7068 : rcuh_kind::COMPILE
));
7070 if (parent_cu
!= nullptr)
7072 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7073 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7075 this_cu
->length
= m_new_cu
->header
.get_length ();
7077 /* Skip dummy compilation units. */
7078 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7079 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7085 m_abbrev_table_holder
7086 = abbrev_table::read (objfile
, abbrev_section
,
7087 m_new_cu
->header
.abbrev_sect_off
);
7089 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7090 m_abbrev_table_holder
.get ());
7091 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7095 /* Type Unit Groups.
7097 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7098 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7099 so that all types coming from the same compilation (.o file) are grouped
7100 together. A future step could be to put the types in the same symtab as
7101 the CU the types ultimately came from. */
7104 hash_type_unit_group (const void *item
)
7106 const struct type_unit_group
*tu_group
7107 = (const struct type_unit_group
*) item
;
7109 return hash_stmt_list_entry (&tu_group
->hash
);
7113 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7115 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7116 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7118 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7121 /* Allocate a hash table for type unit groups. */
7124 allocate_type_unit_groups_table ()
7126 return htab_up (htab_create_alloc (3,
7127 hash_type_unit_group
,
7129 NULL
, xcalloc
, xfree
));
7132 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7133 partial symtabs. We combine several TUs per psymtab to not let the size
7134 of any one psymtab grow too big. */
7135 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7136 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7138 /* Helper routine for get_type_unit_group.
7139 Create the type_unit_group object used to hold one or more TUs. */
7141 static struct type_unit_group
*
7142 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7144 struct dwarf2_per_objfile
*dwarf2_per_objfile
7145 = cu
->per_cu
->dwarf2_per_objfile
;
7146 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7147 struct dwarf2_per_cu_data
*per_cu
;
7148 struct type_unit_group
*tu_group
;
7150 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7151 struct type_unit_group
);
7152 per_cu
= &tu_group
->per_cu
;
7153 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7155 if (dwarf2_per_objfile
->using_index
)
7157 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7158 struct dwarf2_per_cu_quick_data
);
7162 unsigned int line_offset
= to_underlying (line_offset_struct
);
7163 dwarf2_psymtab
*pst
;
7166 /* Give the symtab a useful name for debug purposes. */
7167 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7168 name
= string_printf ("<type_units_%d>",
7169 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7171 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7173 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7174 pst
->anonymous
= true;
7177 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7178 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7183 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7184 STMT_LIST is a DW_AT_stmt_list attribute. */
7186 static struct type_unit_group
*
7187 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7189 struct dwarf2_per_objfile
*dwarf2_per_objfile
7190 = cu
->per_cu
->dwarf2_per_objfile
;
7191 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7192 struct type_unit_group
*tu_group
;
7194 unsigned int line_offset
;
7195 struct type_unit_group type_unit_group_for_lookup
;
7197 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7198 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7200 /* Do we need to create a new group, or can we use an existing one? */
7204 line_offset
= DW_UNSND (stmt_list
);
7205 ++tu_stats
->nr_symtab_sharers
;
7209 /* Ugh, no stmt_list. Rare, but we have to handle it.
7210 We can do various things here like create one group per TU or
7211 spread them over multiple groups to split up the expansion work.
7212 To avoid worst case scenarios (too many groups or too large groups)
7213 we, umm, group them in bunches. */
7214 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7215 | (tu_stats
->nr_stmt_less_type_units
7216 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7217 ++tu_stats
->nr_stmt_less_type_units
;
7220 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7221 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7222 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7223 &type_unit_group_for_lookup
, INSERT
);
7226 tu_group
= (struct type_unit_group
*) *slot
;
7227 gdb_assert (tu_group
!= NULL
);
7231 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7232 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7234 ++tu_stats
->nr_symtabs
;
7240 /* Partial symbol tables. */
7242 /* Create a psymtab named NAME and assign it to PER_CU.
7244 The caller must fill in the following details:
7245 dirname, textlow, texthigh. */
7247 static dwarf2_psymtab
*
7248 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7250 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7251 dwarf2_psymtab
*pst
;
7253 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7255 pst
->psymtabs_addrmap_supported
= true;
7257 /* This is the glue that links PST into GDB's symbol API. */
7258 pst
->per_cu_data
= per_cu
;
7259 per_cu
->v
.psymtab
= pst
;
7264 /* DIE reader function for process_psymtab_comp_unit. */
7267 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7268 const gdb_byte
*info_ptr
,
7269 struct die_info
*comp_unit_die
,
7270 enum language pretend_language
)
7272 struct dwarf2_cu
*cu
= reader
->cu
;
7273 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7274 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7275 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7277 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7278 dwarf2_psymtab
*pst
;
7279 enum pc_bounds_kind cu_bounds_kind
;
7280 const char *filename
;
7282 gdb_assert (! per_cu
->is_debug_types
);
7284 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7286 /* Allocate a new partial symbol table structure. */
7287 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7288 static const char artificial
[] = "<artificial>";
7289 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7290 if (filename
== NULL
)
7292 else if (strcmp (filename
, artificial
) == 0)
7294 debug_filename
.reset (concat (artificial
, "@",
7295 sect_offset_str (per_cu
->sect_off
),
7297 filename
= debug_filename
.get ();
7300 pst
= create_partial_symtab (per_cu
, filename
);
7302 /* This must be done before calling dwarf2_build_include_psymtabs. */
7303 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7305 baseaddr
= objfile
->text_section_offset ();
7307 dwarf2_find_base_address (comp_unit_die
, cu
);
7309 /* Possibly set the default values of LOWPC and HIGHPC from
7311 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7312 &best_highpc
, cu
, pst
);
7313 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7316 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7319 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7321 /* Store the contiguous range if it is not empty; it can be
7322 empty for CUs with no code. */
7323 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7327 /* Check if comp unit has_children.
7328 If so, read the rest of the partial symbols from this comp unit.
7329 If not, there's no more debug_info for this comp unit. */
7330 if (comp_unit_die
->has_children
)
7332 struct partial_die_info
*first_die
;
7333 CORE_ADDR lowpc
, highpc
;
7335 lowpc
= ((CORE_ADDR
) -1);
7336 highpc
= ((CORE_ADDR
) 0);
7338 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7340 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7341 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7343 /* If we didn't find a lowpc, set it to highpc to avoid
7344 complaints from `maint check'. */
7345 if (lowpc
== ((CORE_ADDR
) -1))
7348 /* If the compilation unit didn't have an explicit address range,
7349 then use the information extracted from its child dies. */
7350 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7353 best_highpc
= highpc
;
7356 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7357 best_lowpc
+ baseaddr
)
7359 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7360 best_highpc
+ baseaddr
)
7363 end_psymtab_common (objfile
, pst
);
7365 if (!cu
->per_cu
->imported_symtabs_empty ())
7368 int len
= cu
->per_cu
->imported_symtabs_size ();
7370 /* Fill in 'dependencies' here; we fill in 'users' in a
7372 pst
->number_of_dependencies
= len
;
7374 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7375 for (i
= 0; i
< len
; ++i
)
7377 pst
->dependencies
[i
]
7378 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7381 cu
->per_cu
->imported_symtabs_free ();
7384 /* Get the list of files included in the current compilation unit,
7385 and build a psymtab for each of them. */
7386 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7388 if (dwarf_read_debug
)
7389 fprintf_unfiltered (gdb_stdlog
,
7390 "Psymtab for %s unit @%s: %s - %s"
7391 ", %d global, %d static syms\n",
7392 per_cu
->is_debug_types
? "type" : "comp",
7393 sect_offset_str (per_cu
->sect_off
),
7394 paddress (gdbarch
, pst
->text_low (objfile
)),
7395 paddress (gdbarch
, pst
->text_high (objfile
)),
7396 pst
->n_global_syms
, pst
->n_static_syms
);
7399 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7400 Process compilation unit THIS_CU for a psymtab. */
7403 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7404 bool want_partial_unit
,
7405 enum language pretend_language
)
7407 /* If this compilation unit was already read in, free the
7408 cached copy in order to read it in again. This is
7409 necessary because we skipped some symbols when we first
7410 read in the compilation unit (see load_partial_dies).
7411 This problem could be avoided, but the benefit is unclear. */
7412 if (this_cu
->cu
!= NULL
)
7413 free_one_cached_comp_unit (this_cu
);
7415 cutu_reader
reader (this_cu
, NULL
, 0, false);
7417 switch (reader
.comp_unit_die
->tag
)
7419 case DW_TAG_compile_unit
:
7420 this_cu
->unit_type
= DW_UT_compile
;
7422 case DW_TAG_partial_unit
:
7423 this_cu
->unit_type
= DW_UT_partial
;
7433 else if (this_cu
->is_debug_types
)
7434 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7435 reader
.comp_unit_die
);
7436 else if (want_partial_unit
7437 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7438 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7439 reader
.comp_unit_die
,
7442 this_cu
->lang
= this_cu
->cu
->language
;
7444 /* Age out any secondary CUs. */
7445 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7448 /* Reader function for build_type_psymtabs. */
7451 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7452 const gdb_byte
*info_ptr
,
7453 struct die_info
*type_unit_die
)
7455 struct dwarf2_per_objfile
*dwarf2_per_objfile
7456 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7457 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7458 struct dwarf2_cu
*cu
= reader
->cu
;
7459 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7460 struct signatured_type
*sig_type
;
7461 struct type_unit_group
*tu_group
;
7462 struct attribute
*attr
;
7463 struct partial_die_info
*first_die
;
7464 CORE_ADDR lowpc
, highpc
;
7465 dwarf2_psymtab
*pst
;
7467 gdb_assert (per_cu
->is_debug_types
);
7468 sig_type
= (struct signatured_type
*) per_cu
;
7470 if (! type_unit_die
->has_children
)
7473 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7474 tu_group
= get_type_unit_group (cu
, attr
);
7476 if (tu_group
->tus
== nullptr)
7477 tu_group
->tus
= new std::vector
<signatured_type
*>;
7478 tu_group
->tus
->push_back (sig_type
);
7480 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7481 pst
= create_partial_symtab (per_cu
, "");
7482 pst
->anonymous
= true;
7484 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7486 lowpc
= (CORE_ADDR
) -1;
7487 highpc
= (CORE_ADDR
) 0;
7488 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7490 end_psymtab_common (objfile
, pst
);
7493 /* Struct used to sort TUs by their abbreviation table offset. */
7495 struct tu_abbrev_offset
7497 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7498 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7501 signatured_type
*sig_type
;
7502 sect_offset abbrev_offset
;
7505 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7508 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7509 const struct tu_abbrev_offset
&b
)
7511 return a
.abbrev_offset
< b
.abbrev_offset
;
7514 /* Efficiently read all the type units.
7515 This does the bulk of the work for build_type_psymtabs.
7517 The efficiency is because we sort TUs by the abbrev table they use and
7518 only read each abbrev table once. In one program there are 200K TUs
7519 sharing 8K abbrev tables.
7521 The main purpose of this function is to support building the
7522 dwarf2_per_objfile->type_unit_groups table.
7523 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7524 can collapse the search space by grouping them by stmt_list.
7525 The savings can be significant, in the same program from above the 200K TUs
7526 share 8K stmt_list tables.
7528 FUNC is expected to call get_type_unit_group, which will create the
7529 struct type_unit_group if necessary and add it to
7530 dwarf2_per_objfile->type_unit_groups. */
7533 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7535 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7536 abbrev_table_up abbrev_table
;
7537 sect_offset abbrev_offset
;
7539 /* It's up to the caller to not call us multiple times. */
7540 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7542 if (dwarf2_per_objfile
->all_type_units
.empty ())
7545 /* TUs typically share abbrev tables, and there can be way more TUs than
7546 abbrev tables. Sort by abbrev table to reduce the number of times we
7547 read each abbrev table in.
7548 Alternatives are to punt or to maintain a cache of abbrev tables.
7549 This is simpler and efficient enough for now.
7551 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7552 symtab to use). Typically TUs with the same abbrev offset have the same
7553 stmt_list value too so in practice this should work well.
7555 The basic algorithm here is:
7557 sort TUs by abbrev table
7558 for each TU with same abbrev table:
7559 read abbrev table if first user
7560 read TU top level DIE
7561 [IWBN if DWO skeletons had DW_AT_stmt_list]
7564 if (dwarf_read_debug
)
7565 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7567 /* Sort in a separate table to maintain the order of all_type_units
7568 for .gdb_index: TU indices directly index all_type_units. */
7569 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7570 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7572 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7573 sorted_by_abbrev
.emplace_back
7574 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7575 sig_type
->per_cu
.section
,
7576 sig_type
->per_cu
.sect_off
));
7578 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7579 sort_tu_by_abbrev_offset
);
7581 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7583 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7585 /* Switch to the next abbrev table if necessary. */
7586 if (abbrev_table
== NULL
7587 || tu
.abbrev_offset
!= abbrev_offset
)
7589 abbrev_offset
= tu
.abbrev_offset
;
7591 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7592 &dwarf2_per_objfile
->abbrev
,
7594 ++tu_stats
->nr_uniq_abbrev_tables
;
7597 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7599 if (!reader
.dummy_p
)
7600 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7601 reader
.comp_unit_die
);
7605 /* Print collected type unit statistics. */
7608 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7610 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7612 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7613 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7614 dwarf2_per_objfile
->all_type_units
.size ());
7615 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7616 tu_stats
->nr_uniq_abbrev_tables
);
7617 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7618 tu_stats
->nr_symtabs
);
7619 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7620 tu_stats
->nr_symtab_sharers
);
7621 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7622 tu_stats
->nr_stmt_less_type_units
);
7623 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7624 tu_stats
->nr_all_type_units_reallocs
);
7627 /* Traversal function for build_type_psymtabs. */
7630 build_type_psymtab_dependencies (void **slot
, void *info
)
7632 struct dwarf2_per_objfile
*dwarf2_per_objfile
7633 = (struct dwarf2_per_objfile
*) info
;
7634 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7635 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7636 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7637 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7638 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7641 gdb_assert (len
> 0);
7642 gdb_assert (per_cu
->type_unit_group_p ());
7644 pst
->number_of_dependencies
= len
;
7645 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7646 for (i
= 0; i
< len
; ++i
)
7648 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7649 gdb_assert (iter
->per_cu
.is_debug_types
);
7650 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7651 iter
->type_unit_group
= tu_group
;
7654 delete tu_group
->tus
;
7655 tu_group
->tus
= nullptr;
7660 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7661 Build partial symbol tables for the .debug_types comp-units. */
7664 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7666 if (! create_all_type_units (dwarf2_per_objfile
))
7669 build_type_psymtabs_1 (dwarf2_per_objfile
);
7672 /* Traversal function for process_skeletonless_type_unit.
7673 Read a TU in a DWO file and build partial symbols for it. */
7676 process_skeletonless_type_unit (void **slot
, void *info
)
7678 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7679 struct dwarf2_per_objfile
*dwarf2_per_objfile
7680 = (struct dwarf2_per_objfile
*) info
;
7681 struct signatured_type find_entry
, *entry
;
7683 /* If this TU doesn't exist in the global table, add it and read it in. */
7685 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7686 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7688 find_entry
.signature
= dwo_unit
->signature
;
7689 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7690 &find_entry
, INSERT
);
7691 /* If we've already seen this type there's nothing to do. What's happening
7692 is we're doing our own version of comdat-folding here. */
7696 /* This does the job that create_all_type_units would have done for
7698 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7699 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7702 /* This does the job that build_type_psymtabs_1 would have done. */
7703 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7704 if (!reader
.dummy_p
)
7705 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7706 reader
.comp_unit_die
);
7711 /* Traversal function for process_skeletonless_type_units. */
7714 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7716 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7718 if (dwo_file
->tus
!= NULL
)
7719 htab_traverse_noresize (dwo_file
->tus
.get (),
7720 process_skeletonless_type_unit
, info
);
7725 /* Scan all TUs of DWO files, verifying we've processed them.
7726 This is needed in case a TU was emitted without its skeleton.
7727 Note: This can't be done until we know what all the DWO files are. */
7730 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7732 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7733 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7734 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7736 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7737 process_dwo_file_for_skeletonless_type_units
,
7738 dwarf2_per_objfile
);
7742 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7745 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7747 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7749 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7754 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7756 /* Set the 'user' field only if it is not already set. */
7757 if (pst
->dependencies
[j
]->user
== NULL
)
7758 pst
->dependencies
[j
]->user
= pst
;
7763 /* Build the partial symbol table by doing a quick pass through the
7764 .debug_info and .debug_abbrev sections. */
7767 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7769 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7771 if (dwarf_read_debug
)
7773 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7774 objfile_name (objfile
));
7777 scoped_restore restore_reading_psyms
7778 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7781 dwarf2_per_objfile
->info
.read (objfile
);
7783 /* Any cached compilation units will be linked by the per-objfile
7784 read_in_chain. Make sure to free them when we're done. */
7785 free_cached_comp_units
freer (dwarf2_per_objfile
);
7787 build_type_psymtabs (dwarf2_per_objfile
);
7789 create_all_comp_units (dwarf2_per_objfile
);
7791 /* Create a temporary address map on a temporary obstack. We later
7792 copy this to the final obstack. */
7793 auto_obstack temp_obstack
;
7795 scoped_restore save_psymtabs_addrmap
7796 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7797 addrmap_create_mutable (&temp_obstack
));
7799 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7800 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7802 /* This has to wait until we read the CUs, we need the list of DWOs. */
7803 process_skeletonless_type_units (dwarf2_per_objfile
);
7805 /* Now that all TUs have been processed we can fill in the dependencies. */
7806 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7808 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7809 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7812 if (dwarf_read_debug
)
7813 print_tu_stats (dwarf2_per_objfile
);
7815 set_partial_user (dwarf2_per_objfile
);
7817 objfile
->partial_symtabs
->psymtabs_addrmap
7818 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7819 objfile
->partial_symtabs
->obstack ());
7820 /* At this point we want to keep the address map. */
7821 save_psymtabs_addrmap
.release ();
7823 if (dwarf_read_debug
)
7824 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7825 objfile_name (objfile
));
7828 /* Load the partial DIEs for a secondary CU into memory.
7829 This is also used when rereading a primary CU with load_all_dies. */
7832 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7834 cutu_reader
reader (this_cu
, NULL
, 1, false);
7836 if (!reader
.dummy_p
)
7838 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7841 /* Check if comp unit has_children.
7842 If so, read the rest of the partial symbols from this comp unit.
7843 If not, there's no more debug_info for this comp unit. */
7844 if (reader
.comp_unit_die
->has_children
)
7845 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7852 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7853 struct dwarf2_section_info
*section
,
7854 struct dwarf2_section_info
*abbrev_section
,
7855 unsigned int is_dwz
)
7857 const gdb_byte
*info_ptr
;
7858 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7860 if (dwarf_read_debug
)
7861 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7862 section
->get_name (),
7863 section
->get_file_name ());
7865 section
->read (objfile
);
7867 info_ptr
= section
->buffer
;
7869 while (info_ptr
< section
->buffer
+ section
->size
)
7871 struct dwarf2_per_cu_data
*this_cu
;
7873 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7875 comp_unit_head cu_header
;
7876 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7877 abbrev_section
, info_ptr
,
7878 rcuh_kind::COMPILE
);
7880 /* Save the compilation unit for later lookup. */
7881 if (cu_header
.unit_type
!= DW_UT_type
)
7883 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7884 struct dwarf2_per_cu_data
);
7885 memset (this_cu
, 0, sizeof (*this_cu
));
7889 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7890 struct signatured_type
);
7891 memset (sig_type
, 0, sizeof (*sig_type
));
7892 sig_type
->signature
= cu_header
.signature
;
7893 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7894 this_cu
= &sig_type
->per_cu
;
7896 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7897 this_cu
->sect_off
= sect_off
;
7898 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7899 this_cu
->is_dwz
= is_dwz
;
7900 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7901 this_cu
->section
= section
;
7903 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7905 info_ptr
= info_ptr
+ this_cu
->length
;
7909 /* Create a list of all compilation units in OBJFILE.
7910 This is only done for -readnow and building partial symtabs. */
7913 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7915 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7916 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7917 &dwarf2_per_objfile
->abbrev
, 0);
7919 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7921 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7925 /* Process all loaded DIEs for compilation unit CU, starting at
7926 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7927 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7928 DW_AT_ranges). See the comments of add_partial_subprogram on how
7929 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7932 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7933 CORE_ADDR
*highpc
, int set_addrmap
,
7934 struct dwarf2_cu
*cu
)
7936 struct partial_die_info
*pdi
;
7938 /* Now, march along the PDI's, descending into ones which have
7939 interesting children but skipping the children of the other ones,
7940 until we reach the end of the compilation unit. */
7948 /* Anonymous namespaces or modules have no name but have interesting
7949 children, so we need to look at them. Ditto for anonymous
7952 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7953 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7954 || pdi
->tag
== DW_TAG_imported_unit
7955 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7959 case DW_TAG_subprogram
:
7960 case DW_TAG_inlined_subroutine
:
7961 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7963 case DW_TAG_constant
:
7964 case DW_TAG_variable
:
7965 case DW_TAG_typedef
:
7966 case DW_TAG_union_type
:
7967 if (!pdi
->is_declaration
)
7969 add_partial_symbol (pdi
, cu
);
7972 case DW_TAG_class_type
:
7973 case DW_TAG_interface_type
:
7974 case DW_TAG_structure_type
:
7975 if (!pdi
->is_declaration
)
7977 add_partial_symbol (pdi
, cu
);
7979 if ((cu
->language
== language_rust
7980 || cu
->language
== language_cplus
) && pdi
->has_children
)
7981 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7984 case DW_TAG_enumeration_type
:
7985 if (!pdi
->is_declaration
)
7986 add_partial_enumeration (pdi
, cu
);
7988 case DW_TAG_base_type
:
7989 case DW_TAG_subrange_type
:
7990 /* File scope base type definitions are added to the partial
7992 add_partial_symbol (pdi
, cu
);
7994 case DW_TAG_namespace
:
7995 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7998 if (!pdi
->is_declaration
)
7999 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8001 case DW_TAG_imported_unit
:
8003 struct dwarf2_per_cu_data
*per_cu
;
8005 /* For now we don't handle imported units in type units. */
8006 if (cu
->per_cu
->is_debug_types
)
8008 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8009 " supported in type units [in module %s]"),
8010 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8013 per_cu
= dwarf2_find_containing_comp_unit
8014 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8015 cu
->per_cu
->dwarf2_per_objfile
);
8017 /* Go read the partial unit, if needed. */
8018 if (per_cu
->v
.psymtab
== NULL
)
8019 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8021 cu
->per_cu
->imported_symtabs_push (per_cu
);
8024 case DW_TAG_imported_declaration
:
8025 add_partial_symbol (pdi
, cu
);
8032 /* If the die has a sibling, skip to the sibling. */
8034 pdi
= pdi
->die_sibling
;
8038 /* Functions used to compute the fully scoped name of a partial DIE.
8040 Normally, this is simple. For C++, the parent DIE's fully scoped
8041 name is concatenated with "::" and the partial DIE's name.
8042 Enumerators are an exception; they use the scope of their parent
8043 enumeration type, i.e. the name of the enumeration type is not
8044 prepended to the enumerator.
8046 There are two complexities. One is DW_AT_specification; in this
8047 case "parent" means the parent of the target of the specification,
8048 instead of the direct parent of the DIE. The other is compilers
8049 which do not emit DW_TAG_namespace; in this case we try to guess
8050 the fully qualified name of structure types from their members'
8051 linkage names. This must be done using the DIE's children rather
8052 than the children of any DW_AT_specification target. We only need
8053 to do this for structures at the top level, i.e. if the target of
8054 any DW_AT_specification (if any; otherwise the DIE itself) does not
8057 /* Compute the scope prefix associated with PDI's parent, in
8058 compilation unit CU. The result will be allocated on CU's
8059 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8060 field. NULL is returned if no prefix is necessary. */
8062 partial_die_parent_scope (struct partial_die_info
*pdi
,
8063 struct dwarf2_cu
*cu
)
8065 const char *grandparent_scope
;
8066 struct partial_die_info
*parent
, *real_pdi
;
8068 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8069 then this means the parent of the specification DIE. */
8072 while (real_pdi
->has_specification
)
8074 auto res
= find_partial_die (real_pdi
->spec_offset
,
8075 real_pdi
->spec_is_dwz
, cu
);
8080 parent
= real_pdi
->die_parent
;
8084 if (parent
->scope_set
)
8085 return parent
->scope
;
8089 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8091 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8092 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8093 Work around this problem here. */
8094 if (cu
->language
== language_cplus
8095 && parent
->tag
== DW_TAG_namespace
8096 && strcmp (parent
->name
, "::") == 0
8097 && grandparent_scope
== NULL
)
8099 parent
->scope
= NULL
;
8100 parent
->scope_set
= 1;
8104 /* Nested subroutines in Fortran get a prefix. */
8105 if (pdi
->tag
== DW_TAG_enumerator
)
8106 /* Enumerators should not get the name of the enumeration as a prefix. */
8107 parent
->scope
= grandparent_scope
;
8108 else if (parent
->tag
== DW_TAG_namespace
8109 || parent
->tag
== DW_TAG_module
8110 || parent
->tag
== DW_TAG_structure_type
8111 || parent
->tag
== DW_TAG_class_type
8112 || parent
->tag
== DW_TAG_interface_type
8113 || parent
->tag
== DW_TAG_union_type
8114 || parent
->tag
== DW_TAG_enumeration_type
8115 || (cu
->language
== language_fortran
8116 && parent
->tag
== DW_TAG_subprogram
8117 && pdi
->tag
== DW_TAG_subprogram
))
8119 if (grandparent_scope
== NULL
)
8120 parent
->scope
= parent
->name
;
8122 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8124 parent
->name
, 0, cu
);
8128 /* FIXME drow/2004-04-01: What should we be doing with
8129 function-local names? For partial symbols, we should probably be
8131 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8132 dwarf_tag_name (parent
->tag
),
8133 sect_offset_str (pdi
->sect_off
));
8134 parent
->scope
= grandparent_scope
;
8137 parent
->scope_set
= 1;
8138 return parent
->scope
;
8141 /* Return the fully scoped name associated with PDI, from compilation unit
8142 CU. The result will be allocated with malloc. */
8144 static gdb::unique_xmalloc_ptr
<char>
8145 partial_die_full_name (struct partial_die_info
*pdi
,
8146 struct dwarf2_cu
*cu
)
8148 const char *parent_scope
;
8150 /* If this is a template instantiation, we can not work out the
8151 template arguments from partial DIEs. So, unfortunately, we have
8152 to go through the full DIEs. At least any work we do building
8153 types here will be reused if full symbols are loaded later. */
8154 if (pdi
->has_template_arguments
)
8158 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8160 struct die_info
*die
;
8161 struct attribute attr
;
8162 struct dwarf2_cu
*ref_cu
= cu
;
8164 /* DW_FORM_ref_addr is using section offset. */
8165 attr
.name
= (enum dwarf_attribute
) 0;
8166 attr
.form
= DW_FORM_ref_addr
;
8167 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8168 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8170 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8174 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8175 if (parent_scope
== NULL
)
8178 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8183 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8185 struct dwarf2_per_objfile
*dwarf2_per_objfile
8186 = cu
->per_cu
->dwarf2_per_objfile
;
8187 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8188 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8190 const char *actual_name
= NULL
;
8193 baseaddr
= objfile
->text_section_offset ();
8195 gdb::unique_xmalloc_ptr
<char> built_actual_name
8196 = partial_die_full_name (pdi
, cu
);
8197 if (built_actual_name
!= NULL
)
8198 actual_name
= built_actual_name
.get ();
8200 if (actual_name
== NULL
)
8201 actual_name
= pdi
->name
;
8205 case DW_TAG_inlined_subroutine
:
8206 case DW_TAG_subprogram
:
8207 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8209 if (pdi
->is_external
8210 || cu
->language
== language_ada
8211 || (cu
->language
== language_fortran
8212 && pdi
->die_parent
!= NULL
8213 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8215 /* Normally, only "external" DIEs are part of the global scope.
8216 But in Ada and Fortran, we want to be able to access nested
8217 procedures globally. So all Ada and Fortran subprograms are
8218 stored in the global scope. */
8219 add_psymbol_to_list (actual_name
,
8220 built_actual_name
!= NULL
,
8221 VAR_DOMAIN
, LOC_BLOCK
,
8222 SECT_OFF_TEXT (objfile
),
8223 psymbol_placement::GLOBAL
,
8225 cu
->language
, objfile
);
8229 add_psymbol_to_list (actual_name
,
8230 built_actual_name
!= NULL
,
8231 VAR_DOMAIN
, LOC_BLOCK
,
8232 SECT_OFF_TEXT (objfile
),
8233 psymbol_placement::STATIC
,
8234 addr
, cu
->language
, objfile
);
8237 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8238 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8240 case DW_TAG_constant
:
8241 add_psymbol_to_list (actual_name
,
8242 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8243 -1, (pdi
->is_external
8244 ? psymbol_placement::GLOBAL
8245 : psymbol_placement::STATIC
),
8246 0, cu
->language
, objfile
);
8248 case DW_TAG_variable
:
8250 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8254 && !dwarf2_per_objfile
->has_section_at_zero
)
8256 /* A global or static variable may also have been stripped
8257 out by the linker if unused, in which case its address
8258 will be nullified; do not add such variables into partial
8259 symbol table then. */
8261 else if (pdi
->is_external
)
8264 Don't enter into the minimal symbol tables as there is
8265 a minimal symbol table entry from the ELF symbols already.
8266 Enter into partial symbol table if it has a location
8267 descriptor or a type.
8268 If the location descriptor is missing, new_symbol will create
8269 a LOC_UNRESOLVED symbol, the address of the variable will then
8270 be determined from the minimal symbol table whenever the variable
8272 The address for the partial symbol table entry is not
8273 used by GDB, but it comes in handy for debugging partial symbol
8276 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8277 add_psymbol_to_list (actual_name
,
8278 built_actual_name
!= NULL
,
8279 VAR_DOMAIN
, LOC_STATIC
,
8280 SECT_OFF_TEXT (objfile
),
8281 psymbol_placement::GLOBAL
,
8282 addr
, cu
->language
, objfile
);
8286 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8288 /* Static Variable. Skip symbols whose value we cannot know (those
8289 without location descriptors or constant values). */
8290 if (!has_loc
&& !pdi
->has_const_value
)
8293 add_psymbol_to_list (actual_name
,
8294 built_actual_name
!= NULL
,
8295 VAR_DOMAIN
, LOC_STATIC
,
8296 SECT_OFF_TEXT (objfile
),
8297 psymbol_placement::STATIC
,
8299 cu
->language
, objfile
);
8302 case DW_TAG_typedef
:
8303 case DW_TAG_base_type
:
8304 case DW_TAG_subrange_type
:
8305 add_psymbol_to_list (actual_name
,
8306 built_actual_name
!= NULL
,
8307 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8308 psymbol_placement::STATIC
,
8309 0, cu
->language
, objfile
);
8311 case DW_TAG_imported_declaration
:
8312 case DW_TAG_namespace
:
8313 add_psymbol_to_list (actual_name
,
8314 built_actual_name
!= NULL
,
8315 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8316 psymbol_placement::GLOBAL
,
8317 0, cu
->language
, objfile
);
8320 /* With Fortran 77 there might be a "BLOCK DATA" module
8321 available without any name. If so, we skip the module as it
8322 doesn't bring any value. */
8323 if (actual_name
!= nullptr)
8324 add_psymbol_to_list (actual_name
,
8325 built_actual_name
!= NULL
,
8326 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8327 psymbol_placement::GLOBAL
,
8328 0, cu
->language
, objfile
);
8330 case DW_TAG_class_type
:
8331 case DW_TAG_interface_type
:
8332 case DW_TAG_structure_type
:
8333 case DW_TAG_union_type
:
8334 case DW_TAG_enumeration_type
:
8335 /* Skip external references. The DWARF standard says in the section
8336 about "Structure, Union, and Class Type Entries": "An incomplete
8337 structure, union or class type is represented by a structure,
8338 union or class entry that does not have a byte size attribute
8339 and that has a DW_AT_declaration attribute." */
8340 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8343 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8344 static vs. global. */
8345 add_psymbol_to_list (actual_name
,
8346 built_actual_name
!= NULL
,
8347 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8348 cu
->language
== language_cplus
8349 ? psymbol_placement::GLOBAL
8350 : psymbol_placement::STATIC
,
8351 0, cu
->language
, objfile
);
8354 case DW_TAG_enumerator
:
8355 add_psymbol_to_list (actual_name
,
8356 built_actual_name
!= NULL
,
8357 VAR_DOMAIN
, LOC_CONST
, -1,
8358 cu
->language
== language_cplus
8359 ? psymbol_placement::GLOBAL
8360 : psymbol_placement::STATIC
,
8361 0, cu
->language
, objfile
);
8368 /* Read a partial die corresponding to a namespace; also, add a symbol
8369 corresponding to that namespace to the symbol table. NAMESPACE is
8370 the name of the enclosing namespace. */
8373 add_partial_namespace (struct partial_die_info
*pdi
,
8374 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8375 int set_addrmap
, struct dwarf2_cu
*cu
)
8377 /* Add a symbol for the namespace. */
8379 add_partial_symbol (pdi
, cu
);
8381 /* Now scan partial symbols in that namespace. */
8383 if (pdi
->has_children
)
8384 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8387 /* Read a partial die corresponding to a Fortran module. */
8390 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8391 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8393 /* Add a symbol for the namespace. */
8395 add_partial_symbol (pdi
, cu
);
8397 /* Now scan partial symbols in that module. */
8399 if (pdi
->has_children
)
8400 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8403 /* Read a partial die corresponding to a subprogram or an inlined
8404 subprogram and create a partial symbol for that subprogram.
8405 When the CU language allows it, this routine also defines a partial
8406 symbol for each nested subprogram that this subprogram contains.
8407 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8408 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8410 PDI may also be a lexical block, in which case we simply search
8411 recursively for subprograms defined inside that lexical block.
8412 Again, this is only performed when the CU language allows this
8413 type of definitions. */
8416 add_partial_subprogram (struct partial_die_info
*pdi
,
8417 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8418 int set_addrmap
, struct dwarf2_cu
*cu
)
8420 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8422 if (pdi
->has_pc_info
)
8424 if (pdi
->lowpc
< *lowpc
)
8425 *lowpc
= pdi
->lowpc
;
8426 if (pdi
->highpc
> *highpc
)
8427 *highpc
= pdi
->highpc
;
8430 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8431 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8433 CORE_ADDR this_highpc
;
8434 CORE_ADDR this_lowpc
;
8436 baseaddr
= objfile
->text_section_offset ();
8438 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8439 pdi
->lowpc
+ baseaddr
)
8442 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8443 pdi
->highpc
+ baseaddr
)
8445 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8446 this_lowpc
, this_highpc
- 1,
8447 cu
->per_cu
->v
.psymtab
);
8451 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8453 if (!pdi
->is_declaration
)
8454 /* Ignore subprogram DIEs that do not have a name, they are
8455 illegal. Do not emit a complaint at this point, we will
8456 do so when we convert this psymtab into a symtab. */
8458 add_partial_symbol (pdi
, cu
);
8462 if (! pdi
->has_children
)
8465 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8467 pdi
= pdi
->die_child
;
8471 if (pdi
->tag
== DW_TAG_subprogram
8472 || pdi
->tag
== DW_TAG_inlined_subroutine
8473 || pdi
->tag
== DW_TAG_lexical_block
)
8474 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8475 pdi
= pdi
->die_sibling
;
8480 /* Read a partial die corresponding to an enumeration type. */
8483 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8484 struct dwarf2_cu
*cu
)
8486 struct partial_die_info
*pdi
;
8488 if (enum_pdi
->name
!= NULL
)
8489 add_partial_symbol (enum_pdi
, cu
);
8491 pdi
= enum_pdi
->die_child
;
8494 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8495 complaint (_("malformed enumerator DIE ignored"));
8497 add_partial_symbol (pdi
, cu
);
8498 pdi
= pdi
->die_sibling
;
8502 /* Return the initial uleb128 in the die at INFO_PTR. */
8505 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8507 unsigned int bytes_read
;
8509 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8512 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8513 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8515 Return the corresponding abbrev, or NULL if the number is zero (indicating
8516 an empty DIE). In either case *BYTES_READ will be set to the length of
8517 the initial number. */
8519 static struct abbrev_info
*
8520 peek_die_abbrev (const die_reader_specs
&reader
,
8521 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8523 dwarf2_cu
*cu
= reader
.cu
;
8524 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8525 unsigned int abbrev_number
8526 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8528 if (abbrev_number
== 0)
8531 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8534 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8535 " at offset %s [in module %s]"),
8536 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8537 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8543 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8544 Returns a pointer to the end of a series of DIEs, terminated by an empty
8545 DIE. Any children of the skipped DIEs will also be skipped. */
8547 static const gdb_byte
*
8548 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8552 unsigned int bytes_read
;
8553 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8556 return info_ptr
+ bytes_read
;
8558 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8562 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8563 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8564 abbrev corresponding to that skipped uleb128 should be passed in
8565 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8568 static const gdb_byte
*
8569 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8570 struct abbrev_info
*abbrev
)
8572 unsigned int bytes_read
;
8573 struct attribute attr
;
8574 bfd
*abfd
= reader
->abfd
;
8575 struct dwarf2_cu
*cu
= reader
->cu
;
8576 const gdb_byte
*buffer
= reader
->buffer
;
8577 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8578 unsigned int form
, i
;
8580 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8582 /* The only abbrev we care about is DW_AT_sibling. */
8583 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8586 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8588 if (attr
.form
== DW_FORM_ref_addr
)
8589 complaint (_("ignoring absolute DW_AT_sibling"));
8592 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8593 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8595 if (sibling_ptr
< info_ptr
)
8596 complaint (_("DW_AT_sibling points backwards"));
8597 else if (sibling_ptr
> reader
->buffer_end
)
8598 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8604 /* If it isn't DW_AT_sibling, skip this attribute. */
8605 form
= abbrev
->attrs
[i
].form
;
8609 case DW_FORM_ref_addr
:
8610 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8611 and later it is offset sized. */
8612 if (cu
->header
.version
== 2)
8613 info_ptr
+= cu
->header
.addr_size
;
8615 info_ptr
+= cu
->header
.offset_size
;
8617 case DW_FORM_GNU_ref_alt
:
8618 info_ptr
+= cu
->header
.offset_size
;
8621 info_ptr
+= cu
->header
.addr_size
;
8629 case DW_FORM_flag_present
:
8630 case DW_FORM_implicit_const
:
8647 case DW_FORM_ref_sig8
:
8650 case DW_FORM_data16
:
8653 case DW_FORM_string
:
8654 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8655 info_ptr
+= bytes_read
;
8657 case DW_FORM_sec_offset
:
8659 case DW_FORM_GNU_strp_alt
:
8660 info_ptr
+= cu
->header
.offset_size
;
8662 case DW_FORM_exprloc
:
8664 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8665 info_ptr
+= bytes_read
;
8667 case DW_FORM_block1
:
8668 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8670 case DW_FORM_block2
:
8671 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8673 case DW_FORM_block4
:
8674 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8680 case DW_FORM_ref_udata
:
8681 case DW_FORM_GNU_addr_index
:
8682 case DW_FORM_GNU_str_index
:
8683 case DW_FORM_rnglistx
:
8684 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8686 case DW_FORM_indirect
:
8687 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8688 info_ptr
+= bytes_read
;
8689 /* We need to continue parsing from here, so just go back to
8691 goto skip_attribute
;
8694 error (_("Dwarf Error: Cannot handle %s "
8695 "in DWARF reader [in module %s]"),
8696 dwarf_form_name (form
),
8697 bfd_get_filename (abfd
));
8701 if (abbrev
->has_children
)
8702 return skip_children (reader
, info_ptr
);
8707 /* Locate ORIG_PDI's sibling.
8708 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8710 static const gdb_byte
*
8711 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8712 struct partial_die_info
*orig_pdi
,
8713 const gdb_byte
*info_ptr
)
8715 /* Do we know the sibling already? */
8717 if (orig_pdi
->sibling
)
8718 return orig_pdi
->sibling
;
8720 /* Are there any children to deal with? */
8722 if (!orig_pdi
->has_children
)
8725 /* Skip the children the long way. */
8727 return skip_children (reader
, info_ptr
);
8730 /* Expand this partial symbol table into a full symbol table. SELF is
8734 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8736 struct dwarf2_per_objfile
*dwarf2_per_objfile
8737 = get_dwarf2_per_objfile (objfile
);
8739 gdb_assert (!readin
);
8740 /* If this psymtab is constructed from a debug-only objfile, the
8741 has_section_at_zero flag will not necessarily be correct. We
8742 can get the correct value for this flag by looking at the data
8743 associated with the (presumably stripped) associated objfile. */
8744 if (objfile
->separate_debug_objfile_backlink
)
8746 struct dwarf2_per_objfile
*dpo_backlink
8747 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8749 dwarf2_per_objfile
->has_section_at_zero
8750 = dpo_backlink
->has_section_at_zero
;
8753 expand_psymtab (objfile
);
8755 process_cu_includes (dwarf2_per_objfile
);
8758 /* Reading in full CUs. */
8760 /* Add PER_CU to the queue. */
8763 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8764 enum language pretend_language
)
8767 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8770 /* If PER_CU is not yet queued, add it to the queue.
8771 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8773 The result is non-zero if PER_CU was queued, otherwise the result is zero
8774 meaning either PER_CU is already queued or it is already loaded.
8776 N.B. There is an invariant here that if a CU is queued then it is loaded.
8777 The caller is required to load PER_CU if we return non-zero. */
8780 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8781 struct dwarf2_per_cu_data
*per_cu
,
8782 enum language pretend_language
)
8784 /* We may arrive here during partial symbol reading, if we need full
8785 DIEs to process an unusual case (e.g. template arguments). Do
8786 not queue PER_CU, just tell our caller to load its DIEs. */
8787 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8789 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8794 /* Mark the dependence relation so that we don't flush PER_CU
8796 if (dependent_cu
!= NULL
)
8797 dwarf2_add_dependence (dependent_cu
, per_cu
);
8799 /* If it's already on the queue, we have nothing to do. */
8803 /* If the compilation unit is already loaded, just mark it as
8805 if (per_cu
->cu
!= NULL
)
8807 per_cu
->cu
->last_used
= 0;
8811 /* Add it to the queue. */
8812 queue_comp_unit (per_cu
, pretend_language
);
8817 /* Process the queue. */
8820 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8822 if (dwarf_read_debug
)
8824 fprintf_unfiltered (gdb_stdlog
,
8825 "Expanding one or more symtabs of objfile %s ...\n",
8826 objfile_name (dwarf2_per_objfile
->objfile
));
8829 /* The queue starts out with one item, but following a DIE reference
8830 may load a new CU, adding it to the end of the queue. */
8831 while (!dwarf2_per_objfile
->queue
.empty ())
8833 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8835 if ((dwarf2_per_objfile
->using_index
8836 ? !item
.per_cu
->v
.quick
->compunit_symtab
8837 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8838 /* Skip dummy CUs. */
8839 && item
.per_cu
->cu
!= NULL
)
8841 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8842 unsigned int debug_print_threshold
;
8845 if (per_cu
->is_debug_types
)
8847 struct signatured_type
*sig_type
=
8848 (struct signatured_type
*) per_cu
;
8850 sprintf (buf
, "TU %s at offset %s",
8851 hex_string (sig_type
->signature
),
8852 sect_offset_str (per_cu
->sect_off
));
8853 /* There can be 100s of TUs.
8854 Only print them in verbose mode. */
8855 debug_print_threshold
= 2;
8859 sprintf (buf
, "CU at offset %s",
8860 sect_offset_str (per_cu
->sect_off
));
8861 debug_print_threshold
= 1;
8864 if (dwarf_read_debug
>= debug_print_threshold
)
8865 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8867 if (per_cu
->is_debug_types
)
8868 process_full_type_unit (per_cu
, item
.pretend_language
);
8870 process_full_comp_unit (per_cu
, item
.pretend_language
);
8872 if (dwarf_read_debug
>= debug_print_threshold
)
8873 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8876 item
.per_cu
->queued
= 0;
8877 dwarf2_per_objfile
->queue
.pop ();
8880 if (dwarf_read_debug
)
8882 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8883 objfile_name (dwarf2_per_objfile
->objfile
));
8887 /* Read in full symbols for PST, and anything it depends on. */
8890 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8895 read_dependencies (objfile
);
8897 dw2_do_instantiate_symtab (per_cu_data
, false);
8898 gdb_assert (get_compunit_symtab () != nullptr);
8901 /* Trivial hash function for die_info: the hash value of a DIE
8902 is its offset in .debug_info for this objfile. */
8905 die_hash (const void *item
)
8907 const struct die_info
*die
= (const struct die_info
*) item
;
8909 return to_underlying (die
->sect_off
);
8912 /* Trivial comparison function for die_info structures: two DIEs
8913 are equal if they have the same offset. */
8916 die_eq (const void *item_lhs
, const void *item_rhs
)
8918 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8919 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8921 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8924 /* Load the DIEs associated with PER_CU into memory. */
8927 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8929 enum language pretend_language
)
8931 gdb_assert (! this_cu
->is_debug_types
);
8933 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8937 struct dwarf2_cu
*cu
= reader
.cu
;
8938 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8940 gdb_assert (cu
->die_hash
== NULL
);
8942 htab_create_alloc_ex (cu
->header
.length
/ 12,
8946 &cu
->comp_unit_obstack
,
8947 hashtab_obstack_allocate
,
8948 dummy_obstack_deallocate
);
8950 if (reader
.comp_unit_die
->has_children
)
8951 reader
.comp_unit_die
->child
8952 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8953 &info_ptr
, reader
.comp_unit_die
);
8954 cu
->dies
= reader
.comp_unit_die
;
8955 /* comp_unit_die is not stored in die_hash, no need. */
8957 /* We try not to read any attributes in this function, because not
8958 all CUs needed for references have been loaded yet, and symbol
8959 table processing isn't initialized. But we have to set the CU language,
8960 or we won't be able to build types correctly.
8961 Similarly, if we do not read the producer, we can not apply
8962 producer-specific interpretation. */
8963 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8968 /* Add a DIE to the delayed physname list. */
8971 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8972 const char *name
, struct die_info
*die
,
8973 struct dwarf2_cu
*cu
)
8975 struct delayed_method_info mi
;
8977 mi
.fnfield_index
= fnfield_index
;
8981 cu
->method_list
.push_back (mi
);
8984 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8985 "const" / "volatile". If so, decrements LEN by the length of the
8986 modifier and return true. Otherwise return false. */
8990 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8992 size_t mod_len
= sizeof (mod
) - 1;
8993 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9001 /* Compute the physnames of any methods on the CU's method list.
9003 The computation of method physnames is delayed in order to avoid the
9004 (bad) condition that one of the method's formal parameters is of an as yet
9008 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9010 /* Only C++ delays computing physnames. */
9011 if (cu
->method_list
.empty ())
9013 gdb_assert (cu
->language
== language_cplus
);
9015 for (const delayed_method_info
&mi
: cu
->method_list
)
9017 const char *physname
;
9018 struct fn_fieldlist
*fn_flp
9019 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9020 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9021 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9022 = physname
? physname
: "";
9024 /* Since there's no tag to indicate whether a method is a
9025 const/volatile overload, extract that information out of the
9027 if (physname
!= NULL
)
9029 size_t len
= strlen (physname
);
9033 if (physname
[len
] == ')') /* shortcut */
9035 else if (check_modifier (physname
, len
, " const"))
9036 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9037 else if (check_modifier (physname
, len
, " volatile"))
9038 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9045 /* The list is no longer needed. */
9046 cu
->method_list
.clear ();
9049 /* Go objects should be embedded in a DW_TAG_module DIE,
9050 and it's not clear if/how imported objects will appear.
9051 To keep Go support simple until that's worked out,
9052 go back through what we've read and create something usable.
9053 We could do this while processing each DIE, and feels kinda cleaner,
9054 but that way is more invasive.
9055 This is to, for example, allow the user to type "p var" or "b main"
9056 without having to specify the package name, and allow lookups
9057 of module.object to work in contexts that use the expression
9061 fixup_go_packaging (struct dwarf2_cu
*cu
)
9063 gdb::unique_xmalloc_ptr
<char> package_name
;
9064 struct pending
*list
;
9067 for (list
= *cu
->get_builder ()->get_global_symbols ();
9071 for (i
= 0; i
< list
->nsyms
; ++i
)
9073 struct symbol
*sym
= list
->symbol
[i
];
9075 if (sym
->language () == language_go
9076 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9078 gdb::unique_xmalloc_ptr
<char> this_package_name
9079 (go_symbol_package_name (sym
));
9081 if (this_package_name
== NULL
)
9083 if (package_name
== NULL
)
9084 package_name
= std::move (this_package_name
);
9087 struct objfile
*objfile
9088 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9089 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9090 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9091 (symbol_symtab (sym
) != NULL
9092 ? symtab_to_filename_for_display
9093 (symbol_symtab (sym
))
9094 : objfile_name (objfile
)),
9095 this_package_name
.get (), package_name
.get ());
9101 if (package_name
!= NULL
)
9103 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9104 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9105 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9106 saved_package_name
);
9109 sym
= allocate_symbol (objfile
);
9110 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9111 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9112 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9113 e.g., "main" finds the "main" module and not C's main(). */
9114 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9115 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9116 SYMBOL_TYPE (sym
) = type
;
9118 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9122 /* Allocate a fully-qualified name consisting of the two parts on the
9126 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9128 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9131 /* A helper that allocates a struct discriminant_info to attach to a
9134 static struct discriminant_info
*
9135 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9138 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9139 gdb_assert (discriminant_index
== -1
9140 || (discriminant_index
>= 0
9141 && discriminant_index
< TYPE_NFIELDS (type
)));
9142 gdb_assert (default_index
== -1
9143 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9145 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9147 struct discriminant_info
*disc
9148 = ((struct discriminant_info
*)
9150 offsetof (struct discriminant_info
, discriminants
)
9151 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9152 disc
->default_index
= default_index
;
9153 disc
->discriminant_index
= discriminant_index
;
9155 struct dynamic_prop prop
;
9156 prop
.kind
= PROP_UNDEFINED
;
9157 prop
.data
.baton
= disc
;
9159 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9164 /* Some versions of rustc emitted enums in an unusual way.
9166 Ordinary enums were emitted as unions. The first element of each
9167 structure in the union was named "RUST$ENUM$DISR". This element
9168 held the discriminant.
9170 These versions of Rust also implemented the "non-zero"
9171 optimization. When the enum had two values, and one is empty and
9172 the other holds a pointer that cannot be zero, the pointer is used
9173 as the discriminant, with a zero value meaning the empty variant.
9174 Here, the union's first member is of the form
9175 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9176 where the fieldnos are the indices of the fields that should be
9177 traversed in order to find the field (which may be several fields deep)
9178 and the variantname is the name of the variant of the case when the
9181 This function recognizes whether TYPE is of one of these forms,
9182 and, if so, smashes it to be a variant type. */
9185 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9187 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9189 /* We don't need to deal with empty enums. */
9190 if (TYPE_NFIELDS (type
) == 0)
9193 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9194 if (TYPE_NFIELDS (type
) == 1
9195 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9197 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9199 /* Decode the field name to find the offset of the
9201 ULONGEST bit_offset
= 0;
9202 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9203 while (name
[0] >= '0' && name
[0] <= '9')
9206 unsigned long index
= strtoul (name
, &tail
, 10);
9209 || index
>= TYPE_NFIELDS (field_type
)
9210 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9211 != FIELD_LOC_KIND_BITPOS
))
9213 complaint (_("Could not parse Rust enum encoding string \"%s\""
9215 TYPE_FIELD_NAME (type
, 0),
9216 objfile_name (objfile
));
9221 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9222 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9225 /* Make a union to hold the variants. */
9226 struct type
*union_type
= alloc_type (objfile
);
9227 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9228 TYPE_NFIELDS (union_type
) = 3;
9229 TYPE_FIELDS (union_type
)
9230 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9231 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9232 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9234 /* Put the discriminant must at index 0. */
9235 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9236 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9237 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9238 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9240 /* The order of fields doesn't really matter, so put the real
9241 field at index 1 and the data-less field at index 2. */
9242 struct discriminant_info
*disc
9243 = alloc_discriminant_info (union_type
, 0, 1);
9244 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9245 TYPE_FIELD_NAME (union_type
, 1)
9246 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9247 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9248 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9249 TYPE_FIELD_NAME (union_type
, 1));
9251 const char *dataless_name
9252 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9254 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9256 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9257 /* NAME points into the original discriminant name, which
9258 already has the correct lifetime. */
9259 TYPE_FIELD_NAME (union_type
, 2) = name
;
9260 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9261 disc
->discriminants
[2] = 0;
9263 /* Smash this type to be a structure type. We have to do this
9264 because the type has already been recorded. */
9265 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9266 TYPE_NFIELDS (type
) = 1;
9268 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9270 /* Install the variant part. */
9271 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9272 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9273 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9275 /* A union with a single anonymous field is probably an old-style
9277 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9279 /* Smash this type to be a structure type. We have to do this
9280 because the type has already been recorded. */
9281 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9283 /* Make a union to hold the variants. */
9284 struct type
*union_type
= alloc_type (objfile
);
9285 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9286 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9287 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9288 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9289 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9291 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9292 const char *variant_name
9293 = rust_last_path_segment (TYPE_NAME (field_type
));
9294 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9295 TYPE_NAME (field_type
)
9296 = rust_fully_qualify (&objfile
->objfile_obstack
,
9297 TYPE_NAME (type
), variant_name
);
9299 /* Install the union in the outer struct type. */
9300 TYPE_NFIELDS (type
) = 1;
9302 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9303 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9304 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9305 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9307 alloc_discriminant_info (union_type
, -1, 0);
9311 struct type
*disr_type
= nullptr;
9312 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9314 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9316 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9318 /* All fields of a true enum will be structs. */
9321 else if (TYPE_NFIELDS (disr_type
) == 0)
9323 /* Could be data-less variant, so keep going. */
9324 disr_type
= nullptr;
9326 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9327 "RUST$ENUM$DISR") != 0)
9329 /* Not a Rust enum. */
9339 /* If we got here without a discriminant, then it's probably
9341 if (disr_type
== nullptr)
9344 /* Smash this type to be a structure type. We have to do this
9345 because the type has already been recorded. */
9346 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9348 /* Make a union to hold the variants. */
9349 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9350 struct type
*union_type
= alloc_type (objfile
);
9351 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9352 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9353 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9354 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9355 TYPE_FIELDS (union_type
)
9356 = (struct field
*) TYPE_ZALLOC (union_type
,
9357 (TYPE_NFIELDS (union_type
)
9358 * sizeof (struct field
)));
9360 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9361 TYPE_NFIELDS (type
) * sizeof (struct field
));
9363 /* Install the discriminant at index 0 in the union. */
9364 TYPE_FIELD (union_type
, 0) = *disr_field
;
9365 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9366 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9368 /* Install the union in the outer struct type. */
9369 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9370 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9371 TYPE_NFIELDS (type
) = 1;
9373 /* Set the size and offset of the union type. */
9374 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9376 /* We need a way to find the correct discriminant given a
9377 variant name. For convenience we build a map here. */
9378 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9379 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9380 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9382 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9385 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9386 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9390 int n_fields
= TYPE_NFIELDS (union_type
);
9391 struct discriminant_info
*disc
9392 = alloc_discriminant_info (union_type
, 0, -1);
9393 /* Skip the discriminant here. */
9394 for (int i
= 1; i
< n_fields
; ++i
)
9396 /* Find the final word in the name of this variant's type.
9397 That name can be used to look up the correct
9399 const char *variant_name
9400 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9403 auto iter
= discriminant_map
.find (variant_name
);
9404 if (iter
!= discriminant_map
.end ())
9405 disc
->discriminants
[i
] = iter
->second
;
9407 /* Remove the discriminant field, if it exists. */
9408 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9409 if (TYPE_NFIELDS (sub_type
) > 0)
9411 --TYPE_NFIELDS (sub_type
);
9412 ++TYPE_FIELDS (sub_type
);
9414 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9415 TYPE_NAME (sub_type
)
9416 = rust_fully_qualify (&objfile
->objfile_obstack
,
9417 TYPE_NAME (type
), variant_name
);
9422 /* Rewrite some Rust unions to be structures with variants parts. */
9425 rust_union_quirks (struct dwarf2_cu
*cu
)
9427 gdb_assert (cu
->language
== language_rust
);
9428 for (type
*type_
: cu
->rust_unions
)
9429 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9430 /* We don't need this any more. */
9431 cu
->rust_unions
.clear ();
9434 /* Return the symtab for PER_CU. This works properly regardless of
9435 whether we're using the index or psymtabs. */
9437 static struct compunit_symtab
*
9438 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9440 return (per_cu
->dwarf2_per_objfile
->using_index
9441 ? per_cu
->v
.quick
->compunit_symtab
9442 : per_cu
->v
.psymtab
->compunit_symtab
);
9445 /* A helper function for computing the list of all symbol tables
9446 included by PER_CU. */
9449 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9450 htab_t all_children
, htab_t all_type_symtabs
,
9451 struct dwarf2_per_cu_data
*per_cu
,
9452 struct compunit_symtab
*immediate_parent
)
9455 struct compunit_symtab
*cust
;
9457 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9460 /* This inclusion and its children have been processed. */
9465 /* Only add a CU if it has a symbol table. */
9466 cust
= get_compunit_symtab (per_cu
);
9469 /* If this is a type unit only add its symbol table if we haven't
9470 seen it yet (type unit per_cu's can share symtabs). */
9471 if (per_cu
->is_debug_types
)
9473 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9477 result
->push_back (cust
);
9478 if (cust
->user
== NULL
)
9479 cust
->user
= immediate_parent
;
9484 result
->push_back (cust
);
9485 if (cust
->user
== NULL
)
9486 cust
->user
= immediate_parent
;
9490 if (!per_cu
->imported_symtabs_empty ())
9491 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9493 recursively_compute_inclusions (result
, all_children
,
9494 all_type_symtabs
, ptr
, cust
);
9498 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9502 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9504 gdb_assert (! per_cu
->is_debug_types
);
9506 if (!per_cu
->imported_symtabs_empty ())
9509 std::vector
<compunit_symtab
*> result_symtabs
;
9510 htab_t all_children
, all_type_symtabs
;
9511 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9513 /* If we don't have a symtab, we can just skip this case. */
9517 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9518 NULL
, xcalloc
, xfree
);
9519 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9520 NULL
, xcalloc
, xfree
);
9522 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9524 recursively_compute_inclusions (&result_symtabs
, all_children
,
9525 all_type_symtabs
, ptr
, cust
);
9528 /* Now we have a transitive closure of all the included symtabs. */
9529 len
= result_symtabs
.size ();
9531 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9532 struct compunit_symtab
*, len
+ 1);
9533 memcpy (cust
->includes
, result_symtabs
.data (),
9534 len
* sizeof (compunit_symtab
*));
9535 cust
->includes
[len
] = NULL
;
9537 htab_delete (all_children
);
9538 htab_delete (all_type_symtabs
);
9542 /* Compute the 'includes' field for the symtabs of all the CUs we just
9546 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9548 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9550 if (! iter
->is_debug_types
)
9551 compute_compunit_symtab_includes (iter
);
9554 dwarf2_per_objfile
->just_read_cus
.clear ();
9557 /* Generate full symbol information for PER_CU, whose DIEs have
9558 already been loaded into memory. */
9561 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9562 enum language pretend_language
)
9564 struct dwarf2_cu
*cu
= per_cu
->cu
;
9565 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9566 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9567 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9568 CORE_ADDR lowpc
, highpc
;
9569 struct compunit_symtab
*cust
;
9571 struct block
*static_block
;
9574 baseaddr
= objfile
->text_section_offset ();
9576 /* Clear the list here in case something was left over. */
9577 cu
->method_list
.clear ();
9579 cu
->language
= pretend_language
;
9580 cu
->language_defn
= language_def (cu
->language
);
9582 /* Do line number decoding in read_file_scope () */
9583 process_die (cu
->dies
, cu
);
9585 /* For now fudge the Go package. */
9586 if (cu
->language
== language_go
)
9587 fixup_go_packaging (cu
);
9589 /* Now that we have processed all the DIEs in the CU, all the types
9590 should be complete, and it should now be safe to compute all of the
9592 compute_delayed_physnames (cu
);
9594 if (cu
->language
== language_rust
)
9595 rust_union_quirks (cu
);
9597 /* Some compilers don't define a DW_AT_high_pc attribute for the
9598 compilation unit. If the DW_AT_high_pc is missing, synthesize
9599 it, by scanning the DIE's below the compilation unit. */
9600 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9602 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9603 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9605 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9606 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9607 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9608 addrmap to help ensure it has an accurate map of pc values belonging to
9610 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9612 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9613 SECT_OFF_TEXT (objfile
),
9618 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9620 /* Set symtab language to language from DW_AT_language. If the
9621 compilation is from a C file generated by language preprocessors, do
9622 not set the language if it was already deduced by start_subfile. */
9623 if (!(cu
->language
== language_c
9624 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9625 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9627 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9628 produce DW_AT_location with location lists but it can be possibly
9629 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9630 there were bugs in prologue debug info, fixed later in GCC-4.5
9631 by "unwind info for epilogues" patch (which is not directly related).
9633 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9634 needed, it would be wrong due to missing DW_AT_producer there.
9636 Still one can confuse GDB by using non-standard GCC compilation
9637 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9639 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9640 cust
->locations_valid
= 1;
9642 if (gcc_4_minor
>= 5)
9643 cust
->epilogue_unwind_valid
= 1;
9645 cust
->call_site_htab
= cu
->call_site_htab
;
9648 if (dwarf2_per_objfile
->using_index
)
9649 per_cu
->v
.quick
->compunit_symtab
= cust
;
9652 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9653 pst
->compunit_symtab
= cust
;
9657 /* Push it for inclusion processing later. */
9658 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9660 /* Not needed any more. */
9661 cu
->reset_builder ();
9664 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9665 already been loaded into memory. */
9668 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9669 enum language pretend_language
)
9671 struct dwarf2_cu
*cu
= per_cu
->cu
;
9672 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9673 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9674 struct compunit_symtab
*cust
;
9675 struct signatured_type
*sig_type
;
9677 gdb_assert (per_cu
->is_debug_types
);
9678 sig_type
= (struct signatured_type
*) per_cu
;
9680 /* Clear the list here in case something was left over. */
9681 cu
->method_list
.clear ();
9683 cu
->language
= pretend_language
;
9684 cu
->language_defn
= language_def (cu
->language
);
9686 /* The symbol tables are set up in read_type_unit_scope. */
9687 process_die (cu
->dies
, cu
);
9689 /* For now fudge the Go package. */
9690 if (cu
->language
== language_go
)
9691 fixup_go_packaging (cu
);
9693 /* Now that we have processed all the DIEs in the CU, all the types
9694 should be complete, and it should now be safe to compute all of the
9696 compute_delayed_physnames (cu
);
9698 if (cu
->language
== language_rust
)
9699 rust_union_quirks (cu
);
9701 /* TUs share symbol tables.
9702 If this is the first TU to use this symtab, complete the construction
9703 of it with end_expandable_symtab. Otherwise, complete the addition of
9704 this TU's symbols to the existing symtab. */
9705 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9707 buildsym_compunit
*builder
= cu
->get_builder ();
9708 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9709 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9713 /* Set symtab language to language from DW_AT_language. If the
9714 compilation is from a C file generated by language preprocessors,
9715 do not set the language if it was already deduced by
9717 if (!(cu
->language
== language_c
9718 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9719 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9724 cu
->get_builder ()->augment_type_symtab ();
9725 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9728 if (dwarf2_per_objfile
->using_index
)
9729 per_cu
->v
.quick
->compunit_symtab
= cust
;
9732 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9733 pst
->compunit_symtab
= cust
;
9737 /* Not needed any more. */
9738 cu
->reset_builder ();
9741 /* Process an imported unit DIE. */
9744 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9746 struct attribute
*attr
;
9748 /* For now we don't handle imported units in type units. */
9749 if (cu
->per_cu
->is_debug_types
)
9751 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9752 " supported in type units [in module %s]"),
9753 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9756 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9759 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9760 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9761 dwarf2_per_cu_data
*per_cu
9762 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9763 cu
->per_cu
->dwarf2_per_objfile
);
9765 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9766 into another compilation unit, at root level. Regard this as a hint,
9768 if (die
->parent
&& die
->parent
->parent
== NULL
9769 && per_cu
->unit_type
== DW_UT_compile
9770 && per_cu
->lang
== language_cplus
)
9773 /* If necessary, add it to the queue and load its DIEs. */
9774 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9775 load_full_comp_unit (per_cu
, false, cu
->language
);
9777 cu
->per_cu
->imported_symtabs_push (per_cu
);
9781 /* RAII object that represents a process_die scope: i.e.,
9782 starts/finishes processing a DIE. */
9783 class process_die_scope
9786 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9787 : m_die (die
), m_cu (cu
)
9789 /* We should only be processing DIEs not already in process. */
9790 gdb_assert (!m_die
->in_process
);
9791 m_die
->in_process
= true;
9794 ~process_die_scope ()
9796 m_die
->in_process
= false;
9798 /* If we're done processing the DIE for the CU that owns the line
9799 header, we don't need the line header anymore. */
9800 if (m_cu
->line_header_die_owner
== m_die
)
9802 delete m_cu
->line_header
;
9803 m_cu
->line_header
= NULL
;
9804 m_cu
->line_header_die_owner
= NULL
;
9813 /* Process a die and its children. */
9816 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9818 process_die_scope
scope (die
, cu
);
9822 case DW_TAG_padding
:
9824 case DW_TAG_compile_unit
:
9825 case DW_TAG_partial_unit
:
9826 read_file_scope (die
, cu
);
9828 case DW_TAG_type_unit
:
9829 read_type_unit_scope (die
, cu
);
9831 case DW_TAG_subprogram
:
9832 /* Nested subprograms in Fortran get a prefix. */
9833 if (cu
->language
== language_fortran
9834 && die
->parent
!= NULL
9835 && die
->parent
->tag
== DW_TAG_subprogram
)
9836 cu
->processing_has_namespace_info
= true;
9838 case DW_TAG_inlined_subroutine
:
9839 read_func_scope (die
, cu
);
9841 case DW_TAG_lexical_block
:
9842 case DW_TAG_try_block
:
9843 case DW_TAG_catch_block
:
9844 read_lexical_block_scope (die
, cu
);
9846 case DW_TAG_call_site
:
9847 case DW_TAG_GNU_call_site
:
9848 read_call_site_scope (die
, cu
);
9850 case DW_TAG_class_type
:
9851 case DW_TAG_interface_type
:
9852 case DW_TAG_structure_type
:
9853 case DW_TAG_union_type
:
9854 process_structure_scope (die
, cu
);
9856 case DW_TAG_enumeration_type
:
9857 process_enumeration_scope (die
, cu
);
9860 /* These dies have a type, but processing them does not create
9861 a symbol or recurse to process the children. Therefore we can
9862 read them on-demand through read_type_die. */
9863 case DW_TAG_subroutine_type
:
9864 case DW_TAG_set_type
:
9865 case DW_TAG_array_type
:
9866 case DW_TAG_pointer_type
:
9867 case DW_TAG_ptr_to_member_type
:
9868 case DW_TAG_reference_type
:
9869 case DW_TAG_rvalue_reference_type
:
9870 case DW_TAG_string_type
:
9873 case DW_TAG_base_type
:
9874 case DW_TAG_subrange_type
:
9875 case DW_TAG_typedef
:
9876 /* Add a typedef symbol for the type definition, if it has a
9878 new_symbol (die
, read_type_die (die
, cu
), cu
);
9880 case DW_TAG_common_block
:
9881 read_common_block (die
, cu
);
9883 case DW_TAG_common_inclusion
:
9885 case DW_TAG_namespace
:
9886 cu
->processing_has_namespace_info
= true;
9887 read_namespace (die
, cu
);
9890 cu
->processing_has_namespace_info
= true;
9891 read_module (die
, cu
);
9893 case DW_TAG_imported_declaration
:
9894 cu
->processing_has_namespace_info
= true;
9895 if (read_namespace_alias (die
, cu
))
9897 /* The declaration is not a global namespace alias. */
9899 case DW_TAG_imported_module
:
9900 cu
->processing_has_namespace_info
= true;
9901 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9902 || cu
->language
!= language_fortran
))
9903 complaint (_("Tag '%s' has unexpected children"),
9904 dwarf_tag_name (die
->tag
));
9905 read_import_statement (die
, cu
);
9908 case DW_TAG_imported_unit
:
9909 process_imported_unit_die (die
, cu
);
9912 case DW_TAG_variable
:
9913 read_variable (die
, cu
);
9917 new_symbol (die
, NULL
, cu
);
9922 /* DWARF name computation. */
9924 /* A helper function for dwarf2_compute_name which determines whether DIE
9925 needs to have the name of the scope prepended to the name listed in the
9929 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9931 struct attribute
*attr
;
9935 case DW_TAG_namespace
:
9936 case DW_TAG_typedef
:
9937 case DW_TAG_class_type
:
9938 case DW_TAG_interface_type
:
9939 case DW_TAG_structure_type
:
9940 case DW_TAG_union_type
:
9941 case DW_TAG_enumeration_type
:
9942 case DW_TAG_enumerator
:
9943 case DW_TAG_subprogram
:
9944 case DW_TAG_inlined_subroutine
:
9946 case DW_TAG_imported_declaration
:
9949 case DW_TAG_variable
:
9950 case DW_TAG_constant
:
9951 /* We only need to prefix "globally" visible variables. These include
9952 any variable marked with DW_AT_external or any variable that
9953 lives in a namespace. [Variables in anonymous namespaces
9954 require prefixing, but they are not DW_AT_external.] */
9956 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9958 struct dwarf2_cu
*spec_cu
= cu
;
9960 return die_needs_namespace (die_specification (die
, &spec_cu
),
9964 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9965 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9966 && die
->parent
->tag
!= DW_TAG_module
)
9968 /* A variable in a lexical block of some kind does not need a
9969 namespace, even though in C++ such variables may be external
9970 and have a mangled name. */
9971 if (die
->parent
->tag
== DW_TAG_lexical_block
9972 || die
->parent
->tag
== DW_TAG_try_block
9973 || die
->parent
->tag
== DW_TAG_catch_block
9974 || die
->parent
->tag
== DW_TAG_subprogram
)
9983 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9984 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9985 defined for the given DIE. */
9987 static struct attribute
*
9988 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9990 struct attribute
*attr
;
9992 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9994 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9999 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10000 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10001 defined for the given DIE. */
10003 static const char *
10004 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10006 const char *linkage_name
;
10008 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10009 if (linkage_name
== NULL
)
10010 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10012 return linkage_name
;
10015 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10016 compute the physname for the object, which include a method's:
10017 - formal parameters (C++),
10018 - receiver type (Go),
10020 The term "physname" is a bit confusing.
10021 For C++, for example, it is the demangled name.
10022 For Go, for example, it's the mangled name.
10024 For Ada, return the DIE's linkage name rather than the fully qualified
10025 name. PHYSNAME is ignored..
10027 The result is allocated on the objfile_obstack and canonicalized. */
10029 static const char *
10030 dwarf2_compute_name (const char *name
,
10031 struct die_info
*die
, struct dwarf2_cu
*cu
,
10034 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10037 name
= dwarf2_name (die
, cu
);
10039 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10040 but otherwise compute it by typename_concat inside GDB.
10041 FIXME: Actually this is not really true, or at least not always true.
10042 It's all very confusing. compute_and_set_names doesn't try to demangle
10043 Fortran names because there is no mangling standard. So new_symbol
10044 will set the demangled name to the result of dwarf2_full_name, and it is
10045 the demangled name that GDB uses if it exists. */
10046 if (cu
->language
== language_ada
10047 || (cu
->language
== language_fortran
&& physname
))
10049 /* For Ada unit, we prefer the linkage name over the name, as
10050 the former contains the exported name, which the user expects
10051 to be able to reference. Ideally, we want the user to be able
10052 to reference this entity using either natural or linkage name,
10053 but we haven't started looking at this enhancement yet. */
10054 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10056 if (linkage_name
!= NULL
)
10057 return linkage_name
;
10060 /* These are the only languages we know how to qualify names in. */
10062 && (cu
->language
== language_cplus
10063 || cu
->language
== language_fortran
|| cu
->language
== language_d
10064 || cu
->language
== language_rust
))
10066 if (die_needs_namespace (die
, cu
))
10068 const char *prefix
;
10069 const char *canonical_name
= NULL
;
10073 prefix
= determine_prefix (die
, cu
);
10074 if (*prefix
!= '\0')
10076 gdb::unique_xmalloc_ptr
<char> prefixed_name
10077 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10079 buf
.puts (prefixed_name
.get ());
10084 /* Template parameters may be specified in the DIE's DW_AT_name, or
10085 as children with DW_TAG_template_type_param or
10086 DW_TAG_value_type_param. If the latter, add them to the name
10087 here. If the name already has template parameters, then
10088 skip this step; some versions of GCC emit both, and
10089 it is more efficient to use the pre-computed name.
10091 Something to keep in mind about this process: it is very
10092 unlikely, or in some cases downright impossible, to produce
10093 something that will match the mangled name of a function.
10094 If the definition of the function has the same debug info,
10095 we should be able to match up with it anyway. But fallbacks
10096 using the minimal symbol, for instance to find a method
10097 implemented in a stripped copy of libstdc++, will not work.
10098 If we do not have debug info for the definition, we will have to
10099 match them up some other way.
10101 When we do name matching there is a related problem with function
10102 templates; two instantiated function templates are allowed to
10103 differ only by their return types, which we do not add here. */
10105 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10107 struct attribute
*attr
;
10108 struct die_info
*child
;
10111 die
->building_fullname
= 1;
10113 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10117 const gdb_byte
*bytes
;
10118 struct dwarf2_locexpr_baton
*baton
;
10121 if (child
->tag
!= DW_TAG_template_type_param
10122 && child
->tag
!= DW_TAG_template_value_param
)
10133 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10136 complaint (_("template parameter missing DW_AT_type"));
10137 buf
.puts ("UNKNOWN_TYPE");
10140 type
= die_type (child
, cu
);
10142 if (child
->tag
== DW_TAG_template_type_param
)
10144 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10145 &type_print_raw_options
);
10149 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10152 complaint (_("template parameter missing "
10153 "DW_AT_const_value"));
10154 buf
.puts ("UNKNOWN_VALUE");
10158 dwarf2_const_value_attr (attr
, type
, name
,
10159 &cu
->comp_unit_obstack
, cu
,
10160 &value
, &bytes
, &baton
);
10162 if (TYPE_NOSIGN (type
))
10163 /* GDB prints characters as NUMBER 'CHAR'. If that's
10164 changed, this can use value_print instead. */
10165 c_printchar (value
, type
, &buf
);
10168 struct value_print_options opts
;
10171 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10175 else if (bytes
!= NULL
)
10177 v
= allocate_value (type
);
10178 memcpy (value_contents_writeable (v
), bytes
,
10179 TYPE_LENGTH (type
));
10182 v
= value_from_longest (type
, value
);
10184 /* Specify decimal so that we do not depend on
10186 get_formatted_print_options (&opts
, 'd');
10188 value_print (v
, &buf
, &opts
);
10193 die
->building_fullname
= 0;
10197 /* Close the argument list, with a space if necessary
10198 (nested templates). */
10199 if (!buf
.empty () && buf
.string ().back () == '>')
10206 /* For C++ methods, append formal parameter type
10207 information, if PHYSNAME. */
10209 if (physname
&& die
->tag
== DW_TAG_subprogram
10210 && cu
->language
== language_cplus
)
10212 struct type
*type
= read_type_die (die
, cu
);
10214 c_type_print_args (type
, &buf
, 1, cu
->language
,
10215 &type_print_raw_options
);
10217 if (cu
->language
== language_cplus
)
10219 /* Assume that an artificial first parameter is
10220 "this", but do not crash if it is not. RealView
10221 marks unnamed (and thus unused) parameters as
10222 artificial; there is no way to differentiate
10224 if (TYPE_NFIELDS (type
) > 0
10225 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10226 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10227 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10229 buf
.puts (" const");
10233 const std::string
&intermediate_name
= buf
.string ();
10235 if (cu
->language
== language_cplus
)
10237 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10240 /* If we only computed INTERMEDIATE_NAME, or if
10241 INTERMEDIATE_NAME is already canonical, then we need to
10243 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10244 name
= objfile
->intern (intermediate_name
);
10246 name
= canonical_name
;
10253 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10254 If scope qualifiers are appropriate they will be added. The result
10255 will be allocated on the storage_obstack, or NULL if the DIE does
10256 not have a name. NAME may either be from a previous call to
10257 dwarf2_name or NULL.
10259 The output string will be canonicalized (if C++). */
10261 static const char *
10262 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10264 return dwarf2_compute_name (name
, die
, cu
, 0);
10267 /* Construct a physname for the given DIE in CU. NAME may either be
10268 from a previous call to dwarf2_name or NULL. The result will be
10269 allocated on the objfile_objstack or NULL if the DIE does not have a
10272 The output string will be canonicalized (if C++). */
10274 static const char *
10275 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10277 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10278 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10281 /* In this case dwarf2_compute_name is just a shortcut not building anything
10283 if (!die_needs_namespace (die
, cu
))
10284 return dwarf2_compute_name (name
, die
, cu
, 1);
10286 mangled
= dw2_linkage_name (die
, cu
);
10288 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10289 See https://github.com/rust-lang/rust/issues/32925. */
10290 if (cu
->language
== language_rust
&& mangled
!= NULL
10291 && strchr (mangled
, '{') != NULL
)
10294 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10296 gdb::unique_xmalloc_ptr
<char> demangled
;
10297 if (mangled
!= NULL
)
10300 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10302 /* Do nothing (do not demangle the symbol name). */
10304 else if (cu
->language
== language_go
)
10306 /* This is a lie, but we already lie to the caller new_symbol.
10307 new_symbol assumes we return the mangled name.
10308 This just undoes that lie until things are cleaned up. */
10312 /* Use DMGL_RET_DROP for C++ template functions to suppress
10313 their return type. It is easier for GDB users to search
10314 for such functions as `name(params)' than `long name(params)'.
10315 In such case the minimal symbol names do not match the full
10316 symbol names but for template functions there is never a need
10317 to look up their definition from their declaration so
10318 the only disadvantage remains the minimal symbol variant
10319 `long name(params)' does not have the proper inferior type. */
10320 demangled
.reset (gdb_demangle (mangled
,
10321 (DMGL_PARAMS
| DMGL_ANSI
10322 | DMGL_RET_DROP
)));
10325 canon
= demangled
.get ();
10333 if (canon
== NULL
|| check_physname
)
10335 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10337 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10339 /* It may not mean a bug in GDB. The compiler could also
10340 compute DW_AT_linkage_name incorrectly. But in such case
10341 GDB would need to be bug-to-bug compatible. */
10343 complaint (_("Computed physname <%s> does not match demangled <%s> "
10344 "(from linkage <%s>) - DIE at %s [in module %s]"),
10345 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10346 objfile_name (objfile
));
10348 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10349 is available here - over computed PHYSNAME. It is safer
10350 against both buggy GDB and buggy compilers. */
10364 retval
= objfile
->intern (retval
);
10369 /* Inspect DIE in CU for a namespace alias. If one exists, record
10370 a new symbol for it.
10372 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10375 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10377 struct attribute
*attr
;
10379 /* If the die does not have a name, this is not a namespace
10381 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10385 struct die_info
*d
= die
;
10386 struct dwarf2_cu
*imported_cu
= cu
;
10388 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10389 keep inspecting DIEs until we hit the underlying import. */
10390 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10391 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10393 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10397 d
= follow_die_ref (d
, attr
, &imported_cu
);
10398 if (d
->tag
!= DW_TAG_imported_declaration
)
10402 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10404 complaint (_("DIE at %s has too many recursively imported "
10405 "declarations"), sect_offset_str (d
->sect_off
));
10412 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10414 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10415 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10417 /* This declaration is a global namespace alias. Add
10418 a symbol for it whose type is the aliased namespace. */
10419 new_symbol (die
, type
, cu
);
10428 /* Return the using directives repository (global or local?) to use in the
10429 current context for CU.
10431 For Ada, imported declarations can materialize renamings, which *may* be
10432 global. However it is impossible (for now?) in DWARF to distinguish
10433 "external" imported declarations and "static" ones. As all imported
10434 declarations seem to be static in all other languages, make them all CU-wide
10435 global only in Ada. */
10437 static struct using_direct
**
10438 using_directives (struct dwarf2_cu
*cu
)
10440 if (cu
->language
== language_ada
10441 && cu
->get_builder ()->outermost_context_p ())
10442 return cu
->get_builder ()->get_global_using_directives ();
10444 return cu
->get_builder ()->get_local_using_directives ();
10447 /* Read the import statement specified by the given die and record it. */
10450 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10452 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10453 struct attribute
*import_attr
;
10454 struct die_info
*imported_die
, *child_die
;
10455 struct dwarf2_cu
*imported_cu
;
10456 const char *imported_name
;
10457 const char *imported_name_prefix
;
10458 const char *canonical_name
;
10459 const char *import_alias
;
10460 const char *imported_declaration
= NULL
;
10461 const char *import_prefix
;
10462 std::vector
<const char *> excludes
;
10464 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10465 if (import_attr
== NULL
)
10467 complaint (_("Tag '%s' has no DW_AT_import"),
10468 dwarf_tag_name (die
->tag
));
10473 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10474 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10475 if (imported_name
== NULL
)
10477 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10479 The import in the following code:
10493 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10494 <52> DW_AT_decl_file : 1
10495 <53> DW_AT_decl_line : 6
10496 <54> DW_AT_import : <0x75>
10497 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10498 <59> DW_AT_name : B
10499 <5b> DW_AT_decl_file : 1
10500 <5c> DW_AT_decl_line : 2
10501 <5d> DW_AT_type : <0x6e>
10503 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10504 <76> DW_AT_byte_size : 4
10505 <77> DW_AT_encoding : 5 (signed)
10507 imports the wrong die ( 0x75 instead of 0x58 ).
10508 This case will be ignored until the gcc bug is fixed. */
10512 /* Figure out the local name after import. */
10513 import_alias
= dwarf2_name (die
, cu
);
10515 /* Figure out where the statement is being imported to. */
10516 import_prefix
= determine_prefix (die
, cu
);
10518 /* Figure out what the scope of the imported die is and prepend it
10519 to the name of the imported die. */
10520 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10522 if (imported_die
->tag
!= DW_TAG_namespace
10523 && imported_die
->tag
!= DW_TAG_module
)
10525 imported_declaration
= imported_name
;
10526 canonical_name
= imported_name_prefix
;
10528 else if (strlen (imported_name_prefix
) > 0)
10529 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10530 imported_name_prefix
,
10531 (cu
->language
== language_d
? "." : "::"),
10532 imported_name
, (char *) NULL
);
10534 canonical_name
= imported_name
;
10536 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10537 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10538 child_die
= sibling_die (child_die
))
10540 /* DWARF-4: A Fortran use statement with a “rename list” may be
10541 represented by an imported module entry with an import attribute
10542 referring to the module and owned entries corresponding to those
10543 entities that are renamed as part of being imported. */
10545 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10547 complaint (_("child DW_TAG_imported_declaration expected "
10548 "- DIE at %s [in module %s]"),
10549 sect_offset_str (child_die
->sect_off
),
10550 objfile_name (objfile
));
10554 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10555 if (import_attr
== NULL
)
10557 complaint (_("Tag '%s' has no DW_AT_import"),
10558 dwarf_tag_name (child_die
->tag
));
10563 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10565 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10566 if (imported_name
== NULL
)
10568 complaint (_("child DW_TAG_imported_declaration has unknown "
10569 "imported name - DIE at %s [in module %s]"),
10570 sect_offset_str (child_die
->sect_off
),
10571 objfile_name (objfile
));
10575 excludes
.push_back (imported_name
);
10577 process_die (child_die
, cu
);
10580 add_using_directive (using_directives (cu
),
10584 imported_declaration
,
10587 &objfile
->objfile_obstack
);
10590 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10591 types, but gives them a size of zero. Starting with version 14,
10592 ICC is compatible with GCC. */
10595 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10597 if (!cu
->checked_producer
)
10598 check_producer (cu
);
10600 return cu
->producer_is_icc_lt_14
;
10603 /* ICC generates a DW_AT_type for C void functions. This was observed on
10604 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10605 which says that void functions should not have a DW_AT_type. */
10608 producer_is_icc (struct dwarf2_cu
*cu
)
10610 if (!cu
->checked_producer
)
10611 check_producer (cu
);
10613 return cu
->producer_is_icc
;
10616 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10617 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10618 this, it was first present in GCC release 4.3.0. */
10621 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10623 if (!cu
->checked_producer
)
10624 check_producer (cu
);
10626 return cu
->producer_is_gcc_lt_4_3
;
10629 static file_and_directory
10630 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10632 file_and_directory res
;
10634 /* Find the filename. Do not use dwarf2_name here, since the filename
10635 is not a source language identifier. */
10636 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10637 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10639 if (res
.comp_dir
== NULL
10640 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10641 && IS_ABSOLUTE_PATH (res
.name
))
10643 res
.comp_dir_storage
= ldirname (res
.name
);
10644 if (!res
.comp_dir_storage
.empty ())
10645 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10647 if (res
.comp_dir
!= NULL
)
10649 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10650 directory, get rid of it. */
10651 const char *cp
= strchr (res
.comp_dir
, ':');
10653 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10654 res
.comp_dir
= cp
+ 1;
10657 if (res
.name
== NULL
)
10658 res
.name
= "<unknown>";
10663 /* Handle DW_AT_stmt_list for a compilation unit.
10664 DIE is the DW_TAG_compile_unit die for CU.
10665 COMP_DIR is the compilation directory. LOWPC is passed to
10666 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10669 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10670 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10672 struct dwarf2_per_objfile
*dwarf2_per_objfile
10673 = cu
->per_cu
->dwarf2_per_objfile
;
10674 struct attribute
*attr
;
10675 struct line_header line_header_local
;
10676 hashval_t line_header_local_hash
;
10678 int decode_mapping
;
10680 gdb_assert (! cu
->per_cu
->is_debug_types
);
10682 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10686 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10688 /* The line header hash table is only created if needed (it exists to
10689 prevent redundant reading of the line table for partial_units).
10690 If we're given a partial_unit, we'll need it. If we're given a
10691 compile_unit, then use the line header hash table if it's already
10692 created, but don't create one just yet. */
10694 if (dwarf2_per_objfile
->line_header_hash
== NULL
10695 && die
->tag
== DW_TAG_partial_unit
)
10697 dwarf2_per_objfile
->line_header_hash
10698 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10699 line_header_eq_voidp
,
10700 free_line_header_voidp
,
10704 line_header_local
.sect_off
= line_offset
;
10705 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10706 line_header_local_hash
= line_header_hash (&line_header_local
);
10707 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10709 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10710 &line_header_local
,
10711 line_header_local_hash
, NO_INSERT
);
10713 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10714 is not present in *SLOT (since if there is something in *SLOT then
10715 it will be for a partial_unit). */
10716 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10718 gdb_assert (*slot
!= NULL
);
10719 cu
->line_header
= (struct line_header
*) *slot
;
10724 /* dwarf_decode_line_header does not yet provide sufficient information.
10725 We always have to call also dwarf_decode_lines for it. */
10726 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10730 cu
->line_header
= lh
.release ();
10731 cu
->line_header_die_owner
= die
;
10733 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10737 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10738 &line_header_local
,
10739 line_header_local_hash
, INSERT
);
10740 gdb_assert (slot
!= NULL
);
10742 if (slot
!= NULL
&& *slot
== NULL
)
10744 /* This newly decoded line number information unit will be owned
10745 by line_header_hash hash table. */
10746 *slot
= cu
->line_header
;
10747 cu
->line_header_die_owner
= NULL
;
10751 /* We cannot free any current entry in (*slot) as that struct line_header
10752 may be already used by multiple CUs. Create only temporary decoded
10753 line_header for this CU - it may happen at most once for each line
10754 number information unit. And if we're not using line_header_hash
10755 then this is what we want as well. */
10756 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10758 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10759 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10764 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10767 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10769 struct dwarf2_per_objfile
*dwarf2_per_objfile
10770 = cu
->per_cu
->dwarf2_per_objfile
;
10771 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10772 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10773 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10774 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10775 struct attribute
*attr
;
10776 struct die_info
*child_die
;
10777 CORE_ADDR baseaddr
;
10779 prepare_one_comp_unit (cu
, die
, cu
->language
);
10780 baseaddr
= objfile
->text_section_offset ();
10782 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10784 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10785 from finish_block. */
10786 if (lowpc
== ((CORE_ADDR
) -1))
10788 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10790 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10792 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10793 standardised yet. As a workaround for the language detection we fall
10794 back to the DW_AT_producer string. */
10795 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10796 cu
->language
= language_opencl
;
10798 /* Similar hack for Go. */
10799 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10800 set_cu_language (DW_LANG_Go
, cu
);
10802 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10804 /* Decode line number information if present. We do this before
10805 processing child DIEs, so that the line header table is available
10806 for DW_AT_decl_file. */
10807 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10809 /* Process all dies in compilation unit. */
10810 if (die
->child
!= NULL
)
10812 child_die
= die
->child
;
10813 while (child_die
&& child_die
->tag
)
10815 process_die (child_die
, cu
);
10816 child_die
= sibling_die (child_die
);
10820 /* Decode macro information, if present. Dwarf 2 macro information
10821 refers to information in the line number info statement program
10822 header, so we can only read it if we've read the header
10824 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10826 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10827 if (attr
&& cu
->line_header
)
10829 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10830 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10832 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10836 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10837 if (attr
&& cu
->line_header
)
10839 unsigned int macro_offset
= DW_UNSND (attr
);
10841 dwarf_decode_macros (cu
, macro_offset
, 0);
10847 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10849 struct type_unit_group
*tu_group
;
10851 struct attribute
*attr
;
10853 struct signatured_type
*sig_type
;
10855 gdb_assert (per_cu
->is_debug_types
);
10856 sig_type
= (struct signatured_type
*) per_cu
;
10858 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10860 /* If we're using .gdb_index (includes -readnow) then
10861 per_cu->type_unit_group may not have been set up yet. */
10862 if (sig_type
->type_unit_group
== NULL
)
10863 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10864 tu_group
= sig_type
->type_unit_group
;
10866 /* If we've already processed this stmt_list there's no real need to
10867 do it again, we could fake it and just recreate the part we need
10868 (file name,index -> symtab mapping). If data shows this optimization
10869 is useful we can do it then. */
10870 first_time
= tu_group
->compunit_symtab
== NULL
;
10872 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10877 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10878 lh
= dwarf_decode_line_header (line_offset
, this);
10883 start_symtab ("", NULL
, 0);
10886 gdb_assert (tu_group
->symtabs
== NULL
);
10887 gdb_assert (m_builder
== nullptr);
10888 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10889 m_builder
.reset (new struct buildsym_compunit
10890 (COMPUNIT_OBJFILE (cust
), "",
10891 COMPUNIT_DIRNAME (cust
),
10892 compunit_language (cust
),
10898 line_header
= lh
.release ();
10899 line_header_die_owner
= die
;
10903 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10905 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10906 still initializing it, and our caller (a few levels up)
10907 process_full_type_unit still needs to know if this is the first
10911 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10912 struct symtab
*, line_header
->file_names_size ());
10914 auto &file_names
= line_header
->file_names ();
10915 for (i
= 0; i
< file_names
.size (); ++i
)
10917 file_entry
&fe
= file_names
[i
];
10918 dwarf2_start_subfile (this, fe
.name
,
10919 fe
.include_dir (line_header
));
10920 buildsym_compunit
*b
= get_builder ();
10921 if (b
->get_current_subfile ()->symtab
== NULL
)
10923 /* NOTE: start_subfile will recognize when it's been
10924 passed a file it has already seen. So we can't
10925 assume there's a simple mapping from
10926 cu->line_header->file_names to subfiles, plus
10927 cu->line_header->file_names may contain dups. */
10928 b
->get_current_subfile ()->symtab
10929 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10932 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10933 tu_group
->symtabs
[i
] = fe
.symtab
;
10938 gdb_assert (m_builder
== nullptr);
10939 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10940 m_builder
.reset (new struct buildsym_compunit
10941 (COMPUNIT_OBJFILE (cust
), "",
10942 COMPUNIT_DIRNAME (cust
),
10943 compunit_language (cust
),
10946 auto &file_names
= line_header
->file_names ();
10947 for (i
= 0; i
< file_names
.size (); ++i
)
10949 file_entry
&fe
= file_names
[i
];
10950 fe
.symtab
= tu_group
->symtabs
[i
];
10954 /* The main symtab is allocated last. Type units don't have DW_AT_name
10955 so they don't have a "real" (so to speak) symtab anyway.
10956 There is later code that will assign the main symtab to all symbols
10957 that don't have one. We need to handle the case of a symbol with a
10958 missing symtab (DW_AT_decl_file) anyway. */
10961 /* Process DW_TAG_type_unit.
10962 For TUs we want to skip the first top level sibling if it's not the
10963 actual type being defined by this TU. In this case the first top
10964 level sibling is there to provide context only. */
10967 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10969 struct die_info
*child_die
;
10971 prepare_one_comp_unit (cu
, die
, language_minimal
);
10973 /* Initialize (or reinitialize) the machinery for building symtabs.
10974 We do this before processing child DIEs, so that the line header table
10975 is available for DW_AT_decl_file. */
10976 cu
->setup_type_unit_groups (die
);
10978 if (die
->child
!= NULL
)
10980 child_die
= die
->child
;
10981 while (child_die
&& child_die
->tag
)
10983 process_die (child_die
, cu
);
10984 child_die
= sibling_die (child_die
);
10991 http://gcc.gnu.org/wiki/DebugFission
10992 http://gcc.gnu.org/wiki/DebugFissionDWP
10994 To simplify handling of both DWO files ("object" files with the DWARF info)
10995 and DWP files (a file with the DWOs packaged up into one file), we treat
10996 DWP files as having a collection of virtual DWO files. */
10999 hash_dwo_file (const void *item
)
11001 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11004 hash
= htab_hash_string (dwo_file
->dwo_name
);
11005 if (dwo_file
->comp_dir
!= NULL
)
11006 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11011 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11013 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11014 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11016 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11018 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11019 return lhs
->comp_dir
== rhs
->comp_dir
;
11020 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11023 /* Allocate a hash table for DWO files. */
11026 allocate_dwo_file_hash_table ()
11028 auto delete_dwo_file
= [] (void *item
)
11030 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11035 return htab_up (htab_create_alloc (41,
11042 /* Lookup DWO file DWO_NAME. */
11045 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11046 const char *dwo_name
,
11047 const char *comp_dir
)
11049 struct dwo_file find_entry
;
11052 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11053 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11055 find_entry
.dwo_name
= dwo_name
;
11056 find_entry
.comp_dir
= comp_dir
;
11057 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11064 hash_dwo_unit (const void *item
)
11066 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11068 /* This drops the top 32 bits of the id, but is ok for a hash. */
11069 return dwo_unit
->signature
;
11073 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11075 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11076 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11078 /* The signature is assumed to be unique within the DWO file.
11079 So while object file CU dwo_id's always have the value zero,
11080 that's OK, assuming each object file DWO file has only one CU,
11081 and that's the rule for now. */
11082 return lhs
->signature
== rhs
->signature
;
11085 /* Allocate a hash table for DWO CUs,TUs.
11086 There is one of these tables for each of CUs,TUs for each DWO file. */
11089 allocate_dwo_unit_table ()
11091 /* Start out with a pretty small number.
11092 Generally DWO files contain only one CU and maybe some TUs. */
11093 return htab_up (htab_create_alloc (3,
11096 NULL
, xcalloc
, xfree
));
11099 /* die_reader_func for create_dwo_cu. */
11102 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11103 const gdb_byte
*info_ptr
,
11104 struct die_info
*comp_unit_die
,
11105 struct dwo_file
*dwo_file
,
11106 struct dwo_unit
*dwo_unit
)
11108 struct dwarf2_cu
*cu
= reader
->cu
;
11109 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11110 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11112 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11113 if (!signature
.has_value ())
11115 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11116 " its dwo_id [in module %s]"),
11117 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11121 dwo_unit
->dwo_file
= dwo_file
;
11122 dwo_unit
->signature
= *signature
;
11123 dwo_unit
->section
= section
;
11124 dwo_unit
->sect_off
= sect_off
;
11125 dwo_unit
->length
= cu
->per_cu
->length
;
11127 if (dwarf_read_debug
)
11128 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11129 sect_offset_str (sect_off
),
11130 hex_string (dwo_unit
->signature
));
11133 /* Create the dwo_units for the CUs in a DWO_FILE.
11134 Note: This function processes DWO files only, not DWP files. */
11137 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11138 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11139 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11141 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11142 const gdb_byte
*info_ptr
, *end_ptr
;
11144 section
.read (objfile
);
11145 info_ptr
= section
.buffer
;
11147 if (info_ptr
== NULL
)
11150 if (dwarf_read_debug
)
11152 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11153 section
.get_name (),
11154 section
.get_file_name ());
11157 end_ptr
= info_ptr
+ section
.size
;
11158 while (info_ptr
< end_ptr
)
11160 struct dwarf2_per_cu_data per_cu
;
11161 struct dwo_unit read_unit
{};
11162 struct dwo_unit
*dwo_unit
;
11164 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11166 memset (&per_cu
, 0, sizeof (per_cu
));
11167 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11168 per_cu
.is_debug_types
= 0;
11169 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11170 per_cu
.section
= §ion
;
11172 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11173 if (!reader
.dummy_p
)
11174 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11175 &dwo_file
, &read_unit
);
11176 info_ptr
+= per_cu
.length
;
11178 // If the unit could not be parsed, skip it.
11179 if (read_unit
.dwo_file
== NULL
)
11182 if (cus_htab
== NULL
)
11183 cus_htab
= allocate_dwo_unit_table ();
11185 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11186 *dwo_unit
= read_unit
;
11187 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11188 gdb_assert (slot
!= NULL
);
11191 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11192 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11194 complaint (_("debug cu entry at offset %s is duplicate to"
11195 " the entry at offset %s, signature %s"),
11196 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11197 hex_string (dwo_unit
->signature
));
11199 *slot
= (void *)dwo_unit
;
11203 /* DWP file .debug_{cu,tu}_index section format:
11204 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11208 Both index sections have the same format, and serve to map a 64-bit
11209 signature to a set of section numbers. Each section begins with a header,
11210 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11211 indexes, and a pool of 32-bit section numbers. The index sections will be
11212 aligned at 8-byte boundaries in the file.
11214 The index section header consists of:
11216 V, 32 bit version number
11218 N, 32 bit number of compilation units or type units in the index
11219 M, 32 bit number of slots in the hash table
11221 Numbers are recorded using the byte order of the application binary.
11223 The hash table begins at offset 16 in the section, and consists of an array
11224 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11225 order of the application binary). Unused slots in the hash table are 0.
11226 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11228 The parallel table begins immediately after the hash table
11229 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11230 array of 32-bit indexes (using the byte order of the application binary),
11231 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11232 table contains a 32-bit index into the pool of section numbers. For unused
11233 hash table slots, the corresponding entry in the parallel table will be 0.
11235 The pool of section numbers begins immediately following the hash table
11236 (at offset 16 + 12 * M from the beginning of the section). The pool of
11237 section numbers consists of an array of 32-bit words (using the byte order
11238 of the application binary). Each item in the array is indexed starting
11239 from 0. The hash table entry provides the index of the first section
11240 number in the set. Additional section numbers in the set follow, and the
11241 set is terminated by a 0 entry (section number 0 is not used in ELF).
11243 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11244 section must be the first entry in the set, and the .debug_abbrev.dwo must
11245 be the second entry. Other members of the set may follow in any order.
11251 DWP Version 2 combines all the .debug_info, etc. sections into one,
11252 and the entries in the index tables are now offsets into these sections.
11253 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11256 Index Section Contents:
11258 Hash Table of Signatures dwp_hash_table.hash_table
11259 Parallel Table of Indices dwp_hash_table.unit_table
11260 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11261 Table of Section Sizes dwp_hash_table.v2.sizes
11263 The index section header consists of:
11265 V, 32 bit version number
11266 L, 32 bit number of columns in the table of section offsets
11267 N, 32 bit number of compilation units or type units in the index
11268 M, 32 bit number of slots in the hash table
11270 Numbers are recorded using the byte order of the application binary.
11272 The hash table has the same format as version 1.
11273 The parallel table of indices has the same format as version 1,
11274 except that the entries are origin-1 indices into the table of sections
11275 offsets and the table of section sizes.
11277 The table of offsets begins immediately following the parallel table
11278 (at offset 16 + 12 * M from the beginning of the section). The table is
11279 a two-dimensional array of 32-bit words (using the byte order of the
11280 application binary), with L columns and N+1 rows, in row-major order.
11281 Each row in the array is indexed starting from 0. The first row provides
11282 a key to the remaining rows: each column in this row provides an identifier
11283 for a debug section, and the offsets in the same column of subsequent rows
11284 refer to that section. The section identifiers are:
11286 DW_SECT_INFO 1 .debug_info.dwo
11287 DW_SECT_TYPES 2 .debug_types.dwo
11288 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11289 DW_SECT_LINE 4 .debug_line.dwo
11290 DW_SECT_LOC 5 .debug_loc.dwo
11291 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11292 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11293 DW_SECT_MACRO 8 .debug_macro.dwo
11295 The offsets provided by the CU and TU index sections are the base offsets
11296 for the contributions made by each CU or TU to the corresponding section
11297 in the package file. Each CU and TU header contains an abbrev_offset
11298 field, used to find the abbreviations table for that CU or TU within the
11299 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11300 be interpreted as relative to the base offset given in the index section.
11301 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11302 should be interpreted as relative to the base offset for .debug_line.dwo,
11303 and offsets into other debug sections obtained from DWARF attributes should
11304 also be interpreted as relative to the corresponding base offset.
11306 The table of sizes begins immediately following the table of offsets.
11307 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11308 with L columns and N rows, in row-major order. Each row in the array is
11309 indexed starting from 1 (row 0 is shared by the two tables).
11313 Hash table lookup is handled the same in version 1 and 2:
11315 We assume that N and M will not exceed 2^32 - 1.
11316 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11318 Given a 64-bit compilation unit signature or a type signature S, an entry
11319 in the hash table is located as follows:
11321 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11322 the low-order k bits all set to 1.
11324 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11326 3) If the hash table entry at index H matches the signature, use that
11327 entry. If the hash table entry at index H is unused (all zeroes),
11328 terminate the search: the signature is not present in the table.
11330 4) Let H = (H + H') modulo M. Repeat at Step 3.
11332 Because M > N and H' and M are relatively prime, the search is guaranteed
11333 to stop at an unused slot or find the match. */
11335 /* Create a hash table to map DWO IDs to their CU/TU entry in
11336 .debug_{info,types}.dwo in DWP_FILE.
11337 Returns NULL if there isn't one.
11338 Note: This function processes DWP files only, not DWO files. */
11340 static struct dwp_hash_table
*
11341 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11342 struct dwp_file
*dwp_file
, int is_debug_types
)
11344 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11345 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11346 const gdb_byte
*index_ptr
, *index_end
;
11347 struct dwarf2_section_info
*index
;
11348 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11349 struct dwp_hash_table
*htab
;
11351 if (is_debug_types
)
11352 index
= &dwp_file
->sections
.tu_index
;
11354 index
= &dwp_file
->sections
.cu_index
;
11356 if (index
->empty ())
11358 index
->read (objfile
);
11360 index_ptr
= index
->buffer
;
11361 index_end
= index_ptr
+ index
->size
;
11363 version
= read_4_bytes (dbfd
, index_ptr
);
11366 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11370 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11372 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11375 if (version
!= 1 && version
!= 2)
11377 error (_("Dwarf Error: unsupported DWP file version (%s)"
11378 " [in module %s]"),
11379 pulongest (version
), dwp_file
->name
);
11381 if (nr_slots
!= (nr_slots
& -nr_slots
))
11383 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11384 " is not power of 2 [in module %s]"),
11385 pulongest (nr_slots
), dwp_file
->name
);
11388 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11389 htab
->version
= version
;
11390 htab
->nr_columns
= nr_columns
;
11391 htab
->nr_units
= nr_units
;
11392 htab
->nr_slots
= nr_slots
;
11393 htab
->hash_table
= index_ptr
;
11394 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11396 /* Exit early if the table is empty. */
11397 if (nr_slots
== 0 || nr_units
== 0
11398 || (version
== 2 && nr_columns
== 0))
11400 /* All must be zero. */
11401 if (nr_slots
!= 0 || nr_units
!= 0
11402 || (version
== 2 && nr_columns
!= 0))
11404 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11405 " all zero [in modules %s]"),
11413 htab
->section_pool
.v1
.indices
=
11414 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11415 /* It's harder to decide whether the section is too small in v1.
11416 V1 is deprecated anyway so we punt. */
11420 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11421 int *ids
= htab
->section_pool
.v2
.section_ids
;
11422 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11423 /* Reverse map for error checking. */
11424 int ids_seen
[DW_SECT_MAX
+ 1];
11427 if (nr_columns
< 2)
11429 error (_("Dwarf Error: bad DWP hash table, too few columns"
11430 " in section table [in module %s]"),
11433 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11435 error (_("Dwarf Error: bad DWP hash table, too many columns"
11436 " in section table [in module %s]"),
11439 memset (ids
, 255, sizeof_ids
);
11440 memset (ids_seen
, 255, sizeof (ids_seen
));
11441 for (i
= 0; i
< nr_columns
; ++i
)
11443 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11445 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11447 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11448 " in section table [in module %s]"),
11449 id
, dwp_file
->name
);
11451 if (ids_seen
[id
] != -1)
11453 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11454 " id %d in section table [in module %s]"),
11455 id
, dwp_file
->name
);
11460 /* Must have exactly one info or types section. */
11461 if (((ids_seen
[DW_SECT_INFO
] != -1)
11462 + (ids_seen
[DW_SECT_TYPES
] != -1))
11465 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11466 " DWO info/types section [in module %s]"),
11469 /* Must have an abbrev section. */
11470 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11472 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11473 " section [in module %s]"),
11476 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11477 htab
->section_pool
.v2
.sizes
=
11478 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11479 * nr_units
* nr_columns
);
11480 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11481 * nr_units
* nr_columns
))
11484 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11485 " [in module %s]"),
11493 /* Update SECTIONS with the data from SECTP.
11495 This function is like the other "locate" section routines that are
11496 passed to bfd_map_over_sections, but in this context the sections to
11497 read comes from the DWP V1 hash table, not the full ELF section table.
11499 The result is non-zero for success, or zero if an error was found. */
11502 locate_v1_virtual_dwo_sections (asection
*sectp
,
11503 struct virtual_v1_dwo_sections
*sections
)
11505 const struct dwop_section_names
*names
= &dwop_section_names
;
11507 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11509 /* There can be only one. */
11510 if (sections
->abbrev
.s
.section
!= NULL
)
11512 sections
->abbrev
.s
.section
= sectp
;
11513 sections
->abbrev
.size
= bfd_section_size (sectp
);
11515 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11516 || section_is_p (sectp
->name
, &names
->types_dwo
))
11518 /* There can be only one. */
11519 if (sections
->info_or_types
.s
.section
!= NULL
)
11521 sections
->info_or_types
.s
.section
= sectp
;
11522 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11524 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11526 /* There can be only one. */
11527 if (sections
->line
.s
.section
!= NULL
)
11529 sections
->line
.s
.section
= sectp
;
11530 sections
->line
.size
= bfd_section_size (sectp
);
11532 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11534 /* There can be only one. */
11535 if (sections
->loc
.s
.section
!= NULL
)
11537 sections
->loc
.s
.section
= sectp
;
11538 sections
->loc
.size
= bfd_section_size (sectp
);
11540 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11542 /* There can be only one. */
11543 if (sections
->macinfo
.s
.section
!= NULL
)
11545 sections
->macinfo
.s
.section
= sectp
;
11546 sections
->macinfo
.size
= bfd_section_size (sectp
);
11548 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11550 /* There can be only one. */
11551 if (sections
->macro
.s
.section
!= NULL
)
11553 sections
->macro
.s
.section
= sectp
;
11554 sections
->macro
.size
= bfd_section_size (sectp
);
11556 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11558 /* There can be only one. */
11559 if (sections
->str_offsets
.s
.section
!= NULL
)
11561 sections
->str_offsets
.s
.section
= sectp
;
11562 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11566 /* No other kind of section is valid. */
11573 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11574 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11575 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11576 This is for DWP version 1 files. */
11578 static struct dwo_unit
*
11579 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11580 struct dwp_file
*dwp_file
,
11581 uint32_t unit_index
,
11582 const char *comp_dir
,
11583 ULONGEST signature
, int is_debug_types
)
11585 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11586 const struct dwp_hash_table
*dwp_htab
=
11587 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11588 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11589 const char *kind
= is_debug_types
? "TU" : "CU";
11590 struct dwo_file
*dwo_file
;
11591 struct dwo_unit
*dwo_unit
;
11592 struct virtual_v1_dwo_sections sections
;
11593 void **dwo_file_slot
;
11596 gdb_assert (dwp_file
->version
== 1);
11598 if (dwarf_read_debug
)
11600 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11602 pulongest (unit_index
), hex_string (signature
),
11606 /* Fetch the sections of this DWO unit.
11607 Put a limit on the number of sections we look for so that bad data
11608 doesn't cause us to loop forever. */
11610 #define MAX_NR_V1_DWO_SECTIONS \
11611 (1 /* .debug_info or .debug_types */ \
11612 + 1 /* .debug_abbrev */ \
11613 + 1 /* .debug_line */ \
11614 + 1 /* .debug_loc */ \
11615 + 1 /* .debug_str_offsets */ \
11616 + 1 /* .debug_macro or .debug_macinfo */ \
11617 + 1 /* trailing zero */)
11619 memset (§ions
, 0, sizeof (sections
));
11621 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11624 uint32_t section_nr
=
11625 read_4_bytes (dbfd
,
11626 dwp_htab
->section_pool
.v1
.indices
11627 + (unit_index
+ i
) * sizeof (uint32_t));
11629 if (section_nr
== 0)
11631 if (section_nr
>= dwp_file
->num_sections
)
11633 error (_("Dwarf Error: bad DWP hash table, section number too large"
11634 " [in module %s]"),
11638 sectp
= dwp_file
->elf_sections
[section_nr
];
11639 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11641 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11642 " [in module %s]"),
11648 || sections
.info_or_types
.empty ()
11649 || sections
.abbrev
.empty ())
11651 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11652 " [in module %s]"),
11655 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11657 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11658 " [in module %s]"),
11662 /* It's easier for the rest of the code if we fake a struct dwo_file and
11663 have dwo_unit "live" in that. At least for now.
11665 The DWP file can be made up of a random collection of CUs and TUs.
11666 However, for each CU + set of TUs that came from the same original DWO
11667 file, we can combine them back into a virtual DWO file to save space
11668 (fewer struct dwo_file objects to allocate). Remember that for really
11669 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11671 std::string virtual_dwo_name
=
11672 string_printf ("virtual-dwo/%d-%d-%d-%d",
11673 sections
.abbrev
.get_id (),
11674 sections
.line
.get_id (),
11675 sections
.loc
.get_id (),
11676 sections
.str_offsets
.get_id ());
11677 /* Can we use an existing virtual DWO file? */
11678 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11679 virtual_dwo_name
.c_str (),
11681 /* Create one if necessary. */
11682 if (*dwo_file_slot
== NULL
)
11684 if (dwarf_read_debug
)
11686 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11687 virtual_dwo_name
.c_str ());
11689 dwo_file
= new struct dwo_file
;
11690 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11691 dwo_file
->comp_dir
= comp_dir
;
11692 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11693 dwo_file
->sections
.line
= sections
.line
;
11694 dwo_file
->sections
.loc
= sections
.loc
;
11695 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11696 dwo_file
->sections
.macro
= sections
.macro
;
11697 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11698 /* The "str" section is global to the entire DWP file. */
11699 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11700 /* The info or types section is assigned below to dwo_unit,
11701 there's no need to record it in dwo_file.
11702 Also, we can't simply record type sections in dwo_file because
11703 we record a pointer into the vector in dwo_unit. As we collect more
11704 types we'll grow the vector and eventually have to reallocate space
11705 for it, invalidating all copies of pointers into the previous
11707 *dwo_file_slot
= dwo_file
;
11711 if (dwarf_read_debug
)
11713 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11714 virtual_dwo_name
.c_str ());
11716 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11719 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11720 dwo_unit
->dwo_file
= dwo_file
;
11721 dwo_unit
->signature
= signature
;
11722 dwo_unit
->section
=
11723 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11724 *dwo_unit
->section
= sections
.info_or_types
;
11725 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11730 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11731 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11732 piece within that section used by a TU/CU, return a virtual section
11733 of just that piece. */
11735 static struct dwarf2_section_info
11736 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11737 struct dwarf2_section_info
*section
,
11738 bfd_size_type offset
, bfd_size_type size
)
11740 struct dwarf2_section_info result
;
11743 gdb_assert (section
!= NULL
);
11744 gdb_assert (!section
->is_virtual
);
11746 memset (&result
, 0, sizeof (result
));
11747 result
.s
.containing_section
= section
;
11748 result
.is_virtual
= true;
11753 sectp
= section
->get_bfd_section ();
11755 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11756 bounds of the real section. This is a pretty-rare event, so just
11757 flag an error (easier) instead of a warning and trying to cope. */
11759 || offset
+ size
> bfd_section_size (sectp
))
11761 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11762 " in section %s [in module %s]"),
11763 sectp
? bfd_section_name (sectp
) : "<unknown>",
11764 objfile_name (dwarf2_per_objfile
->objfile
));
11767 result
.virtual_offset
= offset
;
11768 result
.size
= size
;
11772 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11773 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11774 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11775 This is for DWP version 2 files. */
11777 static struct dwo_unit
*
11778 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11779 struct dwp_file
*dwp_file
,
11780 uint32_t unit_index
,
11781 const char *comp_dir
,
11782 ULONGEST signature
, int is_debug_types
)
11784 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11785 const struct dwp_hash_table
*dwp_htab
=
11786 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11787 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11788 const char *kind
= is_debug_types
? "TU" : "CU";
11789 struct dwo_file
*dwo_file
;
11790 struct dwo_unit
*dwo_unit
;
11791 struct virtual_v2_dwo_sections sections
;
11792 void **dwo_file_slot
;
11795 gdb_assert (dwp_file
->version
== 2);
11797 if (dwarf_read_debug
)
11799 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11801 pulongest (unit_index
), hex_string (signature
),
11805 /* Fetch the section offsets of this DWO unit. */
11807 memset (§ions
, 0, sizeof (sections
));
11809 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11811 uint32_t offset
= read_4_bytes (dbfd
,
11812 dwp_htab
->section_pool
.v2
.offsets
11813 + (((unit_index
- 1) * dwp_htab
->nr_columns
11815 * sizeof (uint32_t)));
11816 uint32_t size
= read_4_bytes (dbfd
,
11817 dwp_htab
->section_pool
.v2
.sizes
11818 + (((unit_index
- 1) * dwp_htab
->nr_columns
11820 * sizeof (uint32_t)));
11822 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11825 case DW_SECT_TYPES
:
11826 sections
.info_or_types_offset
= offset
;
11827 sections
.info_or_types_size
= size
;
11829 case DW_SECT_ABBREV
:
11830 sections
.abbrev_offset
= offset
;
11831 sections
.abbrev_size
= size
;
11834 sections
.line_offset
= offset
;
11835 sections
.line_size
= size
;
11838 sections
.loc_offset
= offset
;
11839 sections
.loc_size
= size
;
11841 case DW_SECT_STR_OFFSETS
:
11842 sections
.str_offsets_offset
= offset
;
11843 sections
.str_offsets_size
= size
;
11845 case DW_SECT_MACINFO
:
11846 sections
.macinfo_offset
= offset
;
11847 sections
.macinfo_size
= size
;
11849 case DW_SECT_MACRO
:
11850 sections
.macro_offset
= offset
;
11851 sections
.macro_size
= size
;
11856 /* It's easier for the rest of the code if we fake a struct dwo_file and
11857 have dwo_unit "live" in that. At least for now.
11859 The DWP file can be made up of a random collection of CUs and TUs.
11860 However, for each CU + set of TUs that came from the same original DWO
11861 file, we can combine them back into a virtual DWO file to save space
11862 (fewer struct dwo_file objects to allocate). Remember that for really
11863 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11865 std::string virtual_dwo_name
=
11866 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11867 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11868 (long) (sections
.line_size
? sections
.line_offset
: 0),
11869 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11870 (long) (sections
.str_offsets_size
11871 ? sections
.str_offsets_offset
: 0));
11872 /* Can we use an existing virtual DWO file? */
11873 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11874 virtual_dwo_name
.c_str (),
11876 /* Create one if necessary. */
11877 if (*dwo_file_slot
== NULL
)
11879 if (dwarf_read_debug
)
11881 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11882 virtual_dwo_name
.c_str ());
11884 dwo_file
= new struct dwo_file
;
11885 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11886 dwo_file
->comp_dir
= comp_dir
;
11887 dwo_file
->sections
.abbrev
=
11888 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11889 sections
.abbrev_offset
, sections
.abbrev_size
);
11890 dwo_file
->sections
.line
=
11891 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11892 sections
.line_offset
, sections
.line_size
);
11893 dwo_file
->sections
.loc
=
11894 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11895 sections
.loc_offset
, sections
.loc_size
);
11896 dwo_file
->sections
.macinfo
=
11897 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11898 sections
.macinfo_offset
, sections
.macinfo_size
);
11899 dwo_file
->sections
.macro
=
11900 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11901 sections
.macro_offset
, sections
.macro_size
);
11902 dwo_file
->sections
.str_offsets
=
11903 create_dwp_v2_section (dwarf2_per_objfile
,
11904 &dwp_file
->sections
.str_offsets
,
11905 sections
.str_offsets_offset
,
11906 sections
.str_offsets_size
);
11907 /* The "str" section is global to the entire DWP file. */
11908 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11909 /* The info or types section is assigned below to dwo_unit,
11910 there's no need to record it in dwo_file.
11911 Also, we can't simply record type sections in dwo_file because
11912 we record a pointer into the vector in dwo_unit. As we collect more
11913 types we'll grow the vector and eventually have to reallocate space
11914 for it, invalidating all copies of pointers into the previous
11916 *dwo_file_slot
= dwo_file
;
11920 if (dwarf_read_debug
)
11922 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11923 virtual_dwo_name
.c_str ());
11925 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11928 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11929 dwo_unit
->dwo_file
= dwo_file
;
11930 dwo_unit
->signature
= signature
;
11931 dwo_unit
->section
=
11932 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11933 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11935 ? &dwp_file
->sections
.types
11936 : &dwp_file
->sections
.info
,
11937 sections
.info_or_types_offset
,
11938 sections
.info_or_types_size
);
11939 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11944 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11945 Returns NULL if the signature isn't found. */
11947 static struct dwo_unit
*
11948 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11949 struct dwp_file
*dwp_file
, const char *comp_dir
,
11950 ULONGEST signature
, int is_debug_types
)
11952 const struct dwp_hash_table
*dwp_htab
=
11953 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11954 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11955 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11956 uint32_t hash
= signature
& mask
;
11957 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11960 struct dwo_unit find_dwo_cu
;
11962 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11963 find_dwo_cu
.signature
= signature
;
11964 slot
= htab_find_slot (is_debug_types
11965 ? dwp_file
->loaded_tus
.get ()
11966 : dwp_file
->loaded_cus
.get (),
11967 &find_dwo_cu
, INSERT
);
11970 return (struct dwo_unit
*) *slot
;
11972 /* Use a for loop so that we don't loop forever on bad debug info. */
11973 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11975 ULONGEST signature_in_table
;
11977 signature_in_table
=
11978 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11979 if (signature_in_table
== signature
)
11981 uint32_t unit_index
=
11982 read_4_bytes (dbfd
,
11983 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11985 if (dwp_file
->version
== 1)
11987 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11988 dwp_file
, unit_index
,
11989 comp_dir
, signature
,
11994 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11995 dwp_file
, unit_index
,
11996 comp_dir
, signature
,
11999 return (struct dwo_unit
*) *slot
;
12001 if (signature_in_table
== 0)
12003 hash
= (hash
+ hash2
) & mask
;
12006 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12007 " [in module %s]"),
12011 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12012 Open the file specified by FILE_NAME and hand it off to BFD for
12013 preliminary analysis. Return a newly initialized bfd *, which
12014 includes a canonicalized copy of FILE_NAME.
12015 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12016 SEARCH_CWD is true if the current directory is to be searched.
12017 It will be searched before debug-file-directory.
12018 If successful, the file is added to the bfd include table of the
12019 objfile's bfd (see gdb_bfd_record_inclusion).
12020 If unable to find/open the file, return NULL.
12021 NOTE: This function is derived from symfile_bfd_open. */
12023 static gdb_bfd_ref_ptr
12024 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12025 const char *file_name
, int is_dwp
, int search_cwd
)
12028 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12029 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12030 to debug_file_directory. */
12031 const char *search_path
;
12032 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12034 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12037 if (*debug_file_directory
!= '\0')
12039 search_path_holder
.reset (concat (".", dirname_separator_string
,
12040 debug_file_directory
,
12042 search_path
= search_path_holder
.get ();
12048 search_path
= debug_file_directory
;
12050 openp_flags flags
= OPF_RETURN_REALPATH
;
12052 flags
|= OPF_SEARCH_IN_PATH
;
12054 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12055 desc
= openp (search_path
, flags
, file_name
,
12056 O_RDONLY
| O_BINARY
, &absolute_name
);
12060 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12062 if (sym_bfd
== NULL
)
12064 bfd_set_cacheable (sym_bfd
.get (), 1);
12066 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12069 /* Success. Record the bfd as having been included by the objfile's bfd.
12070 This is important because things like demangled_names_hash lives in the
12071 objfile's per_bfd space and may have references to things like symbol
12072 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12073 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12078 /* Try to open DWO file FILE_NAME.
12079 COMP_DIR is the DW_AT_comp_dir attribute.
12080 The result is the bfd handle of the file.
12081 If there is a problem finding or opening the file, return NULL.
12082 Upon success, the canonicalized path of the file is stored in the bfd,
12083 same as symfile_bfd_open. */
12085 static gdb_bfd_ref_ptr
12086 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12087 const char *file_name
, const char *comp_dir
)
12089 if (IS_ABSOLUTE_PATH (file_name
))
12090 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12091 0 /*is_dwp*/, 0 /*search_cwd*/);
12093 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12095 if (comp_dir
!= NULL
)
12097 gdb::unique_xmalloc_ptr
<char> path_to_try
12098 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12100 /* NOTE: If comp_dir is a relative path, this will also try the
12101 search path, which seems useful. */
12102 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12103 path_to_try
.get (),
12105 1 /*search_cwd*/));
12110 /* That didn't work, try debug-file-directory, which, despite its name,
12111 is a list of paths. */
12113 if (*debug_file_directory
== '\0')
12116 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12117 0 /*is_dwp*/, 1 /*search_cwd*/);
12120 /* This function is mapped across the sections and remembers the offset and
12121 size of each of the DWO debugging sections we are interested in. */
12124 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12126 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12127 const struct dwop_section_names
*names
= &dwop_section_names
;
12129 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12131 dwo_sections
->abbrev
.s
.section
= sectp
;
12132 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12134 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12136 dwo_sections
->info
.s
.section
= sectp
;
12137 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12139 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12141 dwo_sections
->line
.s
.section
= sectp
;
12142 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12144 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12146 dwo_sections
->loc
.s
.section
= sectp
;
12147 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12149 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12151 dwo_sections
->macinfo
.s
.section
= sectp
;
12152 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12154 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12156 dwo_sections
->macro
.s
.section
= sectp
;
12157 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12159 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12161 dwo_sections
->str
.s
.section
= sectp
;
12162 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12164 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12166 dwo_sections
->str_offsets
.s
.section
= sectp
;
12167 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12169 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12171 struct dwarf2_section_info type_section
;
12173 memset (&type_section
, 0, sizeof (type_section
));
12174 type_section
.s
.section
= sectp
;
12175 type_section
.size
= bfd_section_size (sectp
);
12176 dwo_sections
->types
.push_back (type_section
);
12180 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12181 by PER_CU. This is for the non-DWP case.
12182 The result is NULL if DWO_NAME can't be found. */
12184 static struct dwo_file
*
12185 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12186 const char *dwo_name
, const char *comp_dir
)
12188 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12190 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12193 if (dwarf_read_debug
)
12194 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12198 dwo_file_up
dwo_file (new struct dwo_file
);
12199 dwo_file
->dwo_name
= dwo_name
;
12200 dwo_file
->comp_dir
= comp_dir
;
12201 dwo_file
->dbfd
= std::move (dbfd
);
12203 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12204 &dwo_file
->sections
);
12206 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12207 dwo_file
->sections
.info
, dwo_file
->cus
);
12209 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12210 dwo_file
->sections
.types
, dwo_file
->tus
);
12212 if (dwarf_read_debug
)
12213 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12215 return dwo_file
.release ();
12218 /* This function is mapped across the sections and remembers the offset and
12219 size of each of the DWP debugging sections common to version 1 and 2 that
12220 we are interested in. */
12223 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12224 void *dwp_file_ptr
)
12226 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12227 const struct dwop_section_names
*names
= &dwop_section_names
;
12228 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12230 /* Record the ELF section number for later lookup: this is what the
12231 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12232 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12233 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12235 /* Look for specific sections that we need. */
12236 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12238 dwp_file
->sections
.str
.s
.section
= sectp
;
12239 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12241 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12243 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12244 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12246 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12248 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12249 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12253 /* This function is mapped across the sections and remembers the offset and
12254 size of each of the DWP version 2 debugging sections that we are interested
12255 in. This is split into a separate function because we don't know if we
12256 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12259 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12261 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12262 const struct dwop_section_names
*names
= &dwop_section_names
;
12263 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12265 /* Record the ELF section number for later lookup: this is what the
12266 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12267 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12268 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12270 /* Look for specific sections that we need. */
12271 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12273 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12274 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12276 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12278 dwp_file
->sections
.info
.s
.section
= sectp
;
12279 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12281 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12283 dwp_file
->sections
.line
.s
.section
= sectp
;
12284 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12286 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12288 dwp_file
->sections
.loc
.s
.section
= sectp
;
12289 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12291 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12293 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12294 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12296 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12298 dwp_file
->sections
.macro
.s
.section
= sectp
;
12299 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12301 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12303 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12304 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12306 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12308 dwp_file
->sections
.types
.s
.section
= sectp
;
12309 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12313 /* Hash function for dwp_file loaded CUs/TUs. */
12316 hash_dwp_loaded_cutus (const void *item
)
12318 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12320 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12321 return dwo_unit
->signature
;
12324 /* Equality function for dwp_file loaded CUs/TUs. */
12327 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12329 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12330 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12332 return dua
->signature
== dub
->signature
;
12335 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12338 allocate_dwp_loaded_cutus_table ()
12340 return htab_up (htab_create_alloc (3,
12341 hash_dwp_loaded_cutus
,
12342 eq_dwp_loaded_cutus
,
12343 NULL
, xcalloc
, xfree
));
12346 /* Try to open DWP file FILE_NAME.
12347 The result is the bfd handle of the file.
12348 If there is a problem finding or opening the file, return NULL.
12349 Upon success, the canonicalized path of the file is stored in the bfd,
12350 same as symfile_bfd_open. */
12352 static gdb_bfd_ref_ptr
12353 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12354 const char *file_name
)
12356 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12358 1 /*search_cwd*/));
12362 /* Work around upstream bug 15652.
12363 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12364 [Whether that's a "bug" is debatable, but it is getting in our way.]
12365 We have no real idea where the dwp file is, because gdb's realpath-ing
12366 of the executable's path may have discarded the needed info.
12367 [IWBN if the dwp file name was recorded in the executable, akin to
12368 .gnu_debuglink, but that doesn't exist yet.]
12369 Strip the directory from FILE_NAME and search again. */
12370 if (*debug_file_directory
!= '\0')
12372 /* Don't implicitly search the current directory here.
12373 If the user wants to search "." to handle this case,
12374 it must be added to debug-file-directory. */
12375 return try_open_dwop_file (dwarf2_per_objfile
,
12376 lbasename (file_name
), 1 /*is_dwp*/,
12383 /* Initialize the use of the DWP file for the current objfile.
12384 By convention the name of the DWP file is ${objfile}.dwp.
12385 The result is NULL if it can't be found. */
12387 static std::unique_ptr
<struct dwp_file
>
12388 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12390 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12392 /* Try to find first .dwp for the binary file before any symbolic links
12395 /* If the objfile is a debug file, find the name of the real binary
12396 file and get the name of dwp file from there. */
12397 std::string dwp_name
;
12398 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12400 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12401 const char *backlink_basename
= lbasename (backlink
->original_name
);
12403 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12406 dwp_name
= objfile
->original_name
;
12408 dwp_name
+= ".dwp";
12410 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12412 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12414 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12415 dwp_name
= objfile_name (objfile
);
12416 dwp_name
+= ".dwp";
12417 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12422 if (dwarf_read_debug
)
12423 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12424 return std::unique_ptr
<dwp_file
> ();
12427 const char *name
= bfd_get_filename (dbfd
.get ());
12428 std::unique_ptr
<struct dwp_file
> dwp_file
12429 (new struct dwp_file (name
, std::move (dbfd
)));
12431 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12432 dwp_file
->elf_sections
=
12433 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12434 dwp_file
->num_sections
, asection
*);
12436 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12437 dwarf2_locate_common_dwp_sections
,
12440 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12443 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12446 /* The DWP file version is stored in the hash table. Oh well. */
12447 if (dwp_file
->cus
&& dwp_file
->tus
12448 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12450 /* Technically speaking, we should try to limp along, but this is
12451 pretty bizarre. We use pulongest here because that's the established
12452 portability solution (e.g, we cannot use %u for uint32_t). */
12453 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12454 " TU version %s [in DWP file %s]"),
12455 pulongest (dwp_file
->cus
->version
),
12456 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12460 dwp_file
->version
= dwp_file
->cus
->version
;
12461 else if (dwp_file
->tus
)
12462 dwp_file
->version
= dwp_file
->tus
->version
;
12464 dwp_file
->version
= 2;
12466 if (dwp_file
->version
== 2)
12467 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12468 dwarf2_locate_v2_dwp_sections
,
12471 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12472 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12474 if (dwarf_read_debug
)
12476 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12477 fprintf_unfiltered (gdb_stdlog
,
12478 " %s CUs, %s TUs\n",
12479 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12480 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12486 /* Wrapper around open_and_init_dwp_file, only open it once. */
12488 static struct dwp_file
*
12489 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12491 if (! dwarf2_per_objfile
->dwp_checked
)
12493 dwarf2_per_objfile
->dwp_file
12494 = open_and_init_dwp_file (dwarf2_per_objfile
);
12495 dwarf2_per_objfile
->dwp_checked
= 1;
12497 return dwarf2_per_objfile
->dwp_file
.get ();
12500 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12501 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12502 or in the DWP file for the objfile, referenced by THIS_UNIT.
12503 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12504 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12506 This is called, for example, when wanting to read a variable with a
12507 complex location. Therefore we don't want to do file i/o for every call.
12508 Therefore we don't want to look for a DWO file on every call.
12509 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12510 then we check if we've already seen DWO_NAME, and only THEN do we check
12513 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12514 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12516 static struct dwo_unit
*
12517 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12518 const char *dwo_name
, const char *comp_dir
,
12519 ULONGEST signature
, int is_debug_types
)
12521 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12522 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12523 const char *kind
= is_debug_types
? "TU" : "CU";
12524 void **dwo_file_slot
;
12525 struct dwo_file
*dwo_file
;
12526 struct dwp_file
*dwp_file
;
12528 /* First see if there's a DWP file.
12529 If we have a DWP file but didn't find the DWO inside it, don't
12530 look for the original DWO file. It makes gdb behave differently
12531 depending on whether one is debugging in the build tree. */
12533 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12534 if (dwp_file
!= NULL
)
12536 const struct dwp_hash_table
*dwp_htab
=
12537 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12539 if (dwp_htab
!= NULL
)
12541 struct dwo_unit
*dwo_cutu
=
12542 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12543 signature
, is_debug_types
);
12545 if (dwo_cutu
!= NULL
)
12547 if (dwarf_read_debug
)
12549 fprintf_unfiltered (gdb_stdlog
,
12550 "Virtual DWO %s %s found: @%s\n",
12551 kind
, hex_string (signature
),
12552 host_address_to_string (dwo_cutu
));
12560 /* No DWP file, look for the DWO file. */
12562 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12563 dwo_name
, comp_dir
);
12564 if (*dwo_file_slot
== NULL
)
12566 /* Read in the file and build a table of the CUs/TUs it contains. */
12567 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12569 /* NOTE: This will be NULL if unable to open the file. */
12570 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12572 if (dwo_file
!= NULL
)
12574 struct dwo_unit
*dwo_cutu
= NULL
;
12576 if (is_debug_types
&& dwo_file
->tus
)
12578 struct dwo_unit find_dwo_cutu
;
12580 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12581 find_dwo_cutu
.signature
= signature
;
12583 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12586 else if (!is_debug_types
&& dwo_file
->cus
)
12588 struct dwo_unit find_dwo_cutu
;
12590 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12591 find_dwo_cutu
.signature
= signature
;
12592 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12596 if (dwo_cutu
!= NULL
)
12598 if (dwarf_read_debug
)
12600 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12601 kind
, dwo_name
, hex_string (signature
),
12602 host_address_to_string (dwo_cutu
));
12609 /* We didn't find it. This could mean a dwo_id mismatch, or
12610 someone deleted the DWO/DWP file, or the search path isn't set up
12611 correctly to find the file. */
12613 if (dwarf_read_debug
)
12615 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12616 kind
, dwo_name
, hex_string (signature
));
12619 /* This is a warning and not a complaint because it can be caused by
12620 pilot error (e.g., user accidentally deleting the DWO). */
12622 /* Print the name of the DWP file if we looked there, helps the user
12623 better diagnose the problem. */
12624 std::string dwp_text
;
12626 if (dwp_file
!= NULL
)
12627 dwp_text
= string_printf (" [in DWP file %s]",
12628 lbasename (dwp_file
->name
));
12630 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12631 " [in module %s]"),
12632 kind
, dwo_name
, hex_string (signature
),
12634 this_unit
->is_debug_types
? "TU" : "CU",
12635 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12640 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12641 See lookup_dwo_cutu_unit for details. */
12643 static struct dwo_unit
*
12644 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12645 const char *dwo_name
, const char *comp_dir
,
12646 ULONGEST signature
)
12648 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12651 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12652 See lookup_dwo_cutu_unit for details. */
12654 static struct dwo_unit
*
12655 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12656 const char *dwo_name
, const char *comp_dir
)
12658 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12661 /* Traversal function for queue_and_load_all_dwo_tus. */
12664 queue_and_load_dwo_tu (void **slot
, void *info
)
12666 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12667 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12668 ULONGEST signature
= dwo_unit
->signature
;
12669 struct signatured_type
*sig_type
=
12670 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12672 if (sig_type
!= NULL
)
12674 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12676 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12677 a real dependency of PER_CU on SIG_TYPE. That is detected later
12678 while processing PER_CU. */
12679 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12680 load_full_type_unit (sig_cu
);
12681 per_cu
->imported_symtabs_push (sig_cu
);
12687 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12688 The DWO may have the only definition of the type, though it may not be
12689 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12690 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12693 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12695 struct dwo_unit
*dwo_unit
;
12696 struct dwo_file
*dwo_file
;
12698 gdb_assert (!per_cu
->is_debug_types
);
12699 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12700 gdb_assert (per_cu
->cu
!= NULL
);
12702 dwo_unit
= per_cu
->cu
->dwo_unit
;
12703 gdb_assert (dwo_unit
!= NULL
);
12705 dwo_file
= dwo_unit
->dwo_file
;
12706 if (dwo_file
->tus
!= NULL
)
12707 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12711 /* Read in various DIEs. */
12713 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12714 Inherit only the children of the DW_AT_abstract_origin DIE not being
12715 already referenced by DW_AT_abstract_origin from the children of the
12719 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12721 struct die_info
*child_die
;
12722 sect_offset
*offsetp
;
12723 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12724 struct die_info
*origin_die
;
12725 /* Iterator of the ORIGIN_DIE children. */
12726 struct die_info
*origin_child_die
;
12727 struct attribute
*attr
;
12728 struct dwarf2_cu
*origin_cu
;
12729 struct pending
**origin_previous_list_in_scope
;
12731 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12735 /* Note that following die references may follow to a die in a
12739 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12741 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12743 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12744 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12746 if (die
->tag
!= origin_die
->tag
12747 && !(die
->tag
== DW_TAG_inlined_subroutine
12748 && origin_die
->tag
== DW_TAG_subprogram
))
12749 complaint (_("DIE %s and its abstract origin %s have different tags"),
12750 sect_offset_str (die
->sect_off
),
12751 sect_offset_str (origin_die
->sect_off
));
12753 std::vector
<sect_offset
> offsets
;
12755 for (child_die
= die
->child
;
12756 child_die
&& child_die
->tag
;
12757 child_die
= sibling_die (child_die
))
12759 struct die_info
*child_origin_die
;
12760 struct dwarf2_cu
*child_origin_cu
;
12762 /* We are trying to process concrete instance entries:
12763 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12764 it's not relevant to our analysis here. i.e. detecting DIEs that are
12765 present in the abstract instance but not referenced in the concrete
12767 if (child_die
->tag
== DW_TAG_call_site
12768 || child_die
->tag
== DW_TAG_GNU_call_site
)
12771 /* For each CHILD_DIE, find the corresponding child of
12772 ORIGIN_DIE. If there is more than one layer of
12773 DW_AT_abstract_origin, follow them all; there shouldn't be,
12774 but GCC versions at least through 4.4 generate this (GCC PR
12776 child_origin_die
= child_die
;
12777 child_origin_cu
= cu
;
12780 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12784 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12788 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12789 counterpart may exist. */
12790 if (child_origin_die
!= child_die
)
12792 if (child_die
->tag
!= child_origin_die
->tag
12793 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12794 && child_origin_die
->tag
== DW_TAG_subprogram
))
12795 complaint (_("Child DIE %s and its abstract origin %s have "
12797 sect_offset_str (child_die
->sect_off
),
12798 sect_offset_str (child_origin_die
->sect_off
));
12799 if (child_origin_die
->parent
!= origin_die
)
12800 complaint (_("Child DIE %s and its abstract origin %s have "
12801 "different parents"),
12802 sect_offset_str (child_die
->sect_off
),
12803 sect_offset_str (child_origin_die
->sect_off
));
12805 offsets
.push_back (child_origin_die
->sect_off
);
12808 std::sort (offsets
.begin (), offsets
.end ());
12809 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12810 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12811 if (offsetp
[-1] == *offsetp
)
12812 complaint (_("Multiple children of DIE %s refer "
12813 "to DIE %s as their abstract origin"),
12814 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12816 offsetp
= offsets
.data ();
12817 origin_child_die
= origin_die
->child
;
12818 while (origin_child_die
&& origin_child_die
->tag
)
12820 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12821 while (offsetp
< offsets_end
12822 && *offsetp
< origin_child_die
->sect_off
)
12824 if (offsetp
>= offsets_end
12825 || *offsetp
> origin_child_die
->sect_off
)
12827 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12828 Check whether we're already processing ORIGIN_CHILD_DIE.
12829 This can happen with mutually referenced abstract_origins.
12831 if (!origin_child_die
->in_process
)
12832 process_die (origin_child_die
, origin_cu
);
12834 origin_child_die
= sibling_die (origin_child_die
);
12836 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12838 if (cu
!= origin_cu
)
12839 compute_delayed_physnames (origin_cu
);
12843 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12845 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12846 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12847 struct context_stack
*newobj
;
12850 struct die_info
*child_die
;
12851 struct attribute
*attr
, *call_line
, *call_file
;
12853 CORE_ADDR baseaddr
;
12854 struct block
*block
;
12855 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12856 std::vector
<struct symbol
*> template_args
;
12857 struct template_symbol
*templ_func
= NULL
;
12861 /* If we do not have call site information, we can't show the
12862 caller of this inlined function. That's too confusing, so
12863 only use the scope for local variables. */
12864 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12865 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12866 if (call_line
== NULL
|| call_file
== NULL
)
12868 read_lexical_block_scope (die
, cu
);
12873 baseaddr
= objfile
->text_section_offset ();
12875 name
= dwarf2_name (die
, cu
);
12877 /* Ignore functions with missing or empty names. These are actually
12878 illegal according to the DWARF standard. */
12881 complaint (_("missing name for subprogram DIE at %s"),
12882 sect_offset_str (die
->sect_off
));
12886 /* Ignore functions with missing or invalid low and high pc attributes. */
12887 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12888 <= PC_BOUNDS_INVALID
)
12890 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12891 if (!attr
|| !DW_UNSND (attr
))
12892 complaint (_("cannot get low and high bounds "
12893 "for subprogram DIE at %s"),
12894 sect_offset_str (die
->sect_off
));
12898 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12899 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12901 /* If we have any template arguments, then we must allocate a
12902 different sort of symbol. */
12903 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12905 if (child_die
->tag
== DW_TAG_template_type_param
12906 || child_die
->tag
== DW_TAG_template_value_param
)
12908 templ_func
= allocate_template_symbol (objfile
);
12909 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12914 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12915 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12916 (struct symbol
*) templ_func
);
12918 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12919 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12922 /* If there is a location expression for DW_AT_frame_base, record
12924 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12925 if (attr
!= nullptr)
12926 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12928 /* If there is a location for the static link, record it. */
12929 newobj
->static_link
= NULL
;
12930 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12931 if (attr
!= nullptr)
12933 newobj
->static_link
12934 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12935 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12936 cu
->per_cu
->addr_type ());
12939 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12941 if (die
->child
!= NULL
)
12943 child_die
= die
->child
;
12944 while (child_die
&& child_die
->tag
)
12946 if (child_die
->tag
== DW_TAG_template_type_param
12947 || child_die
->tag
== DW_TAG_template_value_param
)
12949 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12952 template_args
.push_back (arg
);
12955 process_die (child_die
, cu
);
12956 child_die
= sibling_die (child_die
);
12960 inherit_abstract_dies (die
, cu
);
12962 /* If we have a DW_AT_specification, we might need to import using
12963 directives from the context of the specification DIE. See the
12964 comment in determine_prefix. */
12965 if (cu
->language
== language_cplus
12966 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12968 struct dwarf2_cu
*spec_cu
= cu
;
12969 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12973 child_die
= spec_die
->child
;
12974 while (child_die
&& child_die
->tag
)
12976 if (child_die
->tag
== DW_TAG_imported_module
)
12977 process_die (child_die
, spec_cu
);
12978 child_die
= sibling_die (child_die
);
12981 /* In some cases, GCC generates specification DIEs that
12982 themselves contain DW_AT_specification attributes. */
12983 spec_die
= die_specification (spec_die
, &spec_cu
);
12987 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12988 /* Make a block for the local symbols within. */
12989 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12990 cstk
.static_link
, lowpc
, highpc
);
12992 /* For C++, set the block's scope. */
12993 if ((cu
->language
== language_cplus
12994 || cu
->language
== language_fortran
12995 || cu
->language
== language_d
12996 || cu
->language
== language_rust
)
12997 && cu
->processing_has_namespace_info
)
12998 block_set_scope (block
, determine_prefix (die
, cu
),
12999 &objfile
->objfile_obstack
);
13001 /* If we have address ranges, record them. */
13002 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13004 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13006 /* Attach template arguments to function. */
13007 if (!template_args
.empty ())
13009 gdb_assert (templ_func
!= NULL
);
13011 templ_func
->n_template_arguments
= template_args
.size ();
13012 templ_func
->template_arguments
13013 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13014 templ_func
->n_template_arguments
);
13015 memcpy (templ_func
->template_arguments
,
13016 template_args
.data (),
13017 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13019 /* Make sure that the symtab is set on the new symbols. Even
13020 though they don't appear in this symtab directly, other parts
13021 of gdb assume that symbols do, and this is reasonably
13023 for (symbol
*sym
: template_args
)
13024 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13027 /* In C++, we can have functions nested inside functions (e.g., when
13028 a function declares a class that has methods). This means that
13029 when we finish processing a function scope, we may need to go
13030 back to building a containing block's symbol lists. */
13031 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13032 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13034 /* If we've finished processing a top-level function, subsequent
13035 symbols go in the file symbol list. */
13036 if (cu
->get_builder ()->outermost_context_p ())
13037 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13040 /* Process all the DIES contained within a lexical block scope. Start
13041 a new scope, process the dies, and then close the scope. */
13044 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13046 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13047 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13048 CORE_ADDR lowpc
, highpc
;
13049 struct die_info
*child_die
;
13050 CORE_ADDR baseaddr
;
13052 baseaddr
= objfile
->text_section_offset ();
13054 /* Ignore blocks with missing or invalid low and high pc attributes. */
13055 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13056 as multiple lexical blocks? Handling children in a sane way would
13057 be nasty. Might be easier to properly extend generic blocks to
13058 describe ranges. */
13059 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13061 case PC_BOUNDS_NOT_PRESENT
:
13062 /* DW_TAG_lexical_block has no attributes, process its children as if
13063 there was no wrapping by that DW_TAG_lexical_block.
13064 GCC does no longer produces such DWARF since GCC r224161. */
13065 for (child_die
= die
->child
;
13066 child_die
!= NULL
&& child_die
->tag
;
13067 child_die
= sibling_die (child_die
))
13068 process_die (child_die
, cu
);
13070 case PC_BOUNDS_INVALID
:
13073 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13074 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13076 cu
->get_builder ()->push_context (0, lowpc
);
13077 if (die
->child
!= NULL
)
13079 child_die
= die
->child
;
13080 while (child_die
&& child_die
->tag
)
13082 process_die (child_die
, cu
);
13083 child_die
= sibling_die (child_die
);
13086 inherit_abstract_dies (die
, cu
);
13087 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13089 if (*cu
->get_builder ()->get_local_symbols () != NULL
13090 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13092 struct block
*block
13093 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13094 cstk
.start_addr
, highpc
);
13096 /* Note that recording ranges after traversing children, as we
13097 do here, means that recording a parent's ranges entails
13098 walking across all its children's ranges as they appear in
13099 the address map, which is quadratic behavior.
13101 It would be nicer to record the parent's ranges before
13102 traversing its children, simply overriding whatever you find
13103 there. But since we don't even decide whether to create a
13104 block until after we've traversed its children, that's hard
13106 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13108 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13109 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13112 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13115 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13117 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13118 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13119 CORE_ADDR pc
, baseaddr
;
13120 struct attribute
*attr
;
13121 struct call_site
*call_site
, call_site_local
;
13124 struct die_info
*child_die
;
13126 baseaddr
= objfile
->text_section_offset ();
13128 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13131 /* This was a pre-DWARF-5 GNU extension alias
13132 for DW_AT_call_return_pc. */
13133 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13137 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13138 "DIE %s [in module %s]"),
13139 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13142 pc
= attr
->value_as_address () + baseaddr
;
13143 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13145 if (cu
->call_site_htab
== NULL
)
13146 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13147 NULL
, &objfile
->objfile_obstack
,
13148 hashtab_obstack_allocate
, NULL
);
13149 call_site_local
.pc
= pc
;
13150 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13153 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13154 "DIE %s [in module %s]"),
13155 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13156 objfile_name (objfile
));
13160 /* Count parameters at the caller. */
13163 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13164 child_die
= sibling_die (child_die
))
13166 if (child_die
->tag
!= DW_TAG_call_site_parameter
13167 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13169 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13170 "DW_TAG_call_site child DIE %s [in module %s]"),
13171 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13172 objfile_name (objfile
));
13180 = ((struct call_site
*)
13181 obstack_alloc (&objfile
->objfile_obstack
,
13182 sizeof (*call_site
)
13183 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13185 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13186 call_site
->pc
= pc
;
13188 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13189 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13191 struct die_info
*func_die
;
13193 /* Skip also over DW_TAG_inlined_subroutine. */
13194 for (func_die
= die
->parent
;
13195 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13196 && func_die
->tag
!= DW_TAG_subroutine_type
;
13197 func_die
= func_die
->parent
);
13199 /* DW_AT_call_all_calls is a superset
13200 of DW_AT_call_all_tail_calls. */
13202 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13203 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13204 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13205 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13207 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13208 not complete. But keep CALL_SITE for look ups via call_site_htab,
13209 both the initial caller containing the real return address PC and
13210 the final callee containing the current PC of a chain of tail
13211 calls do not need to have the tail call list complete. But any
13212 function candidate for a virtual tail call frame searched via
13213 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13214 determined unambiguously. */
13218 struct type
*func_type
= NULL
;
13221 func_type
= get_die_type (func_die
, cu
);
13222 if (func_type
!= NULL
)
13224 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13226 /* Enlist this call site to the function. */
13227 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13228 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13231 complaint (_("Cannot find function owning DW_TAG_call_site "
13232 "DIE %s [in module %s]"),
13233 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13237 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13239 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13241 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13244 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13245 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13247 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13248 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13249 /* Keep NULL DWARF_BLOCK. */;
13250 else if (attr
->form_is_block ())
13252 struct dwarf2_locexpr_baton
*dlbaton
;
13254 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13255 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13256 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13257 dlbaton
->per_cu
= cu
->per_cu
;
13259 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13261 else if (attr
->form_is_ref ())
13263 struct dwarf2_cu
*target_cu
= cu
;
13264 struct die_info
*target_die
;
13266 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13267 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13268 if (die_is_declaration (target_die
, target_cu
))
13270 const char *target_physname
;
13272 /* Prefer the mangled name; otherwise compute the demangled one. */
13273 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13274 if (target_physname
== NULL
)
13275 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13276 if (target_physname
== NULL
)
13277 complaint (_("DW_AT_call_target target DIE has invalid "
13278 "physname, for referencing DIE %s [in module %s]"),
13279 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13281 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13287 /* DW_AT_entry_pc should be preferred. */
13288 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13289 <= PC_BOUNDS_INVALID
)
13290 complaint (_("DW_AT_call_target target DIE has invalid "
13291 "low pc, for referencing DIE %s [in module %s]"),
13292 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13295 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13296 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13301 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13302 "block nor reference, for DIE %s [in module %s]"),
13303 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13305 call_site
->per_cu
= cu
->per_cu
;
13307 for (child_die
= die
->child
;
13308 child_die
&& child_die
->tag
;
13309 child_die
= sibling_die (child_die
))
13311 struct call_site_parameter
*parameter
;
13312 struct attribute
*loc
, *origin
;
13314 if (child_die
->tag
!= DW_TAG_call_site_parameter
13315 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13317 /* Already printed the complaint above. */
13321 gdb_assert (call_site
->parameter_count
< nparams
);
13322 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13324 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13325 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13326 register is contained in DW_AT_call_value. */
13328 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13329 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13330 if (origin
== NULL
)
13332 /* This was a pre-DWARF-5 GNU extension alias
13333 for DW_AT_call_parameter. */
13334 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13336 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13338 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13340 sect_offset sect_off
13341 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13342 if (!cu
->header
.offset_in_cu_p (sect_off
))
13344 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13345 binding can be done only inside one CU. Such referenced DIE
13346 therefore cannot be even moved to DW_TAG_partial_unit. */
13347 complaint (_("DW_AT_call_parameter offset is not in CU for "
13348 "DW_TAG_call_site child DIE %s [in module %s]"),
13349 sect_offset_str (child_die
->sect_off
),
13350 objfile_name (objfile
));
13353 parameter
->u
.param_cu_off
13354 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13356 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13358 complaint (_("No DW_FORM_block* DW_AT_location for "
13359 "DW_TAG_call_site child DIE %s [in module %s]"),
13360 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13365 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13366 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13367 if (parameter
->u
.dwarf_reg
!= -1)
13368 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13369 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13370 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13371 ¶meter
->u
.fb_offset
))
13372 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13375 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13376 "for DW_FORM_block* DW_AT_location is supported for "
13377 "DW_TAG_call_site child DIE %s "
13379 sect_offset_str (child_die
->sect_off
),
13380 objfile_name (objfile
));
13385 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13387 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13388 if (attr
== NULL
|| !attr
->form_is_block ())
13390 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13391 "DW_TAG_call_site child DIE %s [in module %s]"),
13392 sect_offset_str (child_die
->sect_off
),
13393 objfile_name (objfile
));
13396 parameter
->value
= DW_BLOCK (attr
)->data
;
13397 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13399 /* Parameters are not pre-cleared by memset above. */
13400 parameter
->data_value
= NULL
;
13401 parameter
->data_value_size
= 0;
13402 call_site
->parameter_count
++;
13404 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13406 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13407 if (attr
!= nullptr)
13409 if (!attr
->form_is_block ())
13410 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13411 "DW_TAG_call_site child DIE %s [in module %s]"),
13412 sect_offset_str (child_die
->sect_off
),
13413 objfile_name (objfile
));
13416 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13417 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13423 /* Helper function for read_variable. If DIE represents a virtual
13424 table, then return the type of the concrete object that is
13425 associated with the virtual table. Otherwise, return NULL. */
13427 static struct type
*
13428 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13430 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13434 /* Find the type DIE. */
13435 struct die_info
*type_die
= NULL
;
13436 struct dwarf2_cu
*type_cu
= cu
;
13438 if (attr
->form_is_ref ())
13439 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13440 if (type_die
== NULL
)
13443 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13445 return die_containing_type (type_die
, type_cu
);
13448 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13451 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13453 struct rust_vtable_symbol
*storage
= NULL
;
13455 if (cu
->language
== language_rust
)
13457 struct type
*containing_type
= rust_containing_type (die
, cu
);
13459 if (containing_type
!= NULL
)
13461 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13463 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13464 initialize_objfile_symbol (storage
);
13465 storage
->concrete_type
= containing_type
;
13466 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13470 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13471 struct attribute
*abstract_origin
13472 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13473 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13474 if (res
== NULL
&& loc
&& abstract_origin
)
13476 /* We have a variable without a name, but with a location and an abstract
13477 origin. This may be a concrete instance of an abstract variable
13478 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13480 struct dwarf2_cu
*origin_cu
= cu
;
13481 struct die_info
*origin_die
13482 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13483 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13484 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13488 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13489 reading .debug_rnglists.
13490 Callback's type should be:
13491 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13492 Return true if the attributes are present and valid, otherwise,
13495 template <typename Callback
>
13497 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13498 Callback
&&callback
)
13500 struct dwarf2_per_objfile
*dwarf2_per_objfile
13501 = cu
->per_cu
->dwarf2_per_objfile
;
13502 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13503 bfd
*obfd
= objfile
->obfd
;
13504 /* Base address selection entry. */
13507 const gdb_byte
*buffer
;
13508 CORE_ADDR baseaddr
;
13509 bool overflow
= false;
13511 found_base
= cu
->base_known
;
13512 base
= cu
->base_address
;
13514 dwarf2_per_objfile
->rnglists
.read (objfile
);
13515 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13517 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13521 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13523 baseaddr
= objfile
->text_section_offset ();
13527 /* Initialize it due to a false compiler warning. */
13528 CORE_ADDR range_beginning
= 0, range_end
= 0;
13529 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13530 + dwarf2_per_objfile
->rnglists
.size
);
13531 unsigned int bytes_read
;
13533 if (buffer
== buf_end
)
13538 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13541 case DW_RLE_end_of_list
:
13543 case DW_RLE_base_address
:
13544 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13549 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13551 buffer
+= bytes_read
;
13553 case DW_RLE_start_length
:
13554 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13559 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13561 buffer
+= bytes_read
;
13562 range_end
= (range_beginning
13563 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13564 buffer
+= bytes_read
;
13565 if (buffer
> buf_end
)
13571 case DW_RLE_offset_pair
:
13572 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13573 buffer
+= bytes_read
;
13574 if (buffer
> buf_end
)
13579 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13580 buffer
+= bytes_read
;
13581 if (buffer
> buf_end
)
13587 case DW_RLE_start_end
:
13588 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13593 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13595 buffer
+= bytes_read
;
13596 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13597 buffer
+= bytes_read
;
13600 complaint (_("Invalid .debug_rnglists data (no base address)"));
13603 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13605 if (rlet
== DW_RLE_base_address
)
13610 /* We have no valid base address for the ranges
13612 complaint (_("Invalid .debug_rnglists data (no base address)"));
13616 if (range_beginning
> range_end
)
13618 /* Inverted range entries are invalid. */
13619 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13623 /* Empty range entries have no effect. */
13624 if (range_beginning
== range_end
)
13627 range_beginning
+= base
;
13630 /* A not-uncommon case of bad debug info.
13631 Don't pollute the addrmap with bad data. */
13632 if (range_beginning
+ baseaddr
== 0
13633 && !dwarf2_per_objfile
->has_section_at_zero
)
13635 complaint (_(".debug_rnglists entry has start address of zero"
13636 " [in module %s]"), objfile_name (objfile
));
13640 callback (range_beginning
, range_end
);
13645 complaint (_("Offset %d is not terminated "
13646 "for DW_AT_ranges attribute"),
13654 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13655 Callback's type should be:
13656 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13657 Return 1 if the attributes are present and valid, otherwise, return 0. */
13659 template <typename Callback
>
13661 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13662 Callback
&&callback
)
13664 struct dwarf2_per_objfile
*dwarf2_per_objfile
13665 = cu
->per_cu
->dwarf2_per_objfile
;
13666 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13667 struct comp_unit_head
*cu_header
= &cu
->header
;
13668 bfd
*obfd
= objfile
->obfd
;
13669 unsigned int addr_size
= cu_header
->addr_size
;
13670 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13671 /* Base address selection entry. */
13674 unsigned int dummy
;
13675 const gdb_byte
*buffer
;
13676 CORE_ADDR baseaddr
;
13678 if (cu_header
->version
>= 5)
13679 return dwarf2_rnglists_process (offset
, cu
, callback
);
13681 found_base
= cu
->base_known
;
13682 base
= cu
->base_address
;
13684 dwarf2_per_objfile
->ranges
.read (objfile
);
13685 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13687 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13691 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13693 baseaddr
= objfile
->text_section_offset ();
13697 CORE_ADDR range_beginning
, range_end
;
13699 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13700 buffer
+= addr_size
;
13701 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13702 buffer
+= addr_size
;
13703 offset
+= 2 * addr_size
;
13705 /* An end of list marker is a pair of zero addresses. */
13706 if (range_beginning
== 0 && range_end
== 0)
13707 /* Found the end of list entry. */
13710 /* Each base address selection entry is a pair of 2 values.
13711 The first is the largest possible address, the second is
13712 the base address. Check for a base address here. */
13713 if ((range_beginning
& mask
) == mask
)
13715 /* If we found the largest possible address, then we already
13716 have the base address in range_end. */
13724 /* We have no valid base address for the ranges
13726 complaint (_("Invalid .debug_ranges data (no base address)"));
13730 if (range_beginning
> range_end
)
13732 /* Inverted range entries are invalid. */
13733 complaint (_("Invalid .debug_ranges data (inverted range)"));
13737 /* Empty range entries have no effect. */
13738 if (range_beginning
== range_end
)
13741 range_beginning
+= base
;
13744 /* A not-uncommon case of bad debug info.
13745 Don't pollute the addrmap with bad data. */
13746 if (range_beginning
+ baseaddr
== 0
13747 && !dwarf2_per_objfile
->has_section_at_zero
)
13749 complaint (_(".debug_ranges entry has start address of zero"
13750 " [in module %s]"), objfile_name (objfile
));
13754 callback (range_beginning
, range_end
);
13760 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13761 Return 1 if the attributes are present and valid, otherwise, return 0.
13762 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13765 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13766 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13767 dwarf2_psymtab
*ranges_pst
)
13769 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13770 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13771 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13774 CORE_ADDR high
= 0;
13777 retval
= dwarf2_ranges_process (offset
, cu
,
13778 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13780 if (ranges_pst
!= NULL
)
13785 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13786 range_beginning
+ baseaddr
)
13788 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13789 range_end
+ baseaddr
)
13791 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13792 lowpc
, highpc
- 1, ranges_pst
);
13795 /* FIXME: This is recording everything as a low-high
13796 segment of consecutive addresses. We should have a
13797 data structure for discontiguous block ranges
13801 low
= range_beginning
;
13807 if (range_beginning
< low
)
13808 low
= range_beginning
;
13809 if (range_end
> high
)
13817 /* If the first entry is an end-of-list marker, the range
13818 describes an empty scope, i.e. no instructions. */
13824 *high_return
= high
;
13828 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13829 definition for the return value. *LOWPC and *HIGHPC are set iff
13830 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13832 static enum pc_bounds_kind
13833 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13834 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13835 dwarf2_psymtab
*pst
)
13837 struct dwarf2_per_objfile
*dwarf2_per_objfile
13838 = cu
->per_cu
->dwarf2_per_objfile
;
13839 struct attribute
*attr
;
13840 struct attribute
*attr_high
;
13842 CORE_ADDR high
= 0;
13843 enum pc_bounds_kind ret
;
13845 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13848 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13849 if (attr
!= nullptr)
13851 low
= attr
->value_as_address ();
13852 high
= attr_high
->value_as_address ();
13853 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13857 /* Found high w/o low attribute. */
13858 return PC_BOUNDS_INVALID
;
13860 /* Found consecutive range of addresses. */
13861 ret
= PC_BOUNDS_HIGH_LOW
;
13865 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13868 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13869 We take advantage of the fact that DW_AT_ranges does not appear
13870 in DW_TAG_compile_unit of DWO files. */
13871 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13872 unsigned int ranges_offset
= (DW_UNSND (attr
)
13873 + (need_ranges_base
13877 /* Value of the DW_AT_ranges attribute is the offset in the
13878 .debug_ranges section. */
13879 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13880 return PC_BOUNDS_INVALID
;
13881 /* Found discontinuous range of addresses. */
13882 ret
= PC_BOUNDS_RANGES
;
13885 return PC_BOUNDS_NOT_PRESENT
;
13888 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13890 return PC_BOUNDS_INVALID
;
13892 /* When using the GNU linker, .gnu.linkonce. sections are used to
13893 eliminate duplicate copies of functions and vtables and such.
13894 The linker will arbitrarily choose one and discard the others.
13895 The AT_*_pc values for such functions refer to local labels in
13896 these sections. If the section from that file was discarded, the
13897 labels are not in the output, so the relocs get a value of 0.
13898 If this is a discarded function, mark the pc bounds as invalid,
13899 so that GDB will ignore it. */
13900 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13901 return PC_BOUNDS_INVALID
;
13909 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13910 its low and high PC addresses. Do nothing if these addresses could not
13911 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13912 and HIGHPC to the high address if greater than HIGHPC. */
13915 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13916 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13917 struct dwarf2_cu
*cu
)
13919 CORE_ADDR low
, high
;
13920 struct die_info
*child
= die
->child
;
13922 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13924 *lowpc
= std::min (*lowpc
, low
);
13925 *highpc
= std::max (*highpc
, high
);
13928 /* If the language does not allow nested subprograms (either inside
13929 subprograms or lexical blocks), we're done. */
13930 if (cu
->language
!= language_ada
)
13933 /* Check all the children of the given DIE. If it contains nested
13934 subprograms, then check their pc bounds. Likewise, we need to
13935 check lexical blocks as well, as they may also contain subprogram
13937 while (child
&& child
->tag
)
13939 if (child
->tag
== DW_TAG_subprogram
13940 || child
->tag
== DW_TAG_lexical_block
)
13941 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13942 child
= sibling_die (child
);
13946 /* Get the low and high pc's represented by the scope DIE, and store
13947 them in *LOWPC and *HIGHPC. If the correct values can't be
13948 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13951 get_scope_pc_bounds (struct die_info
*die
,
13952 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13953 struct dwarf2_cu
*cu
)
13955 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13956 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13957 CORE_ADDR current_low
, current_high
;
13959 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13960 >= PC_BOUNDS_RANGES
)
13962 best_low
= current_low
;
13963 best_high
= current_high
;
13967 struct die_info
*child
= die
->child
;
13969 while (child
&& child
->tag
)
13971 switch (child
->tag
) {
13972 case DW_TAG_subprogram
:
13973 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13975 case DW_TAG_namespace
:
13976 case DW_TAG_module
:
13977 /* FIXME: carlton/2004-01-16: Should we do this for
13978 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13979 that current GCC's always emit the DIEs corresponding
13980 to definitions of methods of classes as children of a
13981 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13982 the DIEs giving the declarations, which could be
13983 anywhere). But I don't see any reason why the
13984 standards says that they have to be there. */
13985 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13987 if (current_low
!= ((CORE_ADDR
) -1))
13989 best_low
= std::min (best_low
, current_low
);
13990 best_high
= std::max (best_high
, current_high
);
13998 child
= sibling_die (child
);
14003 *highpc
= best_high
;
14006 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14010 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14011 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14013 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14014 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14015 struct attribute
*attr
;
14016 struct attribute
*attr_high
;
14018 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14021 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14022 if (attr
!= nullptr)
14024 CORE_ADDR low
= attr
->value_as_address ();
14025 CORE_ADDR high
= attr_high
->value_as_address ();
14027 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14030 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14031 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14032 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14036 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14037 if (attr
!= nullptr)
14039 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14040 We take advantage of the fact that DW_AT_ranges does not appear
14041 in DW_TAG_compile_unit of DWO files. */
14042 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14044 /* The value of the DW_AT_ranges attribute is the offset of the
14045 address range list in the .debug_ranges section. */
14046 unsigned long offset
= (DW_UNSND (attr
)
14047 + (need_ranges_base
? cu
->ranges_base
: 0));
14049 std::vector
<blockrange
> blockvec
;
14050 dwarf2_ranges_process (offset
, cu
,
14051 [&] (CORE_ADDR start
, CORE_ADDR end
)
14055 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14056 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14057 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14058 blockvec
.emplace_back (start
, end
);
14061 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14065 /* Check whether the producer field indicates either of GCC < 4.6, or the
14066 Intel C/C++ compiler, and cache the result in CU. */
14069 check_producer (struct dwarf2_cu
*cu
)
14073 if (cu
->producer
== NULL
)
14075 /* For unknown compilers expect their behavior is DWARF version
14078 GCC started to support .debug_types sections by -gdwarf-4 since
14079 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14080 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14081 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14082 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14084 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14086 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14087 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14089 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14091 cu
->producer_is_icc
= true;
14092 cu
->producer_is_icc_lt_14
= major
< 14;
14094 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14095 cu
->producer_is_codewarrior
= true;
14098 /* For other non-GCC compilers, expect their behavior is DWARF version
14102 cu
->checked_producer
= true;
14105 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14106 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14107 during 4.6.0 experimental. */
14110 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14112 if (!cu
->checked_producer
)
14113 check_producer (cu
);
14115 return cu
->producer_is_gxx_lt_4_6
;
14119 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14120 with incorrect is_stmt attributes. */
14123 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14125 if (!cu
->checked_producer
)
14126 check_producer (cu
);
14128 return cu
->producer_is_codewarrior
;
14131 /* Return the default accessibility type if it is not overridden by
14132 DW_AT_accessibility. */
14134 static enum dwarf_access_attribute
14135 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14137 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14139 /* The default DWARF 2 accessibility for members is public, the default
14140 accessibility for inheritance is private. */
14142 if (die
->tag
!= DW_TAG_inheritance
)
14143 return DW_ACCESS_public
;
14145 return DW_ACCESS_private
;
14149 /* DWARF 3+ defines the default accessibility a different way. The same
14150 rules apply now for DW_TAG_inheritance as for the members and it only
14151 depends on the container kind. */
14153 if (die
->parent
->tag
== DW_TAG_class_type
)
14154 return DW_ACCESS_private
;
14156 return DW_ACCESS_public
;
14160 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14161 offset. If the attribute was not found return 0, otherwise return
14162 1. If it was found but could not properly be handled, set *OFFSET
14166 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14169 struct attribute
*attr
;
14171 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14176 /* Note that we do not check for a section offset first here.
14177 This is because DW_AT_data_member_location is new in DWARF 4,
14178 so if we see it, we can assume that a constant form is really
14179 a constant and not a section offset. */
14180 if (attr
->form_is_constant ())
14181 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14182 else if (attr
->form_is_section_offset ())
14183 dwarf2_complex_location_expr_complaint ();
14184 else if (attr
->form_is_block ())
14185 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14187 dwarf2_complex_location_expr_complaint ();
14195 /* Add an aggregate field to the field list. */
14198 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14199 struct dwarf2_cu
*cu
)
14201 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14202 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14203 struct nextfield
*new_field
;
14204 struct attribute
*attr
;
14206 const char *fieldname
= "";
14208 if (die
->tag
== DW_TAG_inheritance
)
14210 fip
->baseclasses
.emplace_back ();
14211 new_field
= &fip
->baseclasses
.back ();
14215 fip
->fields
.emplace_back ();
14216 new_field
= &fip
->fields
.back ();
14219 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14220 if (attr
!= nullptr)
14221 new_field
->accessibility
= DW_UNSND (attr
);
14223 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14224 if (new_field
->accessibility
!= DW_ACCESS_public
)
14225 fip
->non_public_fields
= 1;
14227 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14228 if (attr
!= nullptr)
14229 new_field
->virtuality
= DW_UNSND (attr
);
14231 new_field
->virtuality
= DW_VIRTUALITY_none
;
14233 fp
= &new_field
->field
;
14235 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14239 /* Data member other than a C++ static data member. */
14241 /* Get type of field. */
14242 fp
->type
= die_type (die
, cu
);
14244 SET_FIELD_BITPOS (*fp
, 0);
14246 /* Get bit size of field (zero if none). */
14247 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14248 if (attr
!= nullptr)
14250 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14254 FIELD_BITSIZE (*fp
) = 0;
14257 /* Get bit offset of field. */
14258 if (handle_data_member_location (die
, cu
, &offset
))
14259 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14260 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14261 if (attr
!= nullptr)
14263 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14265 /* For big endian bits, the DW_AT_bit_offset gives the
14266 additional bit offset from the MSB of the containing
14267 anonymous object to the MSB of the field. We don't
14268 have to do anything special since we don't need to
14269 know the size of the anonymous object. */
14270 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14274 /* For little endian bits, compute the bit offset to the
14275 MSB of the anonymous object, subtract off the number of
14276 bits from the MSB of the field to the MSB of the
14277 object, and then subtract off the number of bits of
14278 the field itself. The result is the bit offset of
14279 the LSB of the field. */
14280 int anonymous_size
;
14281 int bit_offset
= DW_UNSND (attr
);
14283 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14284 if (attr
!= nullptr)
14286 /* The size of the anonymous object containing
14287 the bit field is explicit, so use the
14288 indicated size (in bytes). */
14289 anonymous_size
= DW_UNSND (attr
);
14293 /* The size of the anonymous object containing
14294 the bit field must be inferred from the type
14295 attribute of the data member containing the
14297 anonymous_size
= TYPE_LENGTH (fp
->type
);
14299 SET_FIELD_BITPOS (*fp
,
14300 (FIELD_BITPOS (*fp
)
14301 + anonymous_size
* bits_per_byte
14302 - bit_offset
- FIELD_BITSIZE (*fp
)));
14305 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14307 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14308 + dwarf2_get_attr_constant_value (attr
, 0)));
14310 /* Get name of field. */
14311 fieldname
= dwarf2_name (die
, cu
);
14312 if (fieldname
== NULL
)
14315 /* The name is already allocated along with this objfile, so we don't
14316 need to duplicate it for the type. */
14317 fp
->name
= fieldname
;
14319 /* Change accessibility for artificial fields (e.g. virtual table
14320 pointer or virtual base class pointer) to private. */
14321 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14323 FIELD_ARTIFICIAL (*fp
) = 1;
14324 new_field
->accessibility
= DW_ACCESS_private
;
14325 fip
->non_public_fields
= 1;
14328 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14330 /* C++ static member. */
14332 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14333 is a declaration, but all versions of G++ as of this writing
14334 (so through at least 3.2.1) incorrectly generate
14335 DW_TAG_variable tags. */
14337 const char *physname
;
14339 /* Get name of field. */
14340 fieldname
= dwarf2_name (die
, cu
);
14341 if (fieldname
== NULL
)
14344 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14346 /* Only create a symbol if this is an external value.
14347 new_symbol checks this and puts the value in the global symbol
14348 table, which we want. If it is not external, new_symbol
14349 will try to put the value in cu->list_in_scope which is wrong. */
14350 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14352 /* A static const member, not much different than an enum as far as
14353 we're concerned, except that we can support more types. */
14354 new_symbol (die
, NULL
, cu
);
14357 /* Get physical name. */
14358 physname
= dwarf2_physname (fieldname
, die
, cu
);
14360 /* The name is already allocated along with this objfile, so we don't
14361 need to duplicate it for the type. */
14362 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14363 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14364 FIELD_NAME (*fp
) = fieldname
;
14366 else if (die
->tag
== DW_TAG_inheritance
)
14370 /* C++ base class field. */
14371 if (handle_data_member_location (die
, cu
, &offset
))
14372 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14373 FIELD_BITSIZE (*fp
) = 0;
14374 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14375 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14377 else if (die
->tag
== DW_TAG_variant_part
)
14379 /* process_structure_scope will treat this DIE as a union. */
14380 process_structure_scope (die
, cu
);
14382 /* The variant part is relative to the start of the enclosing
14384 SET_FIELD_BITPOS (*fp
, 0);
14385 fp
->type
= get_die_type (die
, cu
);
14386 fp
->artificial
= 1;
14387 fp
->name
= "<<variant>>";
14389 /* Normally a DW_TAG_variant_part won't have a size, but our
14390 representation requires one, so set it to the maximum of the
14391 child sizes, being sure to account for the offset at which
14392 each child is seen. */
14393 if (TYPE_LENGTH (fp
->type
) == 0)
14396 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14398 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14399 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14403 TYPE_LENGTH (fp
->type
) = max
;
14407 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14410 /* Can the type given by DIE define another type? */
14413 type_can_define_types (const struct die_info
*die
)
14417 case DW_TAG_typedef
:
14418 case DW_TAG_class_type
:
14419 case DW_TAG_structure_type
:
14420 case DW_TAG_union_type
:
14421 case DW_TAG_enumeration_type
:
14429 /* Add a type definition defined in the scope of the FIP's class. */
14432 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14433 struct dwarf2_cu
*cu
)
14435 struct decl_field fp
;
14436 memset (&fp
, 0, sizeof (fp
));
14438 gdb_assert (type_can_define_types (die
));
14440 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14441 fp
.name
= dwarf2_name (die
, cu
);
14442 fp
.type
= read_type_die (die
, cu
);
14444 /* Save accessibility. */
14445 enum dwarf_access_attribute accessibility
;
14446 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14448 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14450 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14451 switch (accessibility
)
14453 case DW_ACCESS_public
:
14454 /* The assumed value if neither private nor protected. */
14456 case DW_ACCESS_private
:
14459 case DW_ACCESS_protected
:
14460 fp
.is_protected
= 1;
14463 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14466 if (die
->tag
== DW_TAG_typedef
)
14467 fip
->typedef_field_list
.push_back (fp
);
14469 fip
->nested_types_list
.push_back (fp
);
14472 /* Create the vector of fields, and attach it to the type. */
14475 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14476 struct dwarf2_cu
*cu
)
14478 int nfields
= fip
->nfields ();
14480 /* Record the field count, allocate space for the array of fields,
14481 and create blank accessibility bitfields if necessary. */
14482 TYPE_NFIELDS (type
) = nfields
;
14483 TYPE_FIELDS (type
) = (struct field
*)
14484 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14486 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14488 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14490 TYPE_FIELD_PRIVATE_BITS (type
) =
14491 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14492 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14494 TYPE_FIELD_PROTECTED_BITS (type
) =
14495 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14496 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14498 TYPE_FIELD_IGNORE_BITS (type
) =
14499 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14500 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14503 /* If the type has baseclasses, allocate and clear a bit vector for
14504 TYPE_FIELD_VIRTUAL_BITS. */
14505 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14507 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14508 unsigned char *pointer
;
14510 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14511 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14512 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14513 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14514 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14517 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14519 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14521 for (int index
= 0; index
< nfields
; ++index
)
14523 struct nextfield
&field
= fip
->fields
[index
];
14525 if (field
.variant
.is_discriminant
)
14526 di
->discriminant_index
= index
;
14527 else if (field
.variant
.default_branch
)
14528 di
->default_index
= index
;
14530 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14534 /* Copy the saved-up fields into the field vector. */
14535 for (int i
= 0; i
< nfields
; ++i
)
14537 struct nextfield
&field
14538 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14539 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14541 TYPE_FIELD (type
, i
) = field
.field
;
14542 switch (field
.accessibility
)
14544 case DW_ACCESS_private
:
14545 if (cu
->language
!= language_ada
)
14546 SET_TYPE_FIELD_PRIVATE (type
, i
);
14549 case DW_ACCESS_protected
:
14550 if (cu
->language
!= language_ada
)
14551 SET_TYPE_FIELD_PROTECTED (type
, i
);
14554 case DW_ACCESS_public
:
14558 /* Unknown accessibility. Complain and treat it as public. */
14560 complaint (_("unsupported accessibility %d"),
14561 field
.accessibility
);
14565 if (i
< fip
->baseclasses
.size ())
14567 switch (field
.virtuality
)
14569 case DW_VIRTUALITY_virtual
:
14570 case DW_VIRTUALITY_pure_virtual
:
14571 if (cu
->language
== language_ada
)
14572 error (_("unexpected virtuality in component of Ada type"));
14573 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14580 /* Return true if this member function is a constructor, false
14584 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14586 const char *fieldname
;
14587 const char *type_name
;
14590 if (die
->parent
== NULL
)
14593 if (die
->parent
->tag
!= DW_TAG_structure_type
14594 && die
->parent
->tag
!= DW_TAG_union_type
14595 && die
->parent
->tag
!= DW_TAG_class_type
)
14598 fieldname
= dwarf2_name (die
, cu
);
14599 type_name
= dwarf2_name (die
->parent
, cu
);
14600 if (fieldname
== NULL
|| type_name
== NULL
)
14603 len
= strlen (fieldname
);
14604 return (strncmp (fieldname
, type_name
, len
) == 0
14605 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14608 /* Check if the given VALUE is a recognized enum
14609 dwarf_defaulted_attribute constant according to DWARF5 spec,
14613 is_valid_DW_AT_defaulted (ULONGEST value
)
14617 case DW_DEFAULTED_no
:
14618 case DW_DEFAULTED_in_class
:
14619 case DW_DEFAULTED_out_of_class
:
14623 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14627 /* Add a member function to the proper fieldlist. */
14630 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14631 struct type
*type
, struct dwarf2_cu
*cu
)
14633 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14634 struct attribute
*attr
;
14636 struct fnfieldlist
*flp
= nullptr;
14637 struct fn_field
*fnp
;
14638 const char *fieldname
;
14639 struct type
*this_type
;
14640 enum dwarf_access_attribute accessibility
;
14642 if (cu
->language
== language_ada
)
14643 error (_("unexpected member function in Ada type"));
14645 /* Get name of member function. */
14646 fieldname
= dwarf2_name (die
, cu
);
14647 if (fieldname
== NULL
)
14650 /* Look up member function name in fieldlist. */
14651 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14653 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14655 flp
= &fip
->fnfieldlists
[i
];
14660 /* Create a new fnfieldlist if necessary. */
14661 if (flp
== nullptr)
14663 fip
->fnfieldlists
.emplace_back ();
14664 flp
= &fip
->fnfieldlists
.back ();
14665 flp
->name
= fieldname
;
14666 i
= fip
->fnfieldlists
.size () - 1;
14669 /* Create a new member function field and add it to the vector of
14671 flp
->fnfields
.emplace_back ();
14672 fnp
= &flp
->fnfields
.back ();
14674 /* Delay processing of the physname until later. */
14675 if (cu
->language
== language_cplus
)
14676 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14680 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14681 fnp
->physname
= physname
? physname
: "";
14684 fnp
->type
= alloc_type (objfile
);
14685 this_type
= read_type_die (die
, cu
);
14686 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14688 int nparams
= TYPE_NFIELDS (this_type
);
14690 /* TYPE is the domain of this method, and THIS_TYPE is the type
14691 of the method itself (TYPE_CODE_METHOD). */
14692 smash_to_method_type (fnp
->type
, type
,
14693 TYPE_TARGET_TYPE (this_type
),
14694 TYPE_FIELDS (this_type
),
14695 TYPE_NFIELDS (this_type
),
14696 TYPE_VARARGS (this_type
));
14698 /* Handle static member functions.
14699 Dwarf2 has no clean way to discern C++ static and non-static
14700 member functions. G++ helps GDB by marking the first
14701 parameter for non-static member functions (which is the this
14702 pointer) as artificial. We obtain this information from
14703 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14704 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14705 fnp
->voffset
= VOFFSET_STATIC
;
14708 complaint (_("member function type missing for '%s'"),
14709 dwarf2_full_name (fieldname
, die
, cu
));
14711 /* Get fcontext from DW_AT_containing_type if present. */
14712 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14713 fnp
->fcontext
= die_containing_type (die
, cu
);
14715 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14716 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14718 /* Get accessibility. */
14719 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14720 if (attr
!= nullptr)
14721 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14723 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14724 switch (accessibility
)
14726 case DW_ACCESS_private
:
14727 fnp
->is_private
= 1;
14729 case DW_ACCESS_protected
:
14730 fnp
->is_protected
= 1;
14734 /* Check for artificial methods. */
14735 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14736 if (attr
&& DW_UNSND (attr
) != 0)
14737 fnp
->is_artificial
= 1;
14739 /* Check for defaulted methods. */
14740 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14741 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14742 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14744 /* Check for deleted methods. */
14745 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14746 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14747 fnp
->is_deleted
= 1;
14749 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14751 /* Get index in virtual function table if it is a virtual member
14752 function. For older versions of GCC, this is an offset in the
14753 appropriate virtual table, as specified by DW_AT_containing_type.
14754 For everyone else, it is an expression to be evaluated relative
14755 to the object address. */
14757 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14758 if (attr
!= nullptr)
14760 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14762 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14764 /* Old-style GCC. */
14765 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14767 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14768 || (DW_BLOCK (attr
)->size
> 1
14769 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14770 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14772 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14773 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14774 dwarf2_complex_location_expr_complaint ();
14776 fnp
->voffset
/= cu
->header
.addr_size
;
14780 dwarf2_complex_location_expr_complaint ();
14782 if (!fnp
->fcontext
)
14784 /* If there is no `this' field and no DW_AT_containing_type,
14785 we cannot actually find a base class context for the
14787 if (TYPE_NFIELDS (this_type
) == 0
14788 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14790 complaint (_("cannot determine context for virtual member "
14791 "function \"%s\" (offset %s)"),
14792 fieldname
, sect_offset_str (die
->sect_off
));
14797 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14801 else if (attr
->form_is_section_offset ())
14803 dwarf2_complex_location_expr_complaint ();
14807 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14813 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14814 if (attr
&& DW_UNSND (attr
))
14816 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14817 complaint (_("Member function \"%s\" (offset %s) is virtual "
14818 "but the vtable offset is not specified"),
14819 fieldname
, sect_offset_str (die
->sect_off
));
14820 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14821 TYPE_CPLUS_DYNAMIC (type
) = 1;
14826 /* Create the vector of member function fields, and attach it to the type. */
14829 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14830 struct dwarf2_cu
*cu
)
14832 if (cu
->language
== language_ada
)
14833 error (_("unexpected member functions in Ada type"));
14835 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14836 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14838 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14840 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14842 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14843 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14845 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14846 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14847 fn_flp
->fn_fields
= (struct fn_field
*)
14848 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14850 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14851 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14854 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14857 /* Returns non-zero if NAME is the name of a vtable member in CU's
14858 language, zero otherwise. */
14860 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14862 static const char vptr
[] = "_vptr";
14864 /* Look for the C++ form of the vtable. */
14865 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14871 /* GCC outputs unnamed structures that are really pointers to member
14872 functions, with the ABI-specified layout. If TYPE describes
14873 such a structure, smash it into a member function type.
14875 GCC shouldn't do this; it should just output pointer to member DIEs.
14876 This is GCC PR debug/28767. */
14879 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14881 struct type
*pfn_type
, *self_type
, *new_type
;
14883 /* Check for a structure with no name and two children. */
14884 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14887 /* Check for __pfn and __delta members. */
14888 if (TYPE_FIELD_NAME (type
, 0) == NULL
14889 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14890 || TYPE_FIELD_NAME (type
, 1) == NULL
14891 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14894 /* Find the type of the method. */
14895 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14896 if (pfn_type
== NULL
14897 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14898 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14901 /* Look for the "this" argument. */
14902 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14903 if (TYPE_NFIELDS (pfn_type
) == 0
14904 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14905 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14908 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14909 new_type
= alloc_type (objfile
);
14910 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14911 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14912 TYPE_VARARGS (pfn_type
));
14913 smash_to_methodptr_type (type
, new_type
);
14916 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14917 appropriate error checking and issuing complaints if there is a
14921 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14923 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14925 if (attr
== nullptr)
14928 if (!attr
->form_is_constant ())
14930 complaint (_("DW_AT_alignment must have constant form"
14931 " - DIE at %s [in module %s]"),
14932 sect_offset_str (die
->sect_off
),
14933 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14938 if (attr
->form
== DW_FORM_sdata
)
14940 LONGEST val
= DW_SND (attr
);
14943 complaint (_("DW_AT_alignment value must not be negative"
14944 " - DIE at %s [in module %s]"),
14945 sect_offset_str (die
->sect_off
),
14946 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14952 align
= DW_UNSND (attr
);
14956 complaint (_("DW_AT_alignment value must not be zero"
14957 " - DIE at %s [in module %s]"),
14958 sect_offset_str (die
->sect_off
),
14959 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14962 if ((align
& (align
- 1)) != 0)
14964 complaint (_("DW_AT_alignment value must be a power of 2"
14965 " - DIE at %s [in module %s]"),
14966 sect_offset_str (die
->sect_off
),
14967 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14974 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14975 the alignment for TYPE. */
14978 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14981 if (!set_type_align (type
, get_alignment (cu
, die
)))
14982 complaint (_("DW_AT_alignment value too large"
14983 " - DIE at %s [in module %s]"),
14984 sect_offset_str (die
->sect_off
),
14985 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14988 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14989 constant for a type, according to DWARF5 spec, Table 5.5. */
14992 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14997 case DW_CC_pass_by_reference
:
14998 case DW_CC_pass_by_value
:
15002 complaint (_("unrecognized DW_AT_calling_convention value "
15003 "(%s) for a type"), pulongest (value
));
15008 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15009 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15010 also according to GNU-specific values (see include/dwarf2.h). */
15013 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15018 case DW_CC_program
:
15022 case DW_CC_GNU_renesas_sh
:
15023 case DW_CC_GNU_borland_fastcall_i386
:
15024 case DW_CC_GDB_IBM_OpenCL
:
15028 complaint (_("unrecognized DW_AT_calling_convention value "
15029 "(%s) for a subroutine"), pulongest (value
));
15034 /* Called when we find the DIE that starts a structure or union scope
15035 (definition) to create a type for the structure or union. Fill in
15036 the type's name and general properties; the members will not be
15037 processed until process_structure_scope. A symbol table entry for
15038 the type will also not be done until process_structure_scope (assuming
15039 the type has a name).
15041 NOTE: we need to call these functions regardless of whether or not the
15042 DIE has a DW_AT_name attribute, since it might be an anonymous
15043 structure or union. This gets the type entered into our set of
15044 user defined types. */
15046 static struct type
*
15047 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15049 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15051 struct attribute
*attr
;
15054 /* If the definition of this type lives in .debug_types, read that type.
15055 Don't follow DW_AT_specification though, that will take us back up
15056 the chain and we want to go down. */
15057 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15058 if (attr
!= nullptr)
15060 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15062 /* The type's CU may not be the same as CU.
15063 Ensure TYPE is recorded with CU in die_type_hash. */
15064 return set_die_type (die
, type
, cu
);
15067 type
= alloc_type (objfile
);
15068 INIT_CPLUS_SPECIFIC (type
);
15070 name
= dwarf2_name (die
, cu
);
15073 if (cu
->language
== language_cplus
15074 || cu
->language
== language_d
15075 || cu
->language
== language_rust
)
15077 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15079 /* dwarf2_full_name might have already finished building the DIE's
15080 type. If so, there is no need to continue. */
15081 if (get_die_type (die
, cu
) != NULL
)
15082 return get_die_type (die
, cu
);
15084 TYPE_NAME (type
) = full_name
;
15088 /* The name is already allocated along with this objfile, so
15089 we don't need to duplicate it for the type. */
15090 TYPE_NAME (type
) = name
;
15094 if (die
->tag
== DW_TAG_structure_type
)
15096 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15098 else if (die
->tag
== DW_TAG_union_type
)
15100 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15102 else if (die
->tag
== DW_TAG_variant_part
)
15104 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15105 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15109 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15112 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15113 TYPE_DECLARED_CLASS (type
) = 1;
15115 /* Store the calling convention in the type if it's available in
15116 the die. Otherwise the calling convention remains set to
15117 the default value DW_CC_normal. */
15118 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15119 if (attr
!= nullptr
15120 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15122 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15123 TYPE_CPLUS_CALLING_CONVENTION (type
)
15124 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15127 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15128 if (attr
!= nullptr)
15130 if (attr
->form_is_constant ())
15131 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15134 /* For the moment, dynamic type sizes are not supported
15135 by GDB's struct type. The actual size is determined
15136 on-demand when resolving the type of a given object,
15137 so set the type's length to zero for now. Otherwise,
15138 we record an expression as the length, and that expression
15139 could lead to a very large value, which could eventually
15140 lead to us trying to allocate that much memory when creating
15141 a value of that type. */
15142 TYPE_LENGTH (type
) = 0;
15147 TYPE_LENGTH (type
) = 0;
15150 maybe_set_alignment (cu
, die
, type
);
15152 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15154 /* ICC<14 does not output the required DW_AT_declaration on
15155 incomplete types, but gives them a size of zero. */
15156 TYPE_STUB (type
) = 1;
15159 TYPE_STUB_SUPPORTED (type
) = 1;
15161 if (die_is_declaration (die
, cu
))
15162 TYPE_STUB (type
) = 1;
15163 else if (attr
== NULL
&& die
->child
== NULL
15164 && producer_is_realview (cu
->producer
))
15165 /* RealView does not output the required DW_AT_declaration
15166 on incomplete types. */
15167 TYPE_STUB (type
) = 1;
15169 /* We need to add the type field to the die immediately so we don't
15170 infinitely recurse when dealing with pointers to the structure
15171 type within the structure itself. */
15172 set_die_type (die
, type
, cu
);
15174 /* set_die_type should be already done. */
15175 set_descriptive_type (type
, die
, cu
);
15180 /* A helper for process_structure_scope that handles a single member
15184 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15185 struct field_info
*fi
,
15186 std::vector
<struct symbol
*> *template_args
,
15187 struct dwarf2_cu
*cu
)
15189 if (child_die
->tag
== DW_TAG_member
15190 || child_die
->tag
== DW_TAG_variable
15191 || child_die
->tag
== DW_TAG_variant_part
)
15193 /* NOTE: carlton/2002-11-05: A C++ static data member
15194 should be a DW_TAG_member that is a declaration, but
15195 all versions of G++ as of this writing (so through at
15196 least 3.2.1) incorrectly generate DW_TAG_variable
15197 tags for them instead. */
15198 dwarf2_add_field (fi
, child_die
, cu
);
15200 else if (child_die
->tag
== DW_TAG_subprogram
)
15202 /* Rust doesn't have member functions in the C++ sense.
15203 However, it does emit ordinary functions as children
15204 of a struct DIE. */
15205 if (cu
->language
== language_rust
)
15206 read_func_scope (child_die
, cu
);
15209 /* C++ member function. */
15210 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15213 else if (child_die
->tag
== DW_TAG_inheritance
)
15215 /* C++ base class field. */
15216 dwarf2_add_field (fi
, child_die
, cu
);
15218 else if (type_can_define_types (child_die
))
15219 dwarf2_add_type_defn (fi
, child_die
, cu
);
15220 else if (child_die
->tag
== DW_TAG_template_type_param
15221 || child_die
->tag
== DW_TAG_template_value_param
)
15223 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15226 template_args
->push_back (arg
);
15228 else if (child_die
->tag
== DW_TAG_variant
)
15230 /* In a variant we want to get the discriminant and also add a
15231 field for our sole member child. */
15232 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15234 for (die_info
*variant_child
= child_die
->child
;
15235 variant_child
!= NULL
;
15236 variant_child
= sibling_die (variant_child
))
15238 if (variant_child
->tag
== DW_TAG_member
)
15240 handle_struct_member_die (variant_child
, type
, fi
,
15241 template_args
, cu
);
15242 /* Only handle the one. */
15247 /* We don't handle this but we might as well report it if we see
15249 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15250 complaint (_("DW_AT_discr_list is not supported yet"
15251 " - DIE at %s [in module %s]"),
15252 sect_offset_str (child_die
->sect_off
),
15253 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15255 /* The first field was just added, so we can stash the
15256 discriminant there. */
15257 gdb_assert (!fi
->fields
.empty ());
15259 fi
->fields
.back ().variant
.default_branch
= true;
15261 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15265 /* Finish creating a structure or union type, including filling in
15266 its members and creating a symbol for it. */
15269 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15271 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15272 struct die_info
*child_die
;
15275 type
= get_die_type (die
, cu
);
15277 type
= read_structure_type (die
, cu
);
15279 /* When reading a DW_TAG_variant_part, we need to notice when we
15280 read the discriminant member, so we can record it later in the
15281 discriminant_info. */
15282 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15283 sect_offset discr_offset
{};
15284 bool has_template_parameters
= false;
15286 if (is_variant_part
)
15288 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15291 /* Maybe it's a univariant form, an extension we support.
15292 In this case arrange not to check the offset. */
15293 is_variant_part
= false;
15295 else if (discr
->form_is_ref ())
15297 struct dwarf2_cu
*target_cu
= cu
;
15298 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15300 discr_offset
= target_die
->sect_off
;
15304 complaint (_("DW_AT_discr does not have DIE reference form"
15305 " - DIE at %s [in module %s]"),
15306 sect_offset_str (die
->sect_off
),
15307 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15308 is_variant_part
= false;
15312 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15314 struct field_info fi
;
15315 std::vector
<struct symbol
*> template_args
;
15317 child_die
= die
->child
;
15319 while (child_die
&& child_die
->tag
)
15321 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15323 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15324 fi
.fields
.back ().variant
.is_discriminant
= true;
15326 child_die
= sibling_die (child_die
);
15329 /* Attach template arguments to type. */
15330 if (!template_args
.empty ())
15332 has_template_parameters
= true;
15333 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15334 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15335 TYPE_TEMPLATE_ARGUMENTS (type
)
15336 = XOBNEWVEC (&objfile
->objfile_obstack
,
15338 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15339 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15340 template_args
.data (),
15341 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15342 * sizeof (struct symbol
*)));
15345 /* Attach fields and member functions to the type. */
15346 if (fi
.nfields () > 0)
15347 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15348 if (!fi
.fnfieldlists
.empty ())
15350 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15352 /* Get the type which refers to the base class (possibly this
15353 class itself) which contains the vtable pointer for the current
15354 class from the DW_AT_containing_type attribute. This use of
15355 DW_AT_containing_type is a GNU extension. */
15357 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15359 struct type
*t
= die_containing_type (die
, cu
);
15361 set_type_vptr_basetype (type
, t
);
15366 /* Our own class provides vtbl ptr. */
15367 for (i
= TYPE_NFIELDS (t
) - 1;
15368 i
>= TYPE_N_BASECLASSES (t
);
15371 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15373 if (is_vtable_name (fieldname
, cu
))
15375 set_type_vptr_fieldno (type
, i
);
15380 /* Complain if virtual function table field not found. */
15381 if (i
< TYPE_N_BASECLASSES (t
))
15382 complaint (_("virtual function table pointer "
15383 "not found when defining class '%s'"),
15384 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15388 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15391 else if (cu
->producer
15392 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15394 /* The IBM XLC compiler does not provide direct indication
15395 of the containing type, but the vtable pointer is
15396 always named __vfp. */
15400 for (i
= TYPE_NFIELDS (type
) - 1;
15401 i
>= TYPE_N_BASECLASSES (type
);
15404 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15406 set_type_vptr_fieldno (type
, i
);
15407 set_type_vptr_basetype (type
, type
);
15414 /* Copy fi.typedef_field_list linked list elements content into the
15415 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15416 if (!fi
.typedef_field_list
.empty ())
15418 int count
= fi
.typedef_field_list
.size ();
15420 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15421 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15422 = ((struct decl_field
*)
15424 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15425 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15427 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15428 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15431 /* Copy fi.nested_types_list linked list elements content into the
15432 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15433 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15435 int count
= fi
.nested_types_list
.size ();
15437 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15438 TYPE_NESTED_TYPES_ARRAY (type
)
15439 = ((struct decl_field
*)
15440 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15441 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15443 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15444 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15448 quirk_gcc_member_function_pointer (type
, objfile
);
15449 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15450 cu
->rust_unions
.push_back (type
);
15452 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15453 snapshots) has been known to create a die giving a declaration
15454 for a class that has, as a child, a die giving a definition for a
15455 nested class. So we have to process our children even if the
15456 current die is a declaration. Normally, of course, a declaration
15457 won't have any children at all. */
15459 child_die
= die
->child
;
15461 while (child_die
!= NULL
&& child_die
->tag
)
15463 if (child_die
->tag
== DW_TAG_member
15464 || child_die
->tag
== DW_TAG_variable
15465 || child_die
->tag
== DW_TAG_inheritance
15466 || child_die
->tag
== DW_TAG_template_value_param
15467 || child_die
->tag
== DW_TAG_template_type_param
)
15472 process_die (child_die
, cu
);
15474 child_die
= sibling_die (child_die
);
15477 /* Do not consider external references. According to the DWARF standard,
15478 these DIEs are identified by the fact that they have no byte_size
15479 attribute, and a declaration attribute. */
15480 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15481 || !die_is_declaration (die
, cu
))
15483 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15485 if (has_template_parameters
)
15487 struct symtab
*symtab
;
15488 if (sym
!= nullptr)
15489 symtab
= symbol_symtab (sym
);
15490 else if (cu
->line_header
!= nullptr)
15492 /* Any related symtab will do. */
15494 = cu
->line_header
->file_names ()[0].symtab
;
15499 complaint (_("could not find suitable "
15500 "symtab for template parameter"
15501 " - DIE at %s [in module %s]"),
15502 sect_offset_str (die
->sect_off
),
15503 objfile_name (objfile
));
15506 if (symtab
!= nullptr)
15508 /* Make sure that the symtab is set on the new symbols.
15509 Even though they don't appear in this symtab directly,
15510 other parts of gdb assume that symbols do, and this is
15511 reasonably true. */
15512 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15513 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15519 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15520 update TYPE using some information only available in DIE's children. */
15523 update_enumeration_type_from_children (struct die_info
*die
,
15525 struct dwarf2_cu
*cu
)
15527 struct die_info
*child_die
;
15528 int unsigned_enum
= 1;
15531 auto_obstack obstack
;
15533 for (child_die
= die
->child
;
15534 child_die
!= NULL
&& child_die
->tag
;
15535 child_die
= sibling_die (child_die
))
15537 struct attribute
*attr
;
15539 const gdb_byte
*bytes
;
15540 struct dwarf2_locexpr_baton
*baton
;
15543 if (child_die
->tag
!= DW_TAG_enumerator
)
15546 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15550 name
= dwarf2_name (child_die
, cu
);
15552 name
= "<anonymous enumerator>";
15554 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15555 &value
, &bytes
, &baton
);
15563 if (count_one_bits_ll (value
) >= 2)
15567 /* If we already know that the enum type is neither unsigned, nor
15568 a flag type, no need to look at the rest of the enumerates. */
15569 if (!unsigned_enum
&& !flag_enum
)
15574 TYPE_UNSIGNED (type
) = 1;
15576 TYPE_FLAG_ENUM (type
) = 1;
15579 /* Given a DW_AT_enumeration_type die, set its type. We do not
15580 complete the type's fields yet, or create any symbols. */
15582 static struct type
*
15583 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15585 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15587 struct attribute
*attr
;
15590 /* If the definition of this type lives in .debug_types, read that type.
15591 Don't follow DW_AT_specification though, that will take us back up
15592 the chain and we want to go down. */
15593 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15594 if (attr
!= nullptr)
15596 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15598 /* The type's CU may not be the same as CU.
15599 Ensure TYPE is recorded with CU in die_type_hash. */
15600 return set_die_type (die
, type
, cu
);
15603 type
= alloc_type (objfile
);
15605 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15606 name
= dwarf2_full_name (NULL
, die
, cu
);
15608 TYPE_NAME (type
) = name
;
15610 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15613 struct type
*underlying_type
= die_type (die
, cu
);
15615 TYPE_TARGET_TYPE (type
) = underlying_type
;
15618 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15619 if (attr
!= nullptr)
15621 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15625 TYPE_LENGTH (type
) = 0;
15628 maybe_set_alignment (cu
, die
, type
);
15630 /* The enumeration DIE can be incomplete. In Ada, any type can be
15631 declared as private in the package spec, and then defined only
15632 inside the package body. Such types are known as Taft Amendment
15633 Types. When another package uses such a type, an incomplete DIE
15634 may be generated by the compiler. */
15635 if (die_is_declaration (die
, cu
))
15636 TYPE_STUB (type
) = 1;
15638 /* Finish the creation of this type by using the enum's children.
15639 We must call this even when the underlying type has been provided
15640 so that we can determine if we're looking at a "flag" enum. */
15641 update_enumeration_type_from_children (die
, type
, cu
);
15643 /* If this type has an underlying type that is not a stub, then we
15644 may use its attributes. We always use the "unsigned" attribute
15645 in this situation, because ordinarily we guess whether the type
15646 is unsigned -- but the guess can be wrong and the underlying type
15647 can tell us the reality. However, we defer to a local size
15648 attribute if one exists, because this lets the compiler override
15649 the underlying type if needed. */
15650 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15652 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15653 if (TYPE_LENGTH (type
) == 0)
15654 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15655 if (TYPE_RAW_ALIGN (type
) == 0
15656 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15657 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15660 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15662 return set_die_type (die
, type
, cu
);
15665 /* Given a pointer to a die which begins an enumeration, process all
15666 the dies that define the members of the enumeration, and create the
15667 symbol for the enumeration type.
15669 NOTE: We reverse the order of the element list. */
15672 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15674 struct type
*this_type
;
15676 this_type
= get_die_type (die
, cu
);
15677 if (this_type
== NULL
)
15678 this_type
= read_enumeration_type (die
, cu
);
15680 if (die
->child
!= NULL
)
15682 struct die_info
*child_die
;
15683 struct symbol
*sym
;
15684 std::vector
<struct field
> fields
;
15687 child_die
= die
->child
;
15688 while (child_die
&& child_die
->tag
)
15690 if (child_die
->tag
!= DW_TAG_enumerator
)
15692 process_die (child_die
, cu
);
15696 name
= dwarf2_name (child_die
, cu
);
15699 sym
= new_symbol (child_die
, this_type
, cu
);
15701 fields
.emplace_back ();
15702 struct field
&field
= fields
.back ();
15704 FIELD_NAME (field
) = sym
->linkage_name ();
15705 FIELD_TYPE (field
) = NULL
;
15706 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15707 FIELD_BITSIZE (field
) = 0;
15711 child_die
= sibling_die (child_die
);
15714 if (!fields
.empty ())
15716 TYPE_NFIELDS (this_type
) = fields
.size ();
15717 TYPE_FIELDS (this_type
) = (struct field
*)
15718 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15719 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15720 sizeof (struct field
) * fields
.size ());
15724 /* If we are reading an enum from a .debug_types unit, and the enum
15725 is a declaration, and the enum is not the signatured type in the
15726 unit, then we do not want to add a symbol for it. Adding a
15727 symbol would in some cases obscure the true definition of the
15728 enum, giving users an incomplete type when the definition is
15729 actually available. Note that we do not want to do this for all
15730 enums which are just declarations, because C++0x allows forward
15731 enum declarations. */
15732 if (cu
->per_cu
->is_debug_types
15733 && die_is_declaration (die
, cu
))
15735 struct signatured_type
*sig_type
;
15737 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15738 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15739 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15743 new_symbol (die
, this_type
, cu
);
15746 /* Extract all information from a DW_TAG_array_type DIE and put it in
15747 the DIE's type field. For now, this only handles one dimensional
15750 static struct type
*
15751 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15753 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15754 struct die_info
*child_die
;
15756 struct type
*element_type
, *range_type
, *index_type
;
15757 struct attribute
*attr
;
15759 struct dynamic_prop
*byte_stride_prop
= NULL
;
15760 unsigned int bit_stride
= 0;
15762 element_type
= die_type (die
, cu
);
15764 /* The die_type call above may have already set the type for this DIE. */
15765 type
= get_die_type (die
, cu
);
15769 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15773 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15776 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15777 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15781 complaint (_("unable to read array DW_AT_byte_stride "
15782 " - DIE at %s [in module %s]"),
15783 sect_offset_str (die
->sect_off
),
15784 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15785 /* Ignore this attribute. We will likely not be able to print
15786 arrays of this type correctly, but there is little we can do
15787 to help if we cannot read the attribute's value. */
15788 byte_stride_prop
= NULL
;
15792 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15794 bit_stride
= DW_UNSND (attr
);
15796 /* Irix 6.2 native cc creates array types without children for
15797 arrays with unspecified length. */
15798 if (die
->child
== NULL
)
15800 index_type
= objfile_type (objfile
)->builtin_int
;
15801 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15802 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15803 byte_stride_prop
, bit_stride
);
15804 return set_die_type (die
, type
, cu
);
15807 std::vector
<struct type
*> range_types
;
15808 child_die
= die
->child
;
15809 while (child_die
&& child_die
->tag
)
15811 if (child_die
->tag
== DW_TAG_subrange_type
)
15813 struct type
*child_type
= read_type_die (child_die
, cu
);
15815 if (child_type
!= NULL
)
15817 /* The range type was succesfully read. Save it for the
15818 array type creation. */
15819 range_types
.push_back (child_type
);
15822 child_die
= sibling_die (child_die
);
15825 /* Dwarf2 dimensions are output from left to right, create the
15826 necessary array types in backwards order. */
15828 type
= element_type
;
15830 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15834 while (i
< range_types
.size ())
15835 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15836 byte_stride_prop
, bit_stride
);
15840 size_t ndim
= range_types
.size ();
15842 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15843 byte_stride_prop
, bit_stride
);
15846 /* Understand Dwarf2 support for vector types (like they occur on
15847 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15848 array type. This is not part of the Dwarf2/3 standard yet, but a
15849 custom vendor extension. The main difference between a regular
15850 array and the vector variant is that vectors are passed by value
15852 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15853 if (attr
!= nullptr)
15854 make_vector_type (type
);
15856 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15857 implementation may choose to implement triple vectors using this
15859 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15860 if (attr
!= nullptr)
15862 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15863 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15865 complaint (_("DW_AT_byte_size for array type smaller "
15866 "than the total size of elements"));
15869 name
= dwarf2_name (die
, cu
);
15871 TYPE_NAME (type
) = name
;
15873 maybe_set_alignment (cu
, die
, type
);
15875 /* Install the type in the die. */
15876 set_die_type (die
, type
, cu
);
15878 /* set_die_type should be already done. */
15879 set_descriptive_type (type
, die
, cu
);
15884 static enum dwarf_array_dim_ordering
15885 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15887 struct attribute
*attr
;
15889 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15891 if (attr
!= nullptr)
15892 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15894 /* GNU F77 is a special case, as at 08/2004 array type info is the
15895 opposite order to the dwarf2 specification, but data is still
15896 laid out as per normal fortran.
15898 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15899 version checking. */
15901 if (cu
->language
== language_fortran
15902 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15904 return DW_ORD_row_major
;
15907 switch (cu
->language_defn
->la_array_ordering
)
15909 case array_column_major
:
15910 return DW_ORD_col_major
;
15911 case array_row_major
:
15913 return DW_ORD_row_major
;
15917 /* Extract all information from a DW_TAG_set_type DIE and put it in
15918 the DIE's type field. */
15920 static struct type
*
15921 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15923 struct type
*domain_type
, *set_type
;
15924 struct attribute
*attr
;
15926 domain_type
= die_type (die
, cu
);
15928 /* The die_type call above may have already set the type for this DIE. */
15929 set_type
= get_die_type (die
, cu
);
15933 set_type
= create_set_type (NULL
, domain_type
);
15935 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15936 if (attr
!= nullptr)
15937 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15939 maybe_set_alignment (cu
, die
, set_type
);
15941 return set_die_type (die
, set_type
, cu
);
15944 /* A helper for read_common_block that creates a locexpr baton.
15945 SYM is the symbol which we are marking as computed.
15946 COMMON_DIE is the DIE for the common block.
15947 COMMON_LOC is the location expression attribute for the common
15949 MEMBER_LOC is the location expression attribute for the particular
15950 member of the common block that we are processing.
15951 CU is the CU from which the above come. */
15954 mark_common_block_symbol_computed (struct symbol
*sym
,
15955 struct die_info
*common_die
,
15956 struct attribute
*common_loc
,
15957 struct attribute
*member_loc
,
15958 struct dwarf2_cu
*cu
)
15960 struct dwarf2_per_objfile
*dwarf2_per_objfile
15961 = cu
->per_cu
->dwarf2_per_objfile
;
15962 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15963 struct dwarf2_locexpr_baton
*baton
;
15965 unsigned int cu_off
;
15966 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15967 LONGEST offset
= 0;
15969 gdb_assert (common_loc
&& member_loc
);
15970 gdb_assert (common_loc
->form_is_block ());
15971 gdb_assert (member_loc
->form_is_block ()
15972 || member_loc
->form_is_constant ());
15974 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15975 baton
->per_cu
= cu
->per_cu
;
15976 gdb_assert (baton
->per_cu
);
15978 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15980 if (member_loc
->form_is_constant ())
15982 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15983 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15986 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15988 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15991 *ptr
++ = DW_OP_call4
;
15992 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15993 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15996 if (member_loc
->form_is_constant ())
15998 *ptr
++ = DW_OP_addr
;
15999 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16000 ptr
+= cu
->header
.addr_size
;
16004 /* We have to copy the data here, because DW_OP_call4 will only
16005 use a DW_AT_location attribute. */
16006 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16007 ptr
+= DW_BLOCK (member_loc
)->size
;
16010 *ptr
++ = DW_OP_plus
;
16011 gdb_assert (ptr
- baton
->data
== baton
->size
);
16013 SYMBOL_LOCATION_BATON (sym
) = baton
;
16014 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16017 /* Create appropriate locally-scoped variables for all the
16018 DW_TAG_common_block entries. Also create a struct common_block
16019 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16020 is used to separate the common blocks name namespace from regular
16024 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16026 struct attribute
*attr
;
16028 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16029 if (attr
!= nullptr)
16031 /* Support the .debug_loc offsets. */
16032 if (attr
->form_is_block ())
16036 else if (attr
->form_is_section_offset ())
16038 dwarf2_complex_location_expr_complaint ();
16043 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16044 "common block member");
16049 if (die
->child
!= NULL
)
16051 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16052 struct die_info
*child_die
;
16053 size_t n_entries
= 0, size
;
16054 struct common_block
*common_block
;
16055 struct symbol
*sym
;
16057 for (child_die
= die
->child
;
16058 child_die
&& child_die
->tag
;
16059 child_die
= sibling_die (child_die
))
16062 size
= (sizeof (struct common_block
)
16063 + (n_entries
- 1) * sizeof (struct symbol
*));
16065 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16067 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16068 common_block
->n_entries
= 0;
16070 for (child_die
= die
->child
;
16071 child_die
&& child_die
->tag
;
16072 child_die
= sibling_die (child_die
))
16074 /* Create the symbol in the DW_TAG_common_block block in the current
16076 sym
= new_symbol (child_die
, NULL
, cu
);
16079 struct attribute
*member_loc
;
16081 common_block
->contents
[common_block
->n_entries
++] = sym
;
16083 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16087 /* GDB has handled this for a long time, but it is
16088 not specified by DWARF. It seems to have been
16089 emitted by gfortran at least as recently as:
16090 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16091 complaint (_("Variable in common block has "
16092 "DW_AT_data_member_location "
16093 "- DIE at %s [in module %s]"),
16094 sect_offset_str (child_die
->sect_off
),
16095 objfile_name (objfile
));
16097 if (member_loc
->form_is_section_offset ())
16098 dwarf2_complex_location_expr_complaint ();
16099 else if (member_loc
->form_is_constant ()
16100 || member_loc
->form_is_block ())
16102 if (attr
!= nullptr)
16103 mark_common_block_symbol_computed (sym
, die
, attr
,
16107 dwarf2_complex_location_expr_complaint ();
16112 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16113 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16117 /* Create a type for a C++ namespace. */
16119 static struct type
*
16120 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16122 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16123 const char *previous_prefix
, *name
;
16127 /* For extensions, reuse the type of the original namespace. */
16128 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16130 struct die_info
*ext_die
;
16131 struct dwarf2_cu
*ext_cu
= cu
;
16133 ext_die
= dwarf2_extension (die
, &ext_cu
);
16134 type
= read_type_die (ext_die
, ext_cu
);
16136 /* EXT_CU may not be the same as CU.
16137 Ensure TYPE is recorded with CU in die_type_hash. */
16138 return set_die_type (die
, type
, cu
);
16141 name
= namespace_name (die
, &is_anonymous
, cu
);
16143 /* Now build the name of the current namespace. */
16145 previous_prefix
= determine_prefix (die
, cu
);
16146 if (previous_prefix
[0] != '\0')
16147 name
= typename_concat (&objfile
->objfile_obstack
,
16148 previous_prefix
, name
, 0, cu
);
16150 /* Create the type. */
16151 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16153 return set_die_type (die
, type
, cu
);
16156 /* Read a namespace scope. */
16159 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16161 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16164 /* Add a symbol associated to this if we haven't seen the namespace
16165 before. Also, add a using directive if it's an anonymous
16168 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16172 type
= read_type_die (die
, cu
);
16173 new_symbol (die
, type
, cu
);
16175 namespace_name (die
, &is_anonymous
, cu
);
16178 const char *previous_prefix
= determine_prefix (die
, cu
);
16180 std::vector
<const char *> excludes
;
16181 add_using_directive (using_directives (cu
),
16182 previous_prefix
, TYPE_NAME (type
), NULL
,
16183 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16187 if (die
->child
!= NULL
)
16189 struct die_info
*child_die
= die
->child
;
16191 while (child_die
&& child_die
->tag
)
16193 process_die (child_die
, cu
);
16194 child_die
= sibling_die (child_die
);
16199 /* Read a Fortran module as type. This DIE can be only a declaration used for
16200 imported module. Still we need that type as local Fortran "use ... only"
16201 declaration imports depend on the created type in determine_prefix. */
16203 static struct type
*
16204 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16206 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16207 const char *module_name
;
16210 module_name
= dwarf2_name (die
, cu
);
16211 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16213 return set_die_type (die
, type
, cu
);
16216 /* Read a Fortran module. */
16219 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16221 struct die_info
*child_die
= die
->child
;
16224 type
= read_type_die (die
, cu
);
16225 new_symbol (die
, type
, cu
);
16227 while (child_die
&& child_die
->tag
)
16229 process_die (child_die
, cu
);
16230 child_die
= sibling_die (child_die
);
16234 /* Return the name of the namespace represented by DIE. Set
16235 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16238 static const char *
16239 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16241 struct die_info
*current_die
;
16242 const char *name
= NULL
;
16244 /* Loop through the extensions until we find a name. */
16246 for (current_die
= die
;
16247 current_die
!= NULL
;
16248 current_die
= dwarf2_extension (die
, &cu
))
16250 /* We don't use dwarf2_name here so that we can detect the absence
16251 of a name -> anonymous namespace. */
16252 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16258 /* Is it an anonymous namespace? */
16260 *is_anonymous
= (name
== NULL
);
16262 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16267 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16268 the user defined type vector. */
16270 static struct type
*
16271 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16273 struct gdbarch
*gdbarch
16274 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16275 struct comp_unit_head
*cu_header
= &cu
->header
;
16277 struct attribute
*attr_byte_size
;
16278 struct attribute
*attr_address_class
;
16279 int byte_size
, addr_class
;
16280 struct type
*target_type
;
16282 target_type
= die_type (die
, cu
);
16284 /* The die_type call above may have already set the type for this DIE. */
16285 type
= get_die_type (die
, cu
);
16289 type
= lookup_pointer_type (target_type
);
16291 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16292 if (attr_byte_size
)
16293 byte_size
= DW_UNSND (attr_byte_size
);
16295 byte_size
= cu_header
->addr_size
;
16297 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16298 if (attr_address_class
)
16299 addr_class
= DW_UNSND (attr_address_class
);
16301 addr_class
= DW_ADDR_none
;
16303 ULONGEST alignment
= get_alignment (cu
, die
);
16305 /* If the pointer size, alignment, or address class is different
16306 than the default, create a type variant marked as such and set
16307 the length accordingly. */
16308 if (TYPE_LENGTH (type
) != byte_size
16309 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16310 && alignment
!= TYPE_RAW_ALIGN (type
))
16311 || addr_class
!= DW_ADDR_none
)
16313 if (gdbarch_address_class_type_flags_p (gdbarch
))
16317 type_flags
= gdbarch_address_class_type_flags
16318 (gdbarch
, byte_size
, addr_class
);
16319 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16321 type
= make_type_with_address_space (type
, type_flags
);
16323 else if (TYPE_LENGTH (type
) != byte_size
)
16325 complaint (_("invalid pointer size %d"), byte_size
);
16327 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16329 complaint (_("Invalid DW_AT_alignment"
16330 " - DIE at %s [in module %s]"),
16331 sect_offset_str (die
->sect_off
),
16332 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16336 /* Should we also complain about unhandled address classes? */
16340 TYPE_LENGTH (type
) = byte_size
;
16341 set_type_align (type
, alignment
);
16342 return set_die_type (die
, type
, cu
);
16345 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16346 the user defined type vector. */
16348 static struct type
*
16349 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16352 struct type
*to_type
;
16353 struct type
*domain
;
16355 to_type
= die_type (die
, cu
);
16356 domain
= die_containing_type (die
, cu
);
16358 /* The calls above may have already set the type for this DIE. */
16359 type
= get_die_type (die
, cu
);
16363 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16364 type
= lookup_methodptr_type (to_type
);
16365 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16367 struct type
*new_type
16368 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16370 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16371 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16372 TYPE_VARARGS (to_type
));
16373 type
= lookup_methodptr_type (new_type
);
16376 type
= lookup_memberptr_type (to_type
, domain
);
16378 return set_die_type (die
, type
, cu
);
16381 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16382 the user defined type vector. */
16384 static struct type
*
16385 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16386 enum type_code refcode
)
16388 struct comp_unit_head
*cu_header
= &cu
->header
;
16389 struct type
*type
, *target_type
;
16390 struct attribute
*attr
;
16392 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16394 target_type
= die_type (die
, cu
);
16396 /* The die_type call above may have already set the type for this DIE. */
16397 type
= get_die_type (die
, cu
);
16401 type
= lookup_reference_type (target_type
, refcode
);
16402 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16403 if (attr
!= nullptr)
16405 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16409 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16411 maybe_set_alignment (cu
, die
, type
);
16412 return set_die_type (die
, type
, cu
);
16415 /* Add the given cv-qualifiers to the element type of the array. GCC
16416 outputs DWARF type qualifiers that apply to an array, not the
16417 element type. But GDB relies on the array element type to carry
16418 the cv-qualifiers. This mimics section 6.7.3 of the C99
16421 static struct type
*
16422 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16423 struct type
*base_type
, int cnst
, int voltl
)
16425 struct type
*el_type
, *inner_array
;
16427 base_type
= copy_type (base_type
);
16428 inner_array
= base_type
;
16430 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16432 TYPE_TARGET_TYPE (inner_array
) =
16433 copy_type (TYPE_TARGET_TYPE (inner_array
));
16434 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16437 el_type
= TYPE_TARGET_TYPE (inner_array
);
16438 cnst
|= TYPE_CONST (el_type
);
16439 voltl
|= TYPE_VOLATILE (el_type
);
16440 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16442 return set_die_type (die
, base_type
, cu
);
16445 static struct type
*
16446 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16448 struct type
*base_type
, *cv_type
;
16450 base_type
= die_type (die
, cu
);
16452 /* The die_type call above may have already set the type for this DIE. */
16453 cv_type
= get_die_type (die
, cu
);
16457 /* In case the const qualifier is applied to an array type, the element type
16458 is so qualified, not the array type (section 6.7.3 of C99). */
16459 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16460 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16462 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16463 return set_die_type (die
, cv_type
, cu
);
16466 static struct type
*
16467 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16469 struct type
*base_type
, *cv_type
;
16471 base_type
= die_type (die
, cu
);
16473 /* The die_type call above may have already set the type for this DIE. */
16474 cv_type
= get_die_type (die
, cu
);
16478 /* In case the volatile qualifier is applied to an array type, the
16479 element type is so qualified, not the array type (section 6.7.3
16481 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16482 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16484 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16485 return set_die_type (die
, cv_type
, cu
);
16488 /* Handle DW_TAG_restrict_type. */
16490 static struct type
*
16491 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16493 struct type
*base_type
, *cv_type
;
16495 base_type
= die_type (die
, cu
);
16497 /* The die_type call above may have already set the type for this DIE. */
16498 cv_type
= get_die_type (die
, cu
);
16502 cv_type
= make_restrict_type (base_type
);
16503 return set_die_type (die
, cv_type
, cu
);
16506 /* Handle DW_TAG_atomic_type. */
16508 static struct type
*
16509 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16511 struct type
*base_type
, *cv_type
;
16513 base_type
= die_type (die
, cu
);
16515 /* The die_type call above may have already set the type for this DIE. */
16516 cv_type
= get_die_type (die
, cu
);
16520 cv_type
= make_atomic_type (base_type
);
16521 return set_die_type (die
, cv_type
, cu
);
16524 /* Extract all information from a DW_TAG_string_type DIE and add to
16525 the user defined type vector. It isn't really a user defined type,
16526 but it behaves like one, with other DIE's using an AT_user_def_type
16527 attribute to reference it. */
16529 static struct type
*
16530 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16532 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16533 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16534 struct type
*type
, *range_type
, *index_type
, *char_type
;
16535 struct attribute
*attr
;
16536 struct dynamic_prop prop
;
16537 bool length_is_constant
= true;
16540 /* There are a couple of places where bit sizes might be made use of
16541 when parsing a DW_TAG_string_type, however, no producer that we know
16542 of make use of these. Handling bit sizes that are a multiple of the
16543 byte size is easy enough, but what about other bit sizes? Lets deal
16544 with that problem when we have to. Warn about these attributes being
16545 unsupported, then parse the type and ignore them like we always
16547 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16548 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16550 static bool warning_printed
= false;
16551 if (!warning_printed
)
16553 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16554 "currently supported on DW_TAG_string_type."));
16555 warning_printed
= true;
16559 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16560 if (attr
!= nullptr && !attr
->form_is_constant ())
16562 /* The string length describes the location at which the length of
16563 the string can be found. The size of the length field can be
16564 specified with one of the attributes below. */
16565 struct type
*prop_type
;
16566 struct attribute
*len
16567 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16568 if (len
== nullptr)
16569 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16570 if (len
!= nullptr && len
->form_is_constant ())
16572 /* Pass 0 as the default as we know this attribute is constant
16573 and the default value will not be returned. */
16574 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16575 prop_type
= cu
->per_cu
->int_type (sz
, true);
16579 /* If the size is not specified then we assume it is the size of
16580 an address on this target. */
16581 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16584 /* Convert the attribute into a dynamic property. */
16585 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16588 length_is_constant
= false;
16590 else if (attr
!= nullptr)
16592 /* This DW_AT_string_length just contains the length with no
16593 indirection. There's no need to create a dynamic property in this
16594 case. Pass 0 for the default value as we know it will not be
16595 returned in this case. */
16596 length
= dwarf2_get_attr_constant_value (attr
, 0);
16598 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16600 /* We don't currently support non-constant byte sizes for strings. */
16601 length
= dwarf2_get_attr_constant_value (attr
, 1);
16605 /* Use 1 as a fallback length if we have nothing else. */
16609 index_type
= objfile_type (objfile
)->builtin_int
;
16610 if (length_is_constant
)
16611 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16614 struct dynamic_prop low_bound
;
16616 low_bound
.kind
= PROP_CONST
;
16617 low_bound
.data
.const_val
= 1;
16618 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16620 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16621 type
= create_string_type (NULL
, char_type
, range_type
);
16623 return set_die_type (die
, type
, cu
);
16626 /* Assuming that DIE corresponds to a function, returns nonzero
16627 if the function is prototyped. */
16630 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16632 struct attribute
*attr
;
16634 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16635 if (attr
&& (DW_UNSND (attr
) != 0))
16638 /* The DWARF standard implies that the DW_AT_prototyped attribute
16639 is only meaningful for C, but the concept also extends to other
16640 languages that allow unprototyped functions (Eg: Objective C).
16641 For all other languages, assume that functions are always
16643 if (cu
->language
!= language_c
16644 && cu
->language
!= language_objc
16645 && cu
->language
!= language_opencl
)
16648 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16649 prototyped and unprototyped functions; default to prototyped,
16650 since that is more common in modern code (and RealView warns
16651 about unprototyped functions). */
16652 if (producer_is_realview (cu
->producer
))
16658 /* Handle DIES due to C code like:
16662 int (*funcp)(int a, long l);
16666 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16668 static struct type
*
16669 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16671 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16672 struct type
*type
; /* Type that this function returns. */
16673 struct type
*ftype
; /* Function that returns above type. */
16674 struct attribute
*attr
;
16676 type
= die_type (die
, cu
);
16678 /* The die_type call above may have already set the type for this DIE. */
16679 ftype
= get_die_type (die
, cu
);
16683 ftype
= lookup_function_type (type
);
16685 if (prototyped_function_p (die
, cu
))
16686 TYPE_PROTOTYPED (ftype
) = 1;
16688 /* Store the calling convention in the type if it's available in
16689 the subroutine die. Otherwise set the calling convention to
16690 the default value DW_CC_normal. */
16691 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16692 if (attr
!= nullptr
16693 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16694 TYPE_CALLING_CONVENTION (ftype
)
16695 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16696 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16697 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16699 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16701 /* Record whether the function returns normally to its caller or not
16702 if the DWARF producer set that information. */
16703 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16704 if (attr
&& (DW_UNSND (attr
) != 0))
16705 TYPE_NO_RETURN (ftype
) = 1;
16707 /* We need to add the subroutine type to the die immediately so
16708 we don't infinitely recurse when dealing with parameters
16709 declared as the same subroutine type. */
16710 set_die_type (die
, ftype
, cu
);
16712 if (die
->child
!= NULL
)
16714 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16715 struct die_info
*child_die
;
16716 int nparams
, iparams
;
16718 /* Count the number of parameters.
16719 FIXME: GDB currently ignores vararg functions, but knows about
16720 vararg member functions. */
16722 child_die
= die
->child
;
16723 while (child_die
&& child_die
->tag
)
16725 if (child_die
->tag
== DW_TAG_formal_parameter
)
16727 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16728 TYPE_VARARGS (ftype
) = 1;
16729 child_die
= sibling_die (child_die
);
16732 /* Allocate storage for parameters and fill them in. */
16733 TYPE_NFIELDS (ftype
) = nparams
;
16734 TYPE_FIELDS (ftype
) = (struct field
*)
16735 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16737 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16738 even if we error out during the parameters reading below. */
16739 for (iparams
= 0; iparams
< nparams
; iparams
++)
16740 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16743 child_die
= die
->child
;
16744 while (child_die
&& child_die
->tag
)
16746 if (child_die
->tag
== DW_TAG_formal_parameter
)
16748 struct type
*arg_type
;
16750 /* DWARF version 2 has no clean way to discern C++
16751 static and non-static member functions. G++ helps
16752 GDB by marking the first parameter for non-static
16753 member functions (which is the this pointer) as
16754 artificial. We pass this information to
16755 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16757 DWARF version 3 added DW_AT_object_pointer, which GCC
16758 4.5 does not yet generate. */
16759 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16760 if (attr
!= nullptr)
16761 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16763 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16764 arg_type
= die_type (child_die
, cu
);
16766 /* RealView does not mark THIS as const, which the testsuite
16767 expects. GCC marks THIS as const in method definitions,
16768 but not in the class specifications (GCC PR 43053). */
16769 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16770 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16773 struct dwarf2_cu
*arg_cu
= cu
;
16774 const char *name
= dwarf2_name (child_die
, cu
);
16776 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16777 if (attr
!= nullptr)
16779 /* If the compiler emits this, use it. */
16780 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16783 else if (name
&& strcmp (name
, "this") == 0)
16784 /* Function definitions will have the argument names. */
16786 else if (name
== NULL
&& iparams
== 0)
16787 /* Declarations may not have the names, so like
16788 elsewhere in GDB, assume an artificial first
16789 argument is "this". */
16793 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16797 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16800 child_die
= sibling_die (child_die
);
16807 static struct type
*
16808 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16810 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16811 const char *name
= NULL
;
16812 struct type
*this_type
, *target_type
;
16814 name
= dwarf2_full_name (NULL
, die
, cu
);
16815 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16816 TYPE_TARGET_STUB (this_type
) = 1;
16817 set_die_type (die
, this_type
, cu
);
16818 target_type
= die_type (die
, cu
);
16819 if (target_type
!= this_type
)
16820 TYPE_TARGET_TYPE (this_type
) = target_type
;
16823 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16824 spec and cause infinite loops in GDB. */
16825 complaint (_("Self-referential DW_TAG_typedef "
16826 "- DIE at %s [in module %s]"),
16827 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16828 TYPE_TARGET_TYPE (this_type
) = NULL
;
16832 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16833 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16834 Handle these by just returning the target type, rather than
16835 constructing an anonymous typedef type and trying to handle this
16837 set_die_type (die
, target_type
, cu
);
16838 return target_type
;
16843 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16844 (which may be different from NAME) to the architecture back-end to allow
16845 it to guess the correct format if necessary. */
16847 static struct type
*
16848 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16849 const char *name_hint
, enum bfd_endian byte_order
)
16851 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16852 const struct floatformat
**format
;
16855 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16857 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16859 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16864 /* Allocate an integer type of size BITS and name NAME. */
16866 static struct type
*
16867 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16868 int bits
, int unsigned_p
, const char *name
)
16872 /* Versions of Intel's C Compiler generate an integer type called "void"
16873 instead of using DW_TAG_unspecified_type. This has been seen on
16874 at least versions 14, 17, and 18. */
16875 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16876 && strcmp (name
, "void") == 0)
16877 type
= objfile_type (objfile
)->builtin_void
;
16879 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16884 /* Initialise and return a floating point type of size BITS suitable for
16885 use as a component of a complex number. The NAME_HINT is passed through
16886 when initialising the floating point type and is the name of the complex
16889 As DWARF doesn't currently provide an explicit name for the components
16890 of a complex number, but it can be helpful to have these components
16891 named, we try to select a suitable name based on the size of the
16893 static struct type
*
16894 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16895 struct objfile
*objfile
,
16896 int bits
, const char *name_hint
,
16897 enum bfd_endian byte_order
)
16899 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16900 struct type
*tt
= nullptr;
16902 /* Try to find a suitable floating point builtin type of size BITS.
16903 We're going to use the name of this type as the name for the complex
16904 target type that we are about to create. */
16905 switch (cu
->language
)
16907 case language_fortran
:
16911 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16914 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16916 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16918 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16926 tt
= builtin_type (gdbarch
)->builtin_float
;
16929 tt
= builtin_type (gdbarch
)->builtin_double
;
16931 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16933 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16939 /* If the type we found doesn't match the size we were looking for, then
16940 pretend we didn't find a type at all, the complex target type we
16941 create will then be nameless. */
16942 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16945 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16946 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16949 /* Find a representation of a given base type and install
16950 it in the TYPE field of the die. */
16952 static struct type
*
16953 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16955 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16957 struct attribute
*attr
;
16958 int encoding
= 0, bits
= 0;
16962 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16963 if (attr
!= nullptr)
16964 encoding
= DW_UNSND (attr
);
16965 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16966 if (attr
!= nullptr)
16967 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16968 name
= dwarf2_name (die
, cu
);
16970 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16972 arch
= get_objfile_arch (objfile
);
16973 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16975 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16978 int endianity
= DW_UNSND (attr
);
16983 byte_order
= BFD_ENDIAN_BIG
;
16985 case DW_END_little
:
16986 byte_order
= BFD_ENDIAN_LITTLE
;
16989 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16996 case DW_ATE_address
:
16997 /* Turn DW_ATE_address into a void * pointer. */
16998 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16999 type
= init_pointer_type (objfile
, bits
, name
, type
);
17001 case DW_ATE_boolean
:
17002 type
= init_boolean_type (objfile
, bits
, 1, name
);
17004 case DW_ATE_complex_float
:
17005 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17007 type
= init_complex_type (objfile
, name
, type
);
17009 case DW_ATE_decimal_float
:
17010 type
= init_decfloat_type (objfile
, bits
, name
);
17013 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17015 case DW_ATE_signed
:
17016 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17018 case DW_ATE_unsigned
:
17019 if (cu
->language
== language_fortran
17021 && startswith (name
, "character("))
17022 type
= init_character_type (objfile
, bits
, 1, name
);
17024 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17026 case DW_ATE_signed_char
:
17027 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17028 || cu
->language
== language_pascal
17029 || cu
->language
== language_fortran
)
17030 type
= init_character_type (objfile
, bits
, 0, name
);
17032 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17034 case DW_ATE_unsigned_char
:
17035 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17036 || cu
->language
== language_pascal
17037 || cu
->language
== language_fortran
17038 || cu
->language
== language_rust
)
17039 type
= init_character_type (objfile
, bits
, 1, name
);
17041 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17046 type
= builtin_type (arch
)->builtin_char16
;
17047 else if (bits
== 32)
17048 type
= builtin_type (arch
)->builtin_char32
;
17051 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17053 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17055 return set_die_type (die
, type
, cu
);
17060 complaint (_("unsupported DW_AT_encoding: '%s'"),
17061 dwarf_type_encoding_name (encoding
));
17062 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17066 if (name
&& strcmp (name
, "char") == 0)
17067 TYPE_NOSIGN (type
) = 1;
17069 maybe_set_alignment (cu
, die
, type
);
17071 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17073 return set_die_type (die
, type
, cu
);
17076 /* Parse dwarf attribute if it's a block, reference or constant and put the
17077 resulting value of the attribute into struct bound_prop.
17078 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17081 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17082 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17083 struct type
*default_type
)
17085 struct dwarf2_property_baton
*baton
;
17086 struct obstack
*obstack
17087 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17089 gdb_assert (default_type
!= NULL
);
17091 if (attr
== NULL
|| prop
== NULL
)
17094 if (attr
->form_is_block ())
17096 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17097 baton
->property_type
= default_type
;
17098 baton
->locexpr
.per_cu
= cu
->per_cu
;
17099 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17100 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17101 switch (attr
->name
)
17103 case DW_AT_string_length
:
17104 baton
->locexpr
.is_reference
= true;
17107 baton
->locexpr
.is_reference
= false;
17110 prop
->data
.baton
= baton
;
17111 prop
->kind
= PROP_LOCEXPR
;
17112 gdb_assert (prop
->data
.baton
!= NULL
);
17114 else if (attr
->form_is_ref ())
17116 struct dwarf2_cu
*target_cu
= cu
;
17117 struct die_info
*target_die
;
17118 struct attribute
*target_attr
;
17120 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17121 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17122 if (target_attr
== NULL
)
17123 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17125 if (target_attr
== NULL
)
17128 switch (target_attr
->name
)
17130 case DW_AT_location
:
17131 if (target_attr
->form_is_section_offset ())
17133 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17134 baton
->property_type
= die_type (target_die
, target_cu
);
17135 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17136 prop
->data
.baton
= baton
;
17137 prop
->kind
= PROP_LOCLIST
;
17138 gdb_assert (prop
->data
.baton
!= NULL
);
17140 else if (target_attr
->form_is_block ())
17142 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17143 baton
->property_type
= die_type (target_die
, target_cu
);
17144 baton
->locexpr
.per_cu
= cu
->per_cu
;
17145 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17146 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17147 baton
->locexpr
.is_reference
= true;
17148 prop
->data
.baton
= baton
;
17149 prop
->kind
= PROP_LOCEXPR
;
17150 gdb_assert (prop
->data
.baton
!= NULL
);
17154 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17155 "dynamic property");
17159 case DW_AT_data_member_location
:
17163 if (!handle_data_member_location (target_die
, target_cu
,
17167 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17168 baton
->property_type
= read_type_die (target_die
->parent
,
17170 baton
->offset_info
.offset
= offset
;
17171 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17172 prop
->data
.baton
= baton
;
17173 prop
->kind
= PROP_ADDR_OFFSET
;
17178 else if (attr
->form_is_constant ())
17180 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17181 prop
->kind
= PROP_CONST
;
17185 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17186 dwarf2_name (die
, cu
));
17196 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17198 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17199 struct type
*int_type
;
17201 /* Helper macro to examine the various builtin types. */
17202 #define TRY_TYPE(F) \
17203 int_type = (unsigned_p \
17204 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17205 : objfile_type (objfile)->builtin_ ## F); \
17206 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17213 TRY_TYPE (long_long
);
17217 gdb_assert_not_reached ("unable to find suitable integer type");
17223 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17225 int addr_size
= this->addr_size ();
17226 return int_type (addr_size
, unsigned_p
);
17229 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17230 present (which is valid) then compute the default type based on the
17231 compilation units address size. */
17233 static struct type
*
17234 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17236 struct type
*index_type
= die_type (die
, cu
);
17238 /* Dwarf-2 specifications explicitly allows to create subrange types
17239 without specifying a base type.
17240 In that case, the base type must be set to the type of
17241 the lower bound, upper bound or count, in that order, if any of these
17242 three attributes references an object that has a type.
17243 If no base type is found, the Dwarf-2 specifications say that
17244 a signed integer type of size equal to the size of an address should
17246 For the following C code: `extern char gdb_int [];'
17247 GCC produces an empty range DIE.
17248 FIXME: muller/2010-05-28: Possible references to object for low bound,
17249 high bound or count are not yet handled by this code. */
17250 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17251 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17256 /* Read the given DW_AT_subrange DIE. */
17258 static struct type
*
17259 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17261 struct type
*base_type
, *orig_base_type
;
17262 struct type
*range_type
;
17263 struct attribute
*attr
;
17264 struct dynamic_prop low
, high
;
17265 int low_default_is_valid
;
17266 int high_bound_is_count
= 0;
17268 ULONGEST negative_mask
;
17270 orig_base_type
= read_subrange_index_type (die
, cu
);
17272 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17273 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17274 creating the range type, but we use the result of check_typedef
17275 when examining properties of the type. */
17276 base_type
= check_typedef (orig_base_type
);
17278 /* The die_type call above may have already set the type for this DIE. */
17279 range_type
= get_die_type (die
, cu
);
17283 low
.kind
= PROP_CONST
;
17284 high
.kind
= PROP_CONST
;
17285 high
.data
.const_val
= 0;
17287 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17288 omitting DW_AT_lower_bound. */
17289 switch (cu
->language
)
17292 case language_cplus
:
17293 low
.data
.const_val
= 0;
17294 low_default_is_valid
= 1;
17296 case language_fortran
:
17297 low
.data
.const_val
= 1;
17298 low_default_is_valid
= 1;
17301 case language_objc
:
17302 case language_rust
:
17303 low
.data
.const_val
= 0;
17304 low_default_is_valid
= (cu
->header
.version
>= 4);
17308 case language_pascal
:
17309 low
.data
.const_val
= 1;
17310 low_default_is_valid
= (cu
->header
.version
>= 4);
17313 low
.data
.const_val
= 0;
17314 low_default_is_valid
= 0;
17318 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17319 if (attr
!= nullptr)
17320 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17321 else if (!low_default_is_valid
)
17322 complaint (_("Missing DW_AT_lower_bound "
17323 "- DIE at %s [in module %s]"),
17324 sect_offset_str (die
->sect_off
),
17325 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17327 struct attribute
*attr_ub
, *attr_count
;
17328 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17329 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17331 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17332 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17334 /* If bounds are constant do the final calculation here. */
17335 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17336 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17338 high_bound_is_count
= 1;
17342 if (attr_ub
!= NULL
)
17343 complaint (_("Unresolved DW_AT_upper_bound "
17344 "- DIE at %s [in module %s]"),
17345 sect_offset_str (die
->sect_off
),
17346 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17347 if (attr_count
!= NULL
)
17348 complaint (_("Unresolved DW_AT_count "
17349 "- DIE at %s [in module %s]"),
17350 sect_offset_str (die
->sect_off
),
17351 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17356 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17357 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17358 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17360 /* Normally, the DWARF producers are expected to use a signed
17361 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17362 But this is unfortunately not always the case, as witnessed
17363 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17364 is used instead. To work around that ambiguity, we treat
17365 the bounds as signed, and thus sign-extend their values, when
17366 the base type is signed. */
17368 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17369 if (low
.kind
== PROP_CONST
17370 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17371 low
.data
.const_val
|= negative_mask
;
17372 if (high
.kind
== PROP_CONST
17373 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17374 high
.data
.const_val
|= negative_mask
;
17376 /* Check for bit and byte strides. */
17377 struct dynamic_prop byte_stride_prop
;
17378 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17379 if (attr_byte_stride
!= nullptr)
17381 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17382 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17386 struct dynamic_prop bit_stride_prop
;
17387 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17388 if (attr_bit_stride
!= nullptr)
17390 /* It only makes sense to have either a bit or byte stride. */
17391 if (attr_byte_stride
!= nullptr)
17393 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17394 "- DIE at %s [in module %s]"),
17395 sect_offset_str (die
->sect_off
),
17396 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17397 attr_bit_stride
= nullptr;
17401 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17402 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17407 if (attr_byte_stride
!= nullptr
17408 || attr_bit_stride
!= nullptr)
17410 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17411 struct dynamic_prop
*stride
17412 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17415 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17416 &high
, bias
, stride
, byte_stride_p
);
17419 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17421 if (high_bound_is_count
)
17422 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17424 /* Ada expects an empty array on no boundary attributes. */
17425 if (attr
== NULL
&& cu
->language
!= language_ada
)
17426 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17428 name
= dwarf2_name (die
, cu
);
17430 TYPE_NAME (range_type
) = name
;
17432 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17433 if (attr
!= nullptr)
17434 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17436 maybe_set_alignment (cu
, die
, range_type
);
17438 set_die_type (die
, range_type
, cu
);
17440 /* set_die_type should be already done. */
17441 set_descriptive_type (range_type
, die
, cu
);
17446 static struct type
*
17447 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17451 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17453 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17455 /* In Ada, an unspecified type is typically used when the description
17456 of the type is deferred to a different unit. When encountering
17457 such a type, we treat it as a stub, and try to resolve it later on,
17459 if (cu
->language
== language_ada
)
17460 TYPE_STUB (type
) = 1;
17462 return set_die_type (die
, type
, cu
);
17465 /* Read a single die and all its descendents. Set the die's sibling
17466 field to NULL; set other fields in the die correctly, and set all
17467 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17468 location of the info_ptr after reading all of those dies. PARENT
17469 is the parent of the die in question. */
17471 static struct die_info
*
17472 read_die_and_children (const struct die_reader_specs
*reader
,
17473 const gdb_byte
*info_ptr
,
17474 const gdb_byte
**new_info_ptr
,
17475 struct die_info
*parent
)
17477 struct die_info
*die
;
17478 const gdb_byte
*cur_ptr
;
17480 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17483 *new_info_ptr
= cur_ptr
;
17486 store_in_ref_table (die
, reader
->cu
);
17488 if (die
->has_children
)
17489 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17493 *new_info_ptr
= cur_ptr
;
17496 die
->sibling
= NULL
;
17497 die
->parent
= parent
;
17501 /* Read a die, all of its descendents, and all of its siblings; set
17502 all of the fields of all of the dies correctly. Arguments are as
17503 in read_die_and_children. */
17505 static struct die_info
*
17506 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17507 const gdb_byte
*info_ptr
,
17508 const gdb_byte
**new_info_ptr
,
17509 struct die_info
*parent
)
17511 struct die_info
*first_die
, *last_sibling
;
17512 const gdb_byte
*cur_ptr
;
17514 cur_ptr
= info_ptr
;
17515 first_die
= last_sibling
= NULL
;
17519 struct die_info
*die
17520 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17524 *new_info_ptr
= cur_ptr
;
17531 last_sibling
->sibling
= die
;
17533 last_sibling
= die
;
17537 /* Read a die, all of its descendents, and all of its siblings; set
17538 all of the fields of all of the dies correctly. Arguments are as
17539 in read_die_and_children.
17540 This the main entry point for reading a DIE and all its children. */
17542 static struct die_info
*
17543 read_die_and_siblings (const struct die_reader_specs
*reader
,
17544 const gdb_byte
*info_ptr
,
17545 const gdb_byte
**new_info_ptr
,
17546 struct die_info
*parent
)
17548 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17549 new_info_ptr
, parent
);
17551 if (dwarf_die_debug
)
17553 fprintf_unfiltered (gdb_stdlog
,
17554 "Read die from %s@0x%x of %s:\n",
17555 reader
->die_section
->get_name (),
17556 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17557 bfd_get_filename (reader
->abfd
));
17558 dump_die (die
, dwarf_die_debug
);
17564 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17566 The caller is responsible for filling in the extra attributes
17567 and updating (*DIEP)->num_attrs.
17568 Set DIEP to point to a newly allocated die with its information,
17569 except for its child, sibling, and parent fields. */
17571 static const gdb_byte
*
17572 read_full_die_1 (const struct die_reader_specs
*reader
,
17573 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17574 int num_extra_attrs
)
17576 unsigned int abbrev_number
, bytes_read
, i
;
17577 struct abbrev_info
*abbrev
;
17578 struct die_info
*die
;
17579 struct dwarf2_cu
*cu
= reader
->cu
;
17580 bfd
*abfd
= reader
->abfd
;
17582 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17583 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17584 info_ptr
+= bytes_read
;
17585 if (!abbrev_number
)
17591 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17593 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17595 bfd_get_filename (abfd
));
17597 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17598 die
->sect_off
= sect_off
;
17599 die
->tag
= abbrev
->tag
;
17600 die
->abbrev
= abbrev_number
;
17601 die
->has_children
= abbrev
->has_children
;
17603 /* Make the result usable.
17604 The caller needs to update num_attrs after adding the extra
17606 die
->num_attrs
= abbrev
->num_attrs
;
17608 std::vector
<int> indexes_that_need_reprocess
;
17609 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17611 bool need_reprocess
;
17613 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17614 info_ptr
, &need_reprocess
);
17615 if (need_reprocess
)
17616 indexes_that_need_reprocess
.push_back (i
);
17619 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17620 if (attr
!= nullptr)
17621 cu
->str_offsets_base
= DW_UNSND (attr
);
17623 auto maybe_addr_base
= lookup_addr_base(die
);
17624 if (maybe_addr_base
.has_value ())
17625 cu
->addr_base
= *maybe_addr_base
;
17626 for (int index
: indexes_that_need_reprocess
)
17627 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17632 /* Read a die and all its attributes.
17633 Set DIEP to point to a newly allocated die with its information,
17634 except for its child, sibling, and parent fields. */
17636 static const gdb_byte
*
17637 read_full_die (const struct die_reader_specs
*reader
,
17638 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17640 const gdb_byte
*result
;
17642 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17644 if (dwarf_die_debug
)
17646 fprintf_unfiltered (gdb_stdlog
,
17647 "Read die from %s@0x%x of %s:\n",
17648 reader
->die_section
->get_name (),
17649 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17650 bfd_get_filename (reader
->abfd
));
17651 dump_die (*diep
, dwarf_die_debug
);
17658 /* Returns nonzero if TAG represents a type that we might generate a partial
17662 is_type_tag_for_partial (int tag
)
17667 /* Some types that would be reasonable to generate partial symbols for,
17668 that we don't at present. */
17669 case DW_TAG_array_type
:
17670 case DW_TAG_file_type
:
17671 case DW_TAG_ptr_to_member_type
:
17672 case DW_TAG_set_type
:
17673 case DW_TAG_string_type
:
17674 case DW_TAG_subroutine_type
:
17676 case DW_TAG_base_type
:
17677 case DW_TAG_class_type
:
17678 case DW_TAG_interface_type
:
17679 case DW_TAG_enumeration_type
:
17680 case DW_TAG_structure_type
:
17681 case DW_TAG_subrange_type
:
17682 case DW_TAG_typedef
:
17683 case DW_TAG_union_type
:
17690 /* Load all DIEs that are interesting for partial symbols into memory. */
17692 static struct partial_die_info
*
17693 load_partial_dies (const struct die_reader_specs
*reader
,
17694 const gdb_byte
*info_ptr
, int building_psymtab
)
17696 struct dwarf2_cu
*cu
= reader
->cu
;
17697 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17698 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17699 unsigned int bytes_read
;
17700 unsigned int load_all
= 0;
17701 int nesting_level
= 1;
17706 gdb_assert (cu
->per_cu
!= NULL
);
17707 if (cu
->per_cu
->load_all_dies
)
17711 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17715 &cu
->comp_unit_obstack
,
17716 hashtab_obstack_allocate
,
17717 dummy_obstack_deallocate
);
17721 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17723 /* A NULL abbrev means the end of a series of children. */
17724 if (abbrev
== NULL
)
17726 if (--nesting_level
== 0)
17729 info_ptr
+= bytes_read
;
17730 last_die
= parent_die
;
17731 parent_die
= parent_die
->die_parent
;
17735 /* Check for template arguments. We never save these; if
17736 they're seen, we just mark the parent, and go on our way. */
17737 if (parent_die
!= NULL
17738 && cu
->language
== language_cplus
17739 && (abbrev
->tag
== DW_TAG_template_type_param
17740 || abbrev
->tag
== DW_TAG_template_value_param
))
17742 parent_die
->has_template_arguments
= 1;
17746 /* We don't need a partial DIE for the template argument. */
17747 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17752 /* We only recurse into c++ subprograms looking for template arguments.
17753 Skip their other children. */
17755 && cu
->language
== language_cplus
17756 && parent_die
!= NULL
17757 && parent_die
->tag
== DW_TAG_subprogram
)
17759 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17763 /* Check whether this DIE is interesting enough to save. Normally
17764 we would not be interested in members here, but there may be
17765 later variables referencing them via DW_AT_specification (for
17766 static members). */
17768 && !is_type_tag_for_partial (abbrev
->tag
)
17769 && abbrev
->tag
!= DW_TAG_constant
17770 && abbrev
->tag
!= DW_TAG_enumerator
17771 && abbrev
->tag
!= DW_TAG_subprogram
17772 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17773 && abbrev
->tag
!= DW_TAG_lexical_block
17774 && abbrev
->tag
!= DW_TAG_variable
17775 && abbrev
->tag
!= DW_TAG_namespace
17776 && abbrev
->tag
!= DW_TAG_module
17777 && abbrev
->tag
!= DW_TAG_member
17778 && abbrev
->tag
!= DW_TAG_imported_unit
17779 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17781 /* Otherwise we skip to the next sibling, if any. */
17782 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17786 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17789 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17791 /* This two-pass algorithm for processing partial symbols has a
17792 high cost in cache pressure. Thus, handle some simple cases
17793 here which cover the majority of C partial symbols. DIEs
17794 which neither have specification tags in them, nor could have
17795 specification tags elsewhere pointing at them, can simply be
17796 processed and discarded.
17798 This segment is also optional; scan_partial_symbols and
17799 add_partial_symbol will handle these DIEs if we chain
17800 them in normally. When compilers which do not emit large
17801 quantities of duplicate debug information are more common,
17802 this code can probably be removed. */
17804 /* Any complete simple types at the top level (pretty much all
17805 of them, for a language without namespaces), can be processed
17807 if (parent_die
== NULL
17808 && pdi
.has_specification
== 0
17809 && pdi
.is_declaration
== 0
17810 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17811 || pdi
.tag
== DW_TAG_base_type
17812 || pdi
.tag
== DW_TAG_subrange_type
))
17814 if (building_psymtab
&& pdi
.name
!= NULL
)
17815 add_psymbol_to_list (pdi
.name
, false,
17816 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17817 psymbol_placement::STATIC
,
17818 0, cu
->language
, objfile
);
17819 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17823 /* The exception for DW_TAG_typedef with has_children above is
17824 a workaround of GCC PR debug/47510. In the case of this complaint
17825 type_name_or_error will error on such types later.
17827 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17828 it could not find the child DIEs referenced later, this is checked
17829 above. In correct DWARF DW_TAG_typedef should have no children. */
17831 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17832 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17833 "- DIE at %s [in module %s]"),
17834 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17836 /* If we're at the second level, and we're an enumerator, and
17837 our parent has no specification (meaning possibly lives in a
17838 namespace elsewhere), then we can add the partial symbol now
17839 instead of queueing it. */
17840 if (pdi
.tag
== DW_TAG_enumerator
17841 && parent_die
!= NULL
17842 && parent_die
->die_parent
== NULL
17843 && parent_die
->tag
== DW_TAG_enumeration_type
17844 && parent_die
->has_specification
== 0)
17846 if (pdi
.name
== NULL
)
17847 complaint (_("malformed enumerator DIE ignored"));
17848 else if (building_psymtab
)
17849 add_psymbol_to_list (pdi
.name
, false,
17850 VAR_DOMAIN
, LOC_CONST
, -1,
17851 cu
->language
== language_cplus
17852 ? psymbol_placement::GLOBAL
17853 : psymbol_placement::STATIC
,
17854 0, cu
->language
, objfile
);
17856 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17860 struct partial_die_info
*part_die
17861 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17863 /* We'll save this DIE so link it in. */
17864 part_die
->die_parent
= parent_die
;
17865 part_die
->die_sibling
= NULL
;
17866 part_die
->die_child
= NULL
;
17868 if (last_die
&& last_die
== parent_die
)
17869 last_die
->die_child
= part_die
;
17871 last_die
->die_sibling
= part_die
;
17873 last_die
= part_die
;
17875 if (first_die
== NULL
)
17876 first_die
= part_die
;
17878 /* Maybe add the DIE to the hash table. Not all DIEs that we
17879 find interesting need to be in the hash table, because we
17880 also have the parent/sibling/child chains; only those that we
17881 might refer to by offset later during partial symbol reading.
17883 For now this means things that might have be the target of a
17884 DW_AT_specification, DW_AT_abstract_origin, or
17885 DW_AT_extension. DW_AT_extension will refer only to
17886 namespaces; DW_AT_abstract_origin refers to functions (and
17887 many things under the function DIE, but we do not recurse
17888 into function DIEs during partial symbol reading) and
17889 possibly variables as well; DW_AT_specification refers to
17890 declarations. Declarations ought to have the DW_AT_declaration
17891 flag. It happens that GCC forgets to put it in sometimes, but
17892 only for functions, not for types.
17894 Adding more things than necessary to the hash table is harmless
17895 except for the performance cost. Adding too few will result in
17896 wasted time in find_partial_die, when we reread the compilation
17897 unit with load_all_dies set. */
17900 || abbrev
->tag
== DW_TAG_constant
17901 || abbrev
->tag
== DW_TAG_subprogram
17902 || abbrev
->tag
== DW_TAG_variable
17903 || abbrev
->tag
== DW_TAG_namespace
17904 || part_die
->is_declaration
)
17908 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17909 to_underlying (part_die
->sect_off
),
17914 /* For some DIEs we want to follow their children (if any). For C
17915 we have no reason to follow the children of structures; for other
17916 languages we have to, so that we can get at method physnames
17917 to infer fully qualified class names, for DW_AT_specification,
17918 and for C++ template arguments. For C++, we also look one level
17919 inside functions to find template arguments (if the name of the
17920 function does not already contain the template arguments).
17922 For Ada and Fortran, we need to scan the children of subprograms
17923 and lexical blocks as well because these languages allow the
17924 definition of nested entities that could be interesting for the
17925 debugger, such as nested subprograms for instance. */
17926 if (last_die
->has_children
17928 || last_die
->tag
== DW_TAG_namespace
17929 || last_die
->tag
== DW_TAG_module
17930 || last_die
->tag
== DW_TAG_enumeration_type
17931 || (cu
->language
== language_cplus
17932 && last_die
->tag
== DW_TAG_subprogram
17933 && (last_die
->name
== NULL
17934 || strchr (last_die
->name
, '<') == NULL
))
17935 || (cu
->language
!= language_c
17936 && (last_die
->tag
== DW_TAG_class_type
17937 || last_die
->tag
== DW_TAG_interface_type
17938 || last_die
->tag
== DW_TAG_structure_type
17939 || last_die
->tag
== DW_TAG_union_type
))
17940 || ((cu
->language
== language_ada
17941 || cu
->language
== language_fortran
)
17942 && (last_die
->tag
== DW_TAG_subprogram
17943 || last_die
->tag
== DW_TAG_lexical_block
))))
17946 parent_die
= last_die
;
17950 /* Otherwise we skip to the next sibling, if any. */
17951 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17953 /* Back to the top, do it again. */
17957 partial_die_info::partial_die_info (sect_offset sect_off_
,
17958 struct abbrev_info
*abbrev
)
17959 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17963 /* Read a minimal amount of information into the minimal die structure.
17964 INFO_PTR should point just after the initial uleb128 of a DIE. */
17967 partial_die_info::read (const struct die_reader_specs
*reader
,
17968 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17970 struct dwarf2_cu
*cu
= reader
->cu
;
17971 struct dwarf2_per_objfile
*dwarf2_per_objfile
17972 = cu
->per_cu
->dwarf2_per_objfile
;
17974 int has_low_pc_attr
= 0;
17975 int has_high_pc_attr
= 0;
17976 int high_pc_relative
= 0;
17978 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17979 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17981 bool need_reprocess
;
17982 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17983 info_ptr
, &need_reprocess
);
17984 /* String and address offsets that need to do the reprocessing have
17985 already been read at this point, so there is no need to wait until
17986 the loop terminates to do the reprocessing. */
17987 if (need_reprocess
)
17988 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17989 attribute
&attr
= attr_vec
[i
];
17990 /* Store the data if it is of an attribute we want to keep in a
17991 partial symbol table. */
17997 case DW_TAG_compile_unit
:
17998 case DW_TAG_partial_unit
:
17999 case DW_TAG_type_unit
:
18000 /* Compilation units have a DW_AT_name that is a filename, not
18001 a source language identifier. */
18002 case DW_TAG_enumeration_type
:
18003 case DW_TAG_enumerator
:
18004 /* These tags always have simple identifiers already; no need
18005 to canonicalize them. */
18006 name
= DW_STRING (&attr
);
18010 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18013 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18018 case DW_AT_linkage_name
:
18019 case DW_AT_MIPS_linkage_name
:
18020 /* Note that both forms of linkage name might appear. We
18021 assume they will be the same, and we only store the last
18023 linkage_name
= DW_STRING (&attr
);
18026 has_low_pc_attr
= 1;
18027 lowpc
= attr
.value_as_address ();
18029 case DW_AT_high_pc
:
18030 has_high_pc_attr
= 1;
18031 highpc
= attr
.value_as_address ();
18032 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18033 high_pc_relative
= 1;
18035 case DW_AT_location
:
18036 /* Support the .debug_loc offsets. */
18037 if (attr
.form_is_block ())
18039 d
.locdesc
= DW_BLOCK (&attr
);
18041 else if (attr
.form_is_section_offset ())
18043 dwarf2_complex_location_expr_complaint ();
18047 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18048 "partial symbol information");
18051 case DW_AT_external
:
18052 is_external
= DW_UNSND (&attr
);
18054 case DW_AT_declaration
:
18055 is_declaration
= DW_UNSND (&attr
);
18060 case DW_AT_abstract_origin
:
18061 case DW_AT_specification
:
18062 case DW_AT_extension
:
18063 has_specification
= 1;
18064 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18065 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18066 || cu
->per_cu
->is_dwz
);
18068 case DW_AT_sibling
:
18069 /* Ignore absolute siblings, they might point outside of
18070 the current compile unit. */
18071 if (attr
.form
== DW_FORM_ref_addr
)
18072 complaint (_("ignoring absolute DW_AT_sibling"));
18075 const gdb_byte
*buffer
= reader
->buffer
;
18076 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18077 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18079 if (sibling_ptr
< info_ptr
)
18080 complaint (_("DW_AT_sibling points backwards"));
18081 else if (sibling_ptr
> reader
->buffer_end
)
18082 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18084 sibling
= sibling_ptr
;
18087 case DW_AT_byte_size
:
18090 case DW_AT_const_value
:
18091 has_const_value
= 1;
18093 case DW_AT_calling_convention
:
18094 /* DWARF doesn't provide a way to identify a program's source-level
18095 entry point. DW_AT_calling_convention attributes are only meant
18096 to describe functions' calling conventions.
18098 However, because it's a necessary piece of information in
18099 Fortran, and before DWARF 4 DW_CC_program was the only
18100 piece of debugging information whose definition refers to
18101 a 'main program' at all, several compilers marked Fortran
18102 main programs with DW_CC_program --- even when those
18103 functions use the standard calling conventions.
18105 Although DWARF now specifies a way to provide this
18106 information, we support this practice for backward
18108 if (DW_UNSND (&attr
) == DW_CC_program
18109 && cu
->language
== language_fortran
)
18110 main_subprogram
= 1;
18113 if (DW_UNSND (&attr
) == DW_INL_inlined
18114 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18115 may_be_inlined
= 1;
18119 if (tag
== DW_TAG_imported_unit
)
18121 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18122 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18123 || cu
->per_cu
->is_dwz
);
18127 case DW_AT_main_subprogram
:
18128 main_subprogram
= DW_UNSND (&attr
);
18133 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18134 but that requires a full DIE, so instead we just
18136 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18137 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18138 + (need_ranges_base
18142 /* Value of the DW_AT_ranges attribute is the offset in the
18143 .debug_ranges section. */
18144 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18155 /* For Ada, if both the name and the linkage name appear, we prefer
18156 the latter. This lets "catch exception" work better, regardless
18157 of the order in which the name and linkage name were emitted.
18158 Really, though, this is just a workaround for the fact that gdb
18159 doesn't store both the name and the linkage name. */
18160 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18161 name
= linkage_name
;
18163 if (high_pc_relative
)
18166 if (has_low_pc_attr
&& has_high_pc_attr
)
18168 /* When using the GNU linker, .gnu.linkonce. sections are used to
18169 eliminate duplicate copies of functions and vtables and such.
18170 The linker will arbitrarily choose one and discard the others.
18171 The AT_*_pc values for such functions refer to local labels in
18172 these sections. If the section from that file was discarded, the
18173 labels are not in the output, so the relocs get a value of 0.
18174 If this is a discarded function, mark the pc bounds as invalid,
18175 so that GDB will ignore it. */
18176 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18178 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18179 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18181 complaint (_("DW_AT_low_pc %s is zero "
18182 "for DIE at %s [in module %s]"),
18183 paddress (gdbarch
, lowpc
),
18184 sect_offset_str (sect_off
),
18185 objfile_name (objfile
));
18187 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18188 else if (lowpc
>= highpc
)
18190 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18191 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18193 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18194 "for DIE at %s [in module %s]"),
18195 paddress (gdbarch
, lowpc
),
18196 paddress (gdbarch
, highpc
),
18197 sect_offset_str (sect_off
),
18198 objfile_name (objfile
));
18207 /* Find a cached partial DIE at OFFSET in CU. */
18209 struct partial_die_info
*
18210 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18212 struct partial_die_info
*lookup_die
= NULL
;
18213 struct partial_die_info
part_die (sect_off
);
18215 lookup_die
= ((struct partial_die_info
*)
18216 htab_find_with_hash (partial_dies
, &part_die
,
18217 to_underlying (sect_off
)));
18222 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18223 except in the case of .debug_types DIEs which do not reference
18224 outside their CU (they do however referencing other types via
18225 DW_FORM_ref_sig8). */
18227 static const struct cu_partial_die_info
18228 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18230 struct dwarf2_per_objfile
*dwarf2_per_objfile
18231 = cu
->per_cu
->dwarf2_per_objfile
;
18232 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18233 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18234 struct partial_die_info
*pd
= NULL
;
18236 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18237 && cu
->header
.offset_in_cu_p (sect_off
))
18239 pd
= cu
->find_partial_die (sect_off
);
18242 /* We missed recording what we needed.
18243 Load all dies and try again. */
18244 per_cu
= cu
->per_cu
;
18248 /* TUs don't reference other CUs/TUs (except via type signatures). */
18249 if (cu
->per_cu
->is_debug_types
)
18251 error (_("Dwarf Error: Type Unit at offset %s contains"
18252 " external reference to offset %s [in module %s].\n"),
18253 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18254 bfd_get_filename (objfile
->obfd
));
18256 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18257 dwarf2_per_objfile
);
18259 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18260 load_partial_comp_unit (per_cu
);
18262 per_cu
->cu
->last_used
= 0;
18263 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18266 /* If we didn't find it, and not all dies have been loaded,
18267 load them all and try again. */
18269 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18271 per_cu
->load_all_dies
= 1;
18273 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18274 THIS_CU->cu may already be in use. So we can't just free it and
18275 replace its DIEs with the ones we read in. Instead, we leave those
18276 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18277 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18279 load_partial_comp_unit (per_cu
);
18281 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18285 internal_error (__FILE__
, __LINE__
,
18286 _("could not find partial DIE %s "
18287 "in cache [from module %s]\n"),
18288 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18289 return { per_cu
->cu
, pd
};
18292 /* See if we can figure out if the class lives in a namespace. We do
18293 this by looking for a member function; its demangled name will
18294 contain namespace info, if there is any. */
18297 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18298 struct dwarf2_cu
*cu
)
18300 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18301 what template types look like, because the demangler
18302 frequently doesn't give the same name as the debug info. We
18303 could fix this by only using the demangled name to get the
18304 prefix (but see comment in read_structure_type). */
18306 struct partial_die_info
*real_pdi
;
18307 struct partial_die_info
*child_pdi
;
18309 /* If this DIE (this DIE's specification, if any) has a parent, then
18310 we should not do this. We'll prepend the parent's fully qualified
18311 name when we create the partial symbol. */
18313 real_pdi
= struct_pdi
;
18314 while (real_pdi
->has_specification
)
18316 auto res
= find_partial_die (real_pdi
->spec_offset
,
18317 real_pdi
->spec_is_dwz
, cu
);
18318 real_pdi
= res
.pdi
;
18322 if (real_pdi
->die_parent
!= NULL
)
18325 for (child_pdi
= struct_pdi
->die_child
;
18327 child_pdi
= child_pdi
->die_sibling
)
18329 if (child_pdi
->tag
== DW_TAG_subprogram
18330 && child_pdi
->linkage_name
!= NULL
)
18332 gdb::unique_xmalloc_ptr
<char> actual_class_name
18333 (language_class_name_from_physname (cu
->language_defn
,
18334 child_pdi
->linkage_name
));
18335 if (actual_class_name
!= NULL
)
18337 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18338 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18346 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18348 /* Once we've fixed up a die, there's no point in doing so again.
18349 This also avoids a memory leak if we were to call
18350 guess_partial_die_structure_name multiple times. */
18354 /* If we found a reference attribute and the DIE has no name, try
18355 to find a name in the referred to DIE. */
18357 if (name
== NULL
&& has_specification
)
18359 struct partial_die_info
*spec_die
;
18361 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18362 spec_die
= res
.pdi
;
18365 spec_die
->fixup (cu
);
18367 if (spec_die
->name
)
18369 name
= spec_die
->name
;
18371 /* Copy DW_AT_external attribute if it is set. */
18372 if (spec_die
->is_external
)
18373 is_external
= spec_die
->is_external
;
18377 /* Set default names for some unnamed DIEs. */
18379 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18380 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18382 /* If there is no parent die to provide a namespace, and there are
18383 children, see if we can determine the namespace from their linkage
18385 if (cu
->language
== language_cplus
18386 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18387 && die_parent
== NULL
18389 && (tag
== DW_TAG_class_type
18390 || tag
== DW_TAG_structure_type
18391 || tag
== DW_TAG_union_type
))
18392 guess_partial_die_structure_name (this, cu
);
18394 /* GCC might emit a nameless struct or union that has a linkage
18395 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18397 && (tag
== DW_TAG_class_type
18398 || tag
== DW_TAG_interface_type
18399 || tag
== DW_TAG_structure_type
18400 || tag
== DW_TAG_union_type
)
18401 && linkage_name
!= NULL
)
18403 gdb::unique_xmalloc_ptr
<char> demangled
18404 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18405 if (demangled
!= nullptr)
18409 /* Strip any leading namespaces/classes, keep only the base name.
18410 DW_AT_name for named DIEs does not contain the prefixes. */
18411 base
= strrchr (demangled
.get (), ':');
18412 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18415 base
= demangled
.get ();
18417 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18418 name
= objfile
->intern (base
);
18425 /* Process the attributes that had to be skipped in the first round. These
18426 attributes are the ones that need str_offsets_base or addr_base attributes.
18427 They could not have been processed in the first round, because at the time
18428 the values of str_offsets_base or addr_base may not have been known. */
18429 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18430 struct attribute
*attr
)
18432 struct dwarf2_cu
*cu
= reader
->cu
;
18433 switch (attr
->form
)
18435 case DW_FORM_addrx
:
18436 case DW_FORM_GNU_addr_index
:
18437 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18440 case DW_FORM_strx1
:
18441 case DW_FORM_strx2
:
18442 case DW_FORM_strx3
:
18443 case DW_FORM_strx4
:
18444 case DW_FORM_GNU_str_index
:
18446 unsigned int str_index
= DW_UNSND (attr
);
18447 if (reader
->dwo_file
!= NULL
)
18449 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18450 DW_STRING_IS_CANONICAL (attr
) = 0;
18454 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18455 DW_STRING_IS_CANONICAL (attr
) = 0;
18460 gdb_assert_not_reached (_("Unexpected DWARF form."));
18464 /* Read an attribute value described by an attribute form. */
18466 static const gdb_byte
*
18467 read_attribute_value (const struct die_reader_specs
*reader
,
18468 struct attribute
*attr
, unsigned form
,
18469 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18470 bool *need_reprocess
)
18472 struct dwarf2_cu
*cu
= reader
->cu
;
18473 struct dwarf2_per_objfile
*dwarf2_per_objfile
18474 = cu
->per_cu
->dwarf2_per_objfile
;
18475 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18476 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18477 bfd
*abfd
= reader
->abfd
;
18478 struct comp_unit_head
*cu_header
= &cu
->header
;
18479 unsigned int bytes_read
;
18480 struct dwarf_block
*blk
;
18481 *need_reprocess
= false;
18483 attr
->form
= (enum dwarf_form
) form
;
18486 case DW_FORM_ref_addr
:
18487 if (cu
->header
.version
== 2)
18488 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18491 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18493 info_ptr
+= bytes_read
;
18495 case DW_FORM_GNU_ref_alt
:
18496 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18497 info_ptr
+= bytes_read
;
18500 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18501 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18502 info_ptr
+= bytes_read
;
18504 case DW_FORM_block2
:
18505 blk
= dwarf_alloc_block (cu
);
18506 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18508 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18509 info_ptr
+= blk
->size
;
18510 DW_BLOCK (attr
) = blk
;
18512 case DW_FORM_block4
:
18513 blk
= dwarf_alloc_block (cu
);
18514 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18516 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18517 info_ptr
+= blk
->size
;
18518 DW_BLOCK (attr
) = blk
;
18520 case DW_FORM_data2
:
18521 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18524 case DW_FORM_data4
:
18525 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18528 case DW_FORM_data8
:
18529 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18532 case DW_FORM_data16
:
18533 blk
= dwarf_alloc_block (cu
);
18535 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18537 DW_BLOCK (attr
) = blk
;
18539 case DW_FORM_sec_offset
:
18540 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18541 info_ptr
+= bytes_read
;
18543 case DW_FORM_string
:
18544 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18545 DW_STRING_IS_CANONICAL (attr
) = 0;
18546 info_ptr
+= bytes_read
;
18549 if (!cu
->per_cu
->is_dwz
)
18551 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18552 abfd
, info_ptr
, cu_header
,
18554 DW_STRING_IS_CANONICAL (attr
) = 0;
18555 info_ptr
+= bytes_read
;
18559 case DW_FORM_line_strp
:
18560 if (!cu
->per_cu
->is_dwz
)
18562 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18564 cu_header
, &bytes_read
);
18565 DW_STRING_IS_CANONICAL (attr
) = 0;
18566 info_ptr
+= bytes_read
;
18570 case DW_FORM_GNU_strp_alt
:
18572 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18573 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18576 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18577 DW_STRING_IS_CANONICAL (attr
) = 0;
18578 info_ptr
+= bytes_read
;
18581 case DW_FORM_exprloc
:
18582 case DW_FORM_block
:
18583 blk
= dwarf_alloc_block (cu
);
18584 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18585 info_ptr
+= bytes_read
;
18586 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18587 info_ptr
+= blk
->size
;
18588 DW_BLOCK (attr
) = blk
;
18590 case DW_FORM_block1
:
18591 blk
= dwarf_alloc_block (cu
);
18592 blk
->size
= read_1_byte (abfd
, info_ptr
);
18594 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18595 info_ptr
+= blk
->size
;
18596 DW_BLOCK (attr
) = blk
;
18598 case DW_FORM_data1
:
18599 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18603 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18606 case DW_FORM_flag_present
:
18607 DW_UNSND (attr
) = 1;
18609 case DW_FORM_sdata
:
18610 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18611 info_ptr
+= bytes_read
;
18613 case DW_FORM_udata
:
18614 case DW_FORM_rnglistx
:
18615 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18616 info_ptr
+= bytes_read
;
18619 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18620 + read_1_byte (abfd
, info_ptr
));
18624 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18625 + read_2_bytes (abfd
, info_ptr
));
18629 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18630 + read_4_bytes (abfd
, info_ptr
));
18634 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18635 + read_8_bytes (abfd
, info_ptr
));
18638 case DW_FORM_ref_sig8
:
18639 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18642 case DW_FORM_ref_udata
:
18643 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18644 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18645 info_ptr
+= bytes_read
;
18647 case DW_FORM_indirect
:
18648 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18649 info_ptr
+= bytes_read
;
18650 if (form
== DW_FORM_implicit_const
)
18652 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18653 info_ptr
+= bytes_read
;
18655 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18656 info_ptr
, need_reprocess
);
18658 case DW_FORM_implicit_const
:
18659 DW_SND (attr
) = implicit_const
;
18661 case DW_FORM_addrx
:
18662 case DW_FORM_GNU_addr_index
:
18663 *need_reprocess
= true;
18664 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18665 info_ptr
+= bytes_read
;
18668 case DW_FORM_strx1
:
18669 case DW_FORM_strx2
:
18670 case DW_FORM_strx3
:
18671 case DW_FORM_strx4
:
18672 case DW_FORM_GNU_str_index
:
18674 ULONGEST str_index
;
18675 if (form
== DW_FORM_strx1
)
18677 str_index
= read_1_byte (abfd
, info_ptr
);
18680 else if (form
== DW_FORM_strx2
)
18682 str_index
= read_2_bytes (abfd
, info_ptr
);
18685 else if (form
== DW_FORM_strx3
)
18687 str_index
= read_3_bytes (abfd
, info_ptr
);
18690 else if (form
== DW_FORM_strx4
)
18692 str_index
= read_4_bytes (abfd
, info_ptr
);
18697 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18698 info_ptr
+= bytes_read
;
18700 *need_reprocess
= true;
18701 DW_UNSND (attr
) = str_index
;
18705 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18706 dwarf_form_name (form
),
18707 bfd_get_filename (abfd
));
18711 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18712 attr
->form
= DW_FORM_GNU_ref_alt
;
18714 /* We have seen instances where the compiler tried to emit a byte
18715 size attribute of -1 which ended up being encoded as an unsigned
18716 0xffffffff. Although 0xffffffff is technically a valid size value,
18717 an object of this size seems pretty unlikely so we can relatively
18718 safely treat these cases as if the size attribute was invalid and
18719 treat them as zero by default. */
18720 if (attr
->name
== DW_AT_byte_size
18721 && form
== DW_FORM_data4
18722 && DW_UNSND (attr
) >= 0xffffffff)
18725 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18726 hex_string (DW_UNSND (attr
)));
18727 DW_UNSND (attr
) = 0;
18733 /* Read an attribute described by an abbreviated attribute. */
18735 static const gdb_byte
*
18736 read_attribute (const struct die_reader_specs
*reader
,
18737 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18738 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18740 attr
->name
= abbrev
->name
;
18741 return read_attribute_value (reader
, attr
, abbrev
->form
,
18742 abbrev
->implicit_const
, info_ptr
,
18746 /* Cover function for read_initial_length.
18747 Returns the length of the object at BUF, and stores the size of the
18748 initial length in *BYTES_READ and stores the size that offsets will be in
18750 If the initial length size is not equivalent to that specified in
18751 CU_HEADER then issue a complaint.
18752 This is useful when reading non-comp-unit headers. */
18755 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18756 const struct comp_unit_head
*cu_header
,
18757 unsigned int *bytes_read
,
18758 unsigned int *offset_size
)
18760 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18762 gdb_assert (cu_header
->initial_length_size
== 4
18763 || cu_header
->initial_length_size
== 8
18764 || cu_header
->initial_length_size
== 12);
18766 if (cu_header
->initial_length_size
!= *bytes_read
)
18767 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18769 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18773 /* Return pointer to string at section SECT offset STR_OFFSET with error
18774 reporting strings FORM_NAME and SECT_NAME. */
18776 static const char *
18777 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18778 bfd
*abfd
, LONGEST str_offset
,
18779 struct dwarf2_section_info
*sect
,
18780 const char *form_name
,
18781 const char *sect_name
)
18783 sect
->read (objfile
);
18784 if (sect
->buffer
== NULL
)
18785 error (_("%s used without %s section [in module %s]"),
18786 form_name
, sect_name
, bfd_get_filename (abfd
));
18787 if (str_offset
>= sect
->size
)
18788 error (_("%s pointing outside of %s section [in module %s]"),
18789 form_name
, sect_name
, bfd_get_filename (abfd
));
18790 gdb_assert (HOST_CHAR_BIT
== 8);
18791 if (sect
->buffer
[str_offset
] == '\0')
18793 return (const char *) (sect
->buffer
+ str_offset
);
18796 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18798 static const char *
18799 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18800 bfd
*abfd
, LONGEST str_offset
)
18802 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18804 &dwarf2_per_objfile
->str
,
18805 "DW_FORM_strp", ".debug_str");
18808 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18810 static const char *
18811 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18812 bfd
*abfd
, LONGEST str_offset
)
18814 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18816 &dwarf2_per_objfile
->line_str
,
18817 "DW_FORM_line_strp",
18818 ".debug_line_str");
18821 /* Return pointer to string at .debug_str offset as read from BUF.
18822 BUF is assumed to be in a compilation unit described by CU_HEADER.
18823 Return *BYTES_READ_PTR count of bytes read from BUF. */
18825 static const char *
18826 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18827 const gdb_byte
*buf
,
18828 const struct comp_unit_head
*cu_header
,
18829 unsigned int *bytes_read_ptr
)
18831 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18833 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18836 /* Return pointer to string at .debug_line_str offset as read from BUF.
18837 BUF is assumed to be in a compilation unit described by CU_HEADER.
18838 Return *BYTES_READ_PTR count of bytes read from BUF. */
18840 static const char *
18841 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18842 bfd
*abfd
, const gdb_byte
*buf
,
18843 const struct comp_unit_head
*cu_header
,
18844 unsigned int *bytes_read_ptr
)
18846 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18848 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18852 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18853 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18854 ADDR_SIZE is the size of addresses from the CU header. */
18857 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18858 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18861 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18862 bfd
*abfd
= objfile
->obfd
;
18863 const gdb_byte
*info_ptr
;
18864 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18866 dwarf2_per_objfile
->addr
.read (objfile
);
18867 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18868 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18869 objfile_name (objfile
));
18870 if (addr_base_or_zero
+ addr_index
* addr_size
18871 >= dwarf2_per_objfile
->addr
.size
)
18872 error (_("DW_FORM_addr_index pointing outside of "
18873 ".debug_addr section [in module %s]"),
18874 objfile_name (objfile
));
18875 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18876 + addr_base_or_zero
+ addr_index
* addr_size
);
18877 if (addr_size
== 4)
18878 return bfd_get_32 (abfd
, info_ptr
);
18880 return bfd_get_64 (abfd
, info_ptr
);
18883 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18886 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18888 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18889 cu
->addr_base
, cu
->header
.addr_size
);
18892 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18895 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18896 unsigned int *bytes_read
)
18898 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18899 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18901 return read_addr_index (cu
, addr_index
);
18907 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18909 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18910 struct dwarf2_cu
*cu
= per_cu
->cu
;
18911 gdb::optional
<ULONGEST
> addr_base
;
18914 /* We need addr_base and addr_size.
18915 If we don't have PER_CU->cu, we have to get it.
18916 Nasty, but the alternative is storing the needed info in PER_CU,
18917 which at this point doesn't seem justified: it's not clear how frequently
18918 it would get used and it would increase the size of every PER_CU.
18919 Entry points like dwarf2_per_cu_addr_size do a similar thing
18920 so we're not in uncharted territory here.
18921 Alas we need to be a bit more complicated as addr_base is contained
18924 We don't need to read the entire CU(/TU).
18925 We just need the header and top level die.
18927 IWBN to use the aging mechanism to let us lazily later discard the CU.
18928 For now we skip this optimization. */
18932 addr_base
= cu
->addr_base
;
18933 addr_size
= cu
->header
.addr_size
;
18937 cutu_reader
reader (per_cu
, NULL
, 0, false);
18938 addr_base
= reader
.cu
->addr_base
;
18939 addr_size
= reader
.cu
->header
.addr_size
;
18942 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18946 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18947 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18950 static const char *
18951 read_str_index (struct dwarf2_cu
*cu
,
18952 struct dwarf2_section_info
*str_section
,
18953 struct dwarf2_section_info
*str_offsets_section
,
18954 ULONGEST str_offsets_base
, ULONGEST str_index
)
18956 struct dwarf2_per_objfile
*dwarf2_per_objfile
18957 = cu
->per_cu
->dwarf2_per_objfile
;
18958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18959 const char *objf_name
= objfile_name (objfile
);
18960 bfd
*abfd
= objfile
->obfd
;
18961 const gdb_byte
*info_ptr
;
18962 ULONGEST str_offset
;
18963 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18965 str_section
->read (objfile
);
18966 str_offsets_section
->read (objfile
);
18967 if (str_section
->buffer
== NULL
)
18968 error (_("%s used without %s section"
18969 " in CU at offset %s [in module %s]"),
18970 form_name
, str_section
->get_name (),
18971 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18972 if (str_offsets_section
->buffer
== NULL
)
18973 error (_("%s used without %s section"
18974 " in CU at offset %s [in module %s]"),
18975 form_name
, str_section
->get_name (),
18976 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18977 info_ptr
= (str_offsets_section
->buffer
18979 + str_index
* cu
->header
.offset_size
);
18980 if (cu
->header
.offset_size
== 4)
18981 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18983 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18984 if (str_offset
>= str_section
->size
)
18985 error (_("Offset from %s pointing outside of"
18986 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18987 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18988 return (const char *) (str_section
->buffer
+ str_offset
);
18991 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18993 static const char *
18994 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18996 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18997 ? reader
->cu
->header
.addr_size
: 0;
18998 return read_str_index (reader
->cu
,
18999 &reader
->dwo_file
->sections
.str
,
19000 &reader
->dwo_file
->sections
.str_offsets
,
19001 str_offsets_base
, str_index
);
19004 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19006 static const char *
19007 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19009 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19010 const char *objf_name
= objfile_name (objfile
);
19011 static const char form_name
[] = "DW_FORM_GNU_str_index";
19012 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19014 if (!cu
->str_offsets_base
.has_value ())
19015 error (_("%s used in Fission stub without %s"
19016 " in CU at offset 0x%lx [in module %s]"),
19017 form_name
, str_offsets_attr_name
,
19018 (long) cu
->header
.offset_size
, objf_name
);
19020 return read_str_index (cu
,
19021 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19022 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19023 *cu
->str_offsets_base
, str_index
);
19026 /* Return the length of an LEB128 number in BUF. */
19029 leb128_size (const gdb_byte
*buf
)
19031 const gdb_byte
*begin
= buf
;
19037 if ((byte
& 128) == 0)
19038 return buf
- begin
;
19043 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19052 cu
->language
= language_c
;
19055 case DW_LANG_C_plus_plus
:
19056 case DW_LANG_C_plus_plus_11
:
19057 case DW_LANG_C_plus_plus_14
:
19058 cu
->language
= language_cplus
;
19061 cu
->language
= language_d
;
19063 case DW_LANG_Fortran77
:
19064 case DW_LANG_Fortran90
:
19065 case DW_LANG_Fortran95
:
19066 case DW_LANG_Fortran03
:
19067 case DW_LANG_Fortran08
:
19068 cu
->language
= language_fortran
;
19071 cu
->language
= language_go
;
19073 case DW_LANG_Mips_Assembler
:
19074 cu
->language
= language_asm
;
19076 case DW_LANG_Ada83
:
19077 case DW_LANG_Ada95
:
19078 cu
->language
= language_ada
;
19080 case DW_LANG_Modula2
:
19081 cu
->language
= language_m2
;
19083 case DW_LANG_Pascal83
:
19084 cu
->language
= language_pascal
;
19087 cu
->language
= language_objc
;
19090 case DW_LANG_Rust_old
:
19091 cu
->language
= language_rust
;
19093 case DW_LANG_Cobol74
:
19094 case DW_LANG_Cobol85
:
19096 cu
->language
= language_minimal
;
19099 cu
->language_defn
= language_def (cu
->language
);
19102 /* Return the named attribute or NULL if not there. */
19104 static struct attribute
*
19105 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19110 struct attribute
*spec
= NULL
;
19112 for (i
= 0; i
< die
->num_attrs
; ++i
)
19114 if (die
->attrs
[i
].name
== name
)
19115 return &die
->attrs
[i
];
19116 if (die
->attrs
[i
].name
== DW_AT_specification
19117 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19118 spec
= &die
->attrs
[i
];
19124 die
= follow_die_ref (die
, spec
, &cu
);
19130 /* Return the named attribute or NULL if not there,
19131 but do not follow DW_AT_specification, etc.
19132 This is for use in contexts where we're reading .debug_types dies.
19133 Following DW_AT_specification, DW_AT_abstract_origin will take us
19134 back up the chain, and we want to go down. */
19136 static struct attribute
*
19137 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19141 for (i
= 0; i
< die
->num_attrs
; ++i
)
19142 if (die
->attrs
[i
].name
== name
)
19143 return &die
->attrs
[i
];
19148 /* Return the string associated with a string-typed attribute, or NULL if it
19149 is either not found or is of an incorrect type. */
19151 static const char *
19152 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19154 struct attribute
*attr
;
19155 const char *str
= NULL
;
19157 attr
= dwarf2_attr (die
, name
, cu
);
19161 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19162 || attr
->form
== DW_FORM_string
19163 || attr
->form
== DW_FORM_strx
19164 || attr
->form
== DW_FORM_strx1
19165 || attr
->form
== DW_FORM_strx2
19166 || attr
->form
== DW_FORM_strx3
19167 || attr
->form
== DW_FORM_strx4
19168 || attr
->form
== DW_FORM_GNU_str_index
19169 || attr
->form
== DW_FORM_GNU_strp_alt
)
19170 str
= DW_STRING (attr
);
19172 complaint (_("string type expected for attribute %s for "
19173 "DIE at %s in module %s"),
19174 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19175 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19181 /* Return the dwo name or NULL if not present. If present, it is in either
19182 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19183 static const char *
19184 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19186 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19187 if (dwo_name
== nullptr)
19188 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19192 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19193 and holds a non-zero value. This function should only be used for
19194 DW_FORM_flag or DW_FORM_flag_present attributes. */
19197 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19199 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19201 return (attr
&& DW_UNSND (attr
));
19205 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19207 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19208 which value is non-zero. However, we have to be careful with
19209 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19210 (via dwarf2_flag_true_p) follows this attribute. So we may
19211 end up accidently finding a declaration attribute that belongs
19212 to a different DIE referenced by the specification attribute,
19213 even though the given DIE does not have a declaration attribute. */
19214 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19215 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19218 /* Return the die giving the specification for DIE, if there is
19219 one. *SPEC_CU is the CU containing DIE on input, and the CU
19220 containing the return value on output. If there is no
19221 specification, but there is an abstract origin, that is
19224 static struct die_info
*
19225 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19227 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19230 if (spec_attr
== NULL
)
19231 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19233 if (spec_attr
== NULL
)
19236 return follow_die_ref (die
, spec_attr
, spec_cu
);
19239 /* Stub for free_line_header to match void * callback types. */
19242 free_line_header_voidp (void *arg
)
19244 struct line_header
*lh
= (struct line_header
*) arg
;
19249 /* A convenience function to find the proper .debug_line section for a CU. */
19251 static struct dwarf2_section_info
*
19252 get_debug_line_section (struct dwarf2_cu
*cu
)
19254 struct dwarf2_section_info
*section
;
19255 struct dwarf2_per_objfile
*dwarf2_per_objfile
19256 = cu
->per_cu
->dwarf2_per_objfile
;
19258 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19260 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19261 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19262 else if (cu
->per_cu
->is_dwz
)
19264 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19266 section
= &dwz
->line
;
19269 section
= &dwarf2_per_objfile
->line
;
19274 /* Read directory or file name entry format, starting with byte of
19275 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19276 entries count and the entries themselves in the described entry
19280 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19281 bfd
*abfd
, const gdb_byte
**bufp
,
19282 struct line_header
*lh
,
19283 const struct comp_unit_head
*cu_header
,
19284 void (*callback
) (struct line_header
*lh
,
19287 unsigned int mod_time
,
19288 unsigned int length
))
19290 gdb_byte format_count
, formati
;
19291 ULONGEST data_count
, datai
;
19292 const gdb_byte
*buf
= *bufp
;
19293 const gdb_byte
*format_header_data
;
19294 unsigned int bytes_read
;
19296 format_count
= read_1_byte (abfd
, buf
);
19298 format_header_data
= buf
;
19299 for (formati
= 0; formati
< format_count
; formati
++)
19301 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19303 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19307 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19309 for (datai
= 0; datai
< data_count
; datai
++)
19311 const gdb_byte
*format
= format_header_data
;
19312 struct file_entry fe
;
19314 for (formati
= 0; formati
< format_count
; formati
++)
19316 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19317 format
+= bytes_read
;
19319 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19320 format
+= bytes_read
;
19322 gdb::optional
<const char *> string
;
19323 gdb::optional
<unsigned int> uint
;
19327 case DW_FORM_string
:
19328 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19332 case DW_FORM_line_strp
:
19333 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19340 case DW_FORM_data1
:
19341 uint
.emplace (read_1_byte (abfd
, buf
));
19345 case DW_FORM_data2
:
19346 uint
.emplace (read_2_bytes (abfd
, buf
));
19350 case DW_FORM_data4
:
19351 uint
.emplace (read_4_bytes (abfd
, buf
));
19355 case DW_FORM_data8
:
19356 uint
.emplace (read_8_bytes (abfd
, buf
));
19360 case DW_FORM_data16
:
19361 /* This is used for MD5, but file_entry does not record MD5s. */
19365 case DW_FORM_udata
:
19366 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19370 case DW_FORM_block
:
19371 /* It is valid only for DW_LNCT_timestamp which is ignored by
19376 switch (content_type
)
19379 if (string
.has_value ())
19382 case DW_LNCT_directory_index
:
19383 if (uint
.has_value ())
19384 fe
.d_index
= (dir_index
) *uint
;
19386 case DW_LNCT_timestamp
:
19387 if (uint
.has_value ())
19388 fe
.mod_time
= *uint
;
19391 if (uint
.has_value ())
19397 complaint (_("Unknown format content type %s"),
19398 pulongest (content_type
));
19402 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19408 /* Read the statement program header starting at OFFSET in
19409 .debug_line, or .debug_line.dwo. Return a pointer
19410 to a struct line_header, allocated using xmalloc.
19411 Returns NULL if there is a problem reading the header, e.g., if it
19412 has a version we don't understand.
19414 NOTE: the strings in the include directory and file name tables of
19415 the returned object point into the dwarf line section buffer,
19416 and must not be freed. */
19418 static line_header_up
19419 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19421 const gdb_byte
*line_ptr
;
19422 unsigned int bytes_read
, offset_size
;
19424 const char *cur_dir
, *cur_file
;
19425 struct dwarf2_section_info
*section
;
19427 struct dwarf2_per_objfile
*dwarf2_per_objfile
19428 = cu
->per_cu
->dwarf2_per_objfile
;
19430 section
= get_debug_line_section (cu
);
19431 section
->read (dwarf2_per_objfile
->objfile
);
19432 if (section
->buffer
== NULL
)
19434 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19435 complaint (_("missing .debug_line.dwo section"));
19437 complaint (_("missing .debug_line section"));
19441 /* We can't do this until we know the section is non-empty.
19442 Only then do we know we have such a section. */
19443 abfd
= section
->get_bfd_owner ();
19445 /* Make sure that at least there's room for the total_length field.
19446 That could be 12 bytes long, but we're just going to fudge that. */
19447 if (to_underlying (sect_off
) + 4 >= section
->size
)
19449 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19453 line_header_up
lh (new line_header ());
19455 lh
->sect_off
= sect_off
;
19456 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19458 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19460 /* Read in the header. */
19462 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19463 &bytes_read
, &offset_size
);
19464 line_ptr
+= bytes_read
;
19466 const gdb_byte
*start_here
= line_ptr
;
19468 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19470 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19473 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19474 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19476 if (lh
->version
> 5)
19478 /* This is a version we don't understand. The format could have
19479 changed in ways we don't handle properly so just punt. */
19480 complaint (_("unsupported version in .debug_line section"));
19483 if (lh
->version
>= 5)
19485 gdb_byte segment_selector_size
;
19487 /* Skip address size. */
19488 read_1_byte (abfd
, line_ptr
);
19491 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19493 if (segment_selector_size
!= 0)
19495 complaint (_("unsupported segment selector size %u "
19496 "in .debug_line section"),
19497 segment_selector_size
);
19501 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19502 line_ptr
+= offset_size
;
19503 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19504 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19506 if (lh
->version
>= 4)
19508 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19512 lh
->maximum_ops_per_instruction
= 1;
19514 if (lh
->maximum_ops_per_instruction
== 0)
19516 lh
->maximum_ops_per_instruction
= 1;
19517 complaint (_("invalid maximum_ops_per_instruction "
19518 "in `.debug_line' section"));
19521 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19523 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19525 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19527 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19529 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19531 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19532 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19534 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19538 if (lh
->version
>= 5)
19540 /* Read directory table. */
19541 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19543 [] (struct line_header
*header
, const char *name
,
19544 dir_index d_index
, unsigned int mod_time
,
19545 unsigned int length
)
19547 header
->add_include_dir (name
);
19550 /* Read file name table. */
19551 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19553 [] (struct line_header
*header
, const char *name
,
19554 dir_index d_index
, unsigned int mod_time
,
19555 unsigned int length
)
19557 header
->add_file_name (name
, d_index
, mod_time
, length
);
19562 /* Read directory table. */
19563 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19565 line_ptr
+= bytes_read
;
19566 lh
->add_include_dir (cur_dir
);
19568 line_ptr
+= bytes_read
;
19570 /* Read file name table. */
19571 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19573 unsigned int mod_time
, length
;
19576 line_ptr
+= bytes_read
;
19577 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19578 line_ptr
+= bytes_read
;
19579 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19580 line_ptr
+= bytes_read
;
19581 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19582 line_ptr
+= bytes_read
;
19584 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19586 line_ptr
+= bytes_read
;
19589 if (line_ptr
> (section
->buffer
+ section
->size
))
19590 complaint (_("line number info header doesn't "
19591 "fit in `.debug_line' section"));
19596 /* Subroutine of dwarf_decode_lines to simplify it.
19597 Return the file name of the psymtab for the given file_entry.
19598 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19599 If space for the result is malloc'd, *NAME_HOLDER will be set.
19600 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19602 static const char *
19603 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19604 const dwarf2_psymtab
*pst
,
19605 const char *comp_dir
,
19606 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19608 const char *include_name
= fe
.name
;
19609 const char *include_name_to_compare
= include_name
;
19610 const char *pst_filename
;
19613 const char *dir_name
= fe
.include_dir (lh
);
19615 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19616 if (!IS_ABSOLUTE_PATH (include_name
)
19617 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19619 /* Avoid creating a duplicate psymtab for PST.
19620 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19621 Before we do the comparison, however, we need to account
19622 for DIR_NAME and COMP_DIR.
19623 First prepend dir_name (if non-NULL). If we still don't
19624 have an absolute path prepend comp_dir (if non-NULL).
19625 However, the directory we record in the include-file's
19626 psymtab does not contain COMP_DIR (to match the
19627 corresponding symtab(s)).
19632 bash$ gcc -g ./hello.c
19633 include_name = "hello.c"
19635 DW_AT_comp_dir = comp_dir = "/tmp"
19636 DW_AT_name = "./hello.c"
19640 if (dir_name
!= NULL
)
19642 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19643 include_name
, (char *) NULL
));
19644 include_name
= name_holder
->get ();
19645 include_name_to_compare
= include_name
;
19647 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19649 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19650 include_name
, (char *) NULL
));
19651 include_name_to_compare
= hold_compare
.get ();
19655 pst_filename
= pst
->filename
;
19656 gdb::unique_xmalloc_ptr
<char> copied_name
;
19657 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19659 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19660 pst_filename
, (char *) NULL
));
19661 pst_filename
= copied_name
.get ();
19664 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19668 return include_name
;
19671 /* State machine to track the state of the line number program. */
19673 class lnp_state_machine
19676 /* Initialize a machine state for the start of a line number
19678 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19679 bool record_lines_p
);
19681 file_entry
*current_file ()
19683 /* lh->file_names is 0-based, but the file name numbers in the
19684 statement program are 1-based. */
19685 return m_line_header
->file_name_at (m_file
);
19688 /* Record the line in the state machine. END_SEQUENCE is true if
19689 we're processing the end of a sequence. */
19690 void record_line (bool end_sequence
);
19692 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19693 nop-out rest of the lines in this sequence. */
19694 void check_line_address (struct dwarf2_cu
*cu
,
19695 const gdb_byte
*line_ptr
,
19696 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19698 void handle_set_discriminator (unsigned int discriminator
)
19700 m_discriminator
= discriminator
;
19701 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19704 /* Handle DW_LNE_set_address. */
19705 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19708 address
+= baseaddr
;
19709 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19712 /* Handle DW_LNS_advance_pc. */
19713 void handle_advance_pc (CORE_ADDR adjust
);
19715 /* Handle a special opcode. */
19716 void handle_special_opcode (unsigned char op_code
);
19718 /* Handle DW_LNS_advance_line. */
19719 void handle_advance_line (int line_delta
)
19721 advance_line (line_delta
);
19724 /* Handle DW_LNS_set_file. */
19725 void handle_set_file (file_name_index file
);
19727 /* Handle DW_LNS_negate_stmt. */
19728 void handle_negate_stmt ()
19730 m_is_stmt
= !m_is_stmt
;
19733 /* Handle DW_LNS_const_add_pc. */
19734 void handle_const_add_pc ();
19736 /* Handle DW_LNS_fixed_advance_pc. */
19737 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19739 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19743 /* Handle DW_LNS_copy. */
19744 void handle_copy ()
19746 record_line (false);
19747 m_discriminator
= 0;
19750 /* Handle DW_LNE_end_sequence. */
19751 void handle_end_sequence ()
19753 m_currently_recording_lines
= true;
19757 /* Advance the line by LINE_DELTA. */
19758 void advance_line (int line_delta
)
19760 m_line
+= line_delta
;
19762 if (line_delta
!= 0)
19763 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19766 struct dwarf2_cu
*m_cu
;
19768 gdbarch
*m_gdbarch
;
19770 /* True if we're recording lines.
19771 Otherwise we're building partial symtabs and are just interested in
19772 finding include files mentioned by the line number program. */
19773 bool m_record_lines_p
;
19775 /* The line number header. */
19776 line_header
*m_line_header
;
19778 /* These are part of the standard DWARF line number state machine,
19779 and initialized according to the DWARF spec. */
19781 unsigned char m_op_index
= 0;
19782 /* The line table index of the current file. */
19783 file_name_index m_file
= 1;
19784 unsigned int m_line
= 1;
19786 /* These are initialized in the constructor. */
19788 CORE_ADDR m_address
;
19790 unsigned int m_discriminator
;
19792 /* Additional bits of state we need to track. */
19794 /* The last file that we called dwarf2_start_subfile for.
19795 This is only used for TLLs. */
19796 unsigned int m_last_file
= 0;
19797 /* The last file a line number was recorded for. */
19798 struct subfile
*m_last_subfile
= NULL
;
19800 /* When true, record the lines we decode. */
19801 bool m_currently_recording_lines
= false;
19803 /* The last line number that was recorded, used to coalesce
19804 consecutive entries for the same line. This can happen, for
19805 example, when discriminators are present. PR 17276. */
19806 unsigned int m_last_line
= 0;
19807 bool m_line_has_non_zero_discriminator
= false;
19811 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19813 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19814 / m_line_header
->maximum_ops_per_instruction
)
19815 * m_line_header
->minimum_instruction_length
);
19816 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19817 m_op_index
= ((m_op_index
+ adjust
)
19818 % m_line_header
->maximum_ops_per_instruction
);
19822 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19824 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19825 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19826 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19827 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19828 / m_line_header
->maximum_ops_per_instruction
)
19829 * m_line_header
->minimum_instruction_length
);
19830 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19831 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19832 % m_line_header
->maximum_ops_per_instruction
);
19834 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19835 advance_line (line_delta
);
19836 record_line (false);
19837 m_discriminator
= 0;
19841 lnp_state_machine::handle_set_file (file_name_index file
)
19845 const file_entry
*fe
= current_file ();
19847 dwarf2_debug_line_missing_file_complaint ();
19848 else if (m_record_lines_p
)
19850 const char *dir
= fe
->include_dir (m_line_header
);
19852 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19853 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19854 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19859 lnp_state_machine::handle_const_add_pc ()
19862 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19865 = (((m_op_index
+ adjust
)
19866 / m_line_header
->maximum_ops_per_instruction
)
19867 * m_line_header
->minimum_instruction_length
);
19869 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19870 m_op_index
= ((m_op_index
+ adjust
)
19871 % m_line_header
->maximum_ops_per_instruction
);
19874 /* Return non-zero if we should add LINE to the line number table.
19875 LINE is the line to add, LAST_LINE is the last line that was added,
19876 LAST_SUBFILE is the subfile for LAST_LINE.
19877 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19878 had a non-zero discriminator.
19880 We have to be careful in the presence of discriminators.
19881 E.g., for this line:
19883 for (i = 0; i < 100000; i++);
19885 clang can emit four line number entries for that one line,
19886 each with a different discriminator.
19887 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19889 However, we want gdb to coalesce all four entries into one.
19890 Otherwise the user could stepi into the middle of the line and
19891 gdb would get confused about whether the pc really was in the
19892 middle of the line.
19894 Things are further complicated by the fact that two consecutive
19895 line number entries for the same line is a heuristic used by gcc
19896 to denote the end of the prologue. So we can't just discard duplicate
19897 entries, we have to be selective about it. The heuristic we use is
19898 that we only collapse consecutive entries for the same line if at least
19899 one of those entries has a non-zero discriminator. PR 17276.
19901 Note: Addresses in the line number state machine can never go backwards
19902 within one sequence, thus this coalescing is ok. */
19905 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19906 unsigned int line
, unsigned int last_line
,
19907 int line_has_non_zero_discriminator
,
19908 struct subfile
*last_subfile
)
19910 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19912 if (line
!= last_line
)
19914 /* Same line for the same file that we've seen already.
19915 As a last check, for pr 17276, only record the line if the line
19916 has never had a non-zero discriminator. */
19917 if (!line_has_non_zero_discriminator
)
19922 /* Use the CU's builder to record line number LINE beginning at
19923 address ADDRESS in the line table of subfile SUBFILE. */
19926 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19927 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19928 struct dwarf2_cu
*cu
)
19930 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19932 if (dwarf_line_debug
)
19934 fprintf_unfiltered (gdb_stdlog
,
19935 "Recording line %u, file %s, address %s\n",
19936 line
, lbasename (subfile
->name
),
19937 paddress (gdbarch
, address
));
19941 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19944 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19945 Mark the end of a set of line number records.
19946 The arguments are the same as for dwarf_record_line_1.
19947 If SUBFILE is NULL the request is ignored. */
19950 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19951 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19953 if (subfile
== NULL
)
19956 if (dwarf_line_debug
)
19958 fprintf_unfiltered (gdb_stdlog
,
19959 "Finishing current line, file %s, address %s\n",
19960 lbasename (subfile
->name
),
19961 paddress (gdbarch
, address
));
19964 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19968 lnp_state_machine::record_line (bool end_sequence
)
19970 if (dwarf_line_debug
)
19972 fprintf_unfiltered (gdb_stdlog
,
19973 "Processing actual line %u: file %u,"
19974 " address %s, is_stmt %u, discrim %u%s\n",
19976 paddress (m_gdbarch
, m_address
),
19977 m_is_stmt
, m_discriminator
,
19978 (end_sequence
? "\t(end sequence)" : ""));
19981 file_entry
*fe
= current_file ();
19984 dwarf2_debug_line_missing_file_complaint ();
19985 /* For now we ignore lines not starting on an instruction boundary.
19986 But not when processing end_sequence for compatibility with the
19987 previous version of the code. */
19988 else if (m_op_index
== 0 || end_sequence
)
19990 fe
->included_p
= 1;
19991 if (m_record_lines_p
)
19993 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19996 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19997 m_currently_recording_lines
? m_cu
: nullptr);
20002 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20004 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20005 m_line_has_non_zero_discriminator
,
20008 buildsym_compunit
*builder
= m_cu
->get_builder ();
20009 dwarf_record_line_1 (m_gdbarch
,
20010 builder
->get_current_subfile (),
20011 m_line
, m_address
, is_stmt
,
20012 m_currently_recording_lines
? m_cu
: nullptr);
20014 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20015 m_last_line
= m_line
;
20021 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20022 line_header
*lh
, bool record_lines_p
)
20026 m_record_lines_p
= record_lines_p
;
20027 m_line_header
= lh
;
20029 m_currently_recording_lines
= true;
20031 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20032 was a line entry for it so that the backend has a chance to adjust it
20033 and also record it in case it needs it. This is currently used by MIPS
20034 code, cf. `mips_adjust_dwarf2_line'. */
20035 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20036 m_is_stmt
= lh
->default_is_stmt
;
20037 m_discriminator
= 0;
20041 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20042 const gdb_byte
*line_ptr
,
20043 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20045 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20046 the pc range of the CU. However, we restrict the test to only ADDRESS
20047 values of zero to preserve GDB's previous behaviour which is to handle
20048 the specific case of a function being GC'd by the linker. */
20050 if (address
== 0 && address
< unrelocated_lowpc
)
20052 /* This line table is for a function which has been
20053 GCd by the linker. Ignore it. PR gdb/12528 */
20055 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20056 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20058 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20059 line_offset
, objfile_name (objfile
));
20060 m_currently_recording_lines
= false;
20061 /* Note: m_currently_recording_lines is left as false until we see
20062 DW_LNE_end_sequence. */
20066 /* Subroutine of dwarf_decode_lines to simplify it.
20067 Process the line number information in LH.
20068 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20069 program in order to set included_p for every referenced header. */
20072 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20073 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20075 const gdb_byte
*line_ptr
, *extended_end
;
20076 const gdb_byte
*line_end
;
20077 unsigned int bytes_read
, extended_len
;
20078 unsigned char op_code
, extended_op
;
20079 CORE_ADDR baseaddr
;
20080 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20081 bfd
*abfd
= objfile
->obfd
;
20082 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20083 /* True if we're recording line info (as opposed to building partial
20084 symtabs and just interested in finding include files mentioned by
20085 the line number program). */
20086 bool record_lines_p
= !decode_for_pst_p
;
20088 baseaddr
= objfile
->text_section_offset ();
20090 line_ptr
= lh
->statement_program_start
;
20091 line_end
= lh
->statement_program_end
;
20093 /* Read the statement sequences until there's nothing left. */
20094 while (line_ptr
< line_end
)
20096 /* The DWARF line number program state machine. Reset the state
20097 machine at the start of each sequence. */
20098 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20099 bool end_sequence
= false;
20101 if (record_lines_p
)
20103 /* Start a subfile for the current file of the state
20105 const file_entry
*fe
= state_machine
.current_file ();
20108 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20111 /* Decode the table. */
20112 while (line_ptr
< line_end
&& !end_sequence
)
20114 op_code
= read_1_byte (abfd
, line_ptr
);
20117 if (op_code
>= lh
->opcode_base
)
20119 /* Special opcode. */
20120 state_machine
.handle_special_opcode (op_code
);
20122 else switch (op_code
)
20124 case DW_LNS_extended_op
:
20125 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20127 line_ptr
+= bytes_read
;
20128 extended_end
= line_ptr
+ extended_len
;
20129 extended_op
= read_1_byte (abfd
, line_ptr
);
20131 switch (extended_op
)
20133 case DW_LNE_end_sequence
:
20134 state_machine
.handle_end_sequence ();
20135 end_sequence
= true;
20137 case DW_LNE_set_address
:
20140 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20141 line_ptr
+= bytes_read
;
20143 state_machine
.check_line_address (cu
, line_ptr
,
20144 lowpc
- baseaddr
, address
);
20145 state_machine
.handle_set_address (baseaddr
, address
);
20148 case DW_LNE_define_file
:
20150 const char *cur_file
;
20151 unsigned int mod_time
, length
;
20154 cur_file
= read_direct_string (abfd
, line_ptr
,
20156 line_ptr
+= bytes_read
;
20157 dindex
= (dir_index
)
20158 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20159 line_ptr
+= bytes_read
;
20161 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20162 line_ptr
+= bytes_read
;
20164 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20165 line_ptr
+= bytes_read
;
20166 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20169 case DW_LNE_set_discriminator
:
20171 /* The discriminator is not interesting to the
20172 debugger; just ignore it. We still need to
20173 check its value though:
20174 if there are consecutive entries for the same
20175 (non-prologue) line we want to coalesce them.
20178 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20179 line_ptr
+= bytes_read
;
20181 state_machine
.handle_set_discriminator (discr
);
20185 complaint (_("mangled .debug_line section"));
20188 /* Make sure that we parsed the extended op correctly. If e.g.
20189 we expected a different address size than the producer used,
20190 we may have read the wrong number of bytes. */
20191 if (line_ptr
!= extended_end
)
20193 complaint (_("mangled .debug_line section"));
20198 state_machine
.handle_copy ();
20200 case DW_LNS_advance_pc
:
20203 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20204 line_ptr
+= bytes_read
;
20206 state_machine
.handle_advance_pc (adjust
);
20209 case DW_LNS_advance_line
:
20212 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20213 line_ptr
+= bytes_read
;
20215 state_machine
.handle_advance_line (line_delta
);
20218 case DW_LNS_set_file
:
20220 file_name_index file
20221 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20223 line_ptr
+= bytes_read
;
20225 state_machine
.handle_set_file (file
);
20228 case DW_LNS_set_column
:
20229 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20230 line_ptr
+= bytes_read
;
20232 case DW_LNS_negate_stmt
:
20233 state_machine
.handle_negate_stmt ();
20235 case DW_LNS_set_basic_block
:
20237 /* Add to the address register of the state machine the
20238 address increment value corresponding to special opcode
20239 255. I.e., this value is scaled by the minimum
20240 instruction length since special opcode 255 would have
20241 scaled the increment. */
20242 case DW_LNS_const_add_pc
:
20243 state_machine
.handle_const_add_pc ();
20245 case DW_LNS_fixed_advance_pc
:
20247 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20250 state_machine
.handle_fixed_advance_pc (addr_adj
);
20255 /* Unknown standard opcode, ignore it. */
20258 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20260 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20261 line_ptr
+= bytes_read
;
20268 dwarf2_debug_line_missing_end_sequence_complaint ();
20270 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20271 in which case we still finish recording the last line). */
20272 state_machine
.record_line (true);
20276 /* Decode the Line Number Program (LNP) for the given line_header
20277 structure and CU. The actual information extracted and the type
20278 of structures created from the LNP depends on the value of PST.
20280 1. If PST is NULL, then this procedure uses the data from the program
20281 to create all necessary symbol tables, and their linetables.
20283 2. If PST is not NULL, this procedure reads the program to determine
20284 the list of files included by the unit represented by PST, and
20285 builds all the associated partial symbol tables.
20287 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20288 It is used for relative paths in the line table.
20289 NOTE: When processing partial symtabs (pst != NULL),
20290 comp_dir == pst->dirname.
20292 NOTE: It is important that psymtabs have the same file name (via strcmp)
20293 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20294 symtab we don't use it in the name of the psymtabs we create.
20295 E.g. expand_line_sal requires this when finding psymtabs to expand.
20296 A good testcase for this is mb-inline.exp.
20298 LOWPC is the lowest address in CU (or 0 if not known).
20300 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20301 for its PC<->lines mapping information. Otherwise only the filename
20302 table is read in. */
20305 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20306 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20307 CORE_ADDR lowpc
, int decode_mapping
)
20309 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20310 const int decode_for_pst_p
= (pst
!= NULL
);
20312 if (decode_mapping
)
20313 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20315 if (decode_for_pst_p
)
20317 /* Now that we're done scanning the Line Header Program, we can
20318 create the psymtab of each included file. */
20319 for (auto &file_entry
: lh
->file_names ())
20320 if (file_entry
.included_p
== 1)
20322 gdb::unique_xmalloc_ptr
<char> name_holder
;
20323 const char *include_name
=
20324 psymtab_include_file_name (lh
, file_entry
, pst
,
20325 comp_dir
, &name_holder
);
20326 if (include_name
!= NULL
)
20327 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20332 /* Make sure a symtab is created for every file, even files
20333 which contain only variables (i.e. no code with associated
20335 buildsym_compunit
*builder
= cu
->get_builder ();
20336 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20338 for (auto &fe
: lh
->file_names ())
20340 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20341 if (builder
->get_current_subfile ()->symtab
== NULL
)
20343 builder
->get_current_subfile ()->symtab
20344 = allocate_symtab (cust
,
20345 builder
->get_current_subfile ()->name
);
20347 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20352 /* Start a subfile for DWARF. FILENAME is the name of the file and
20353 DIRNAME the name of the source directory which contains FILENAME
20354 or NULL if not known.
20355 This routine tries to keep line numbers from identical absolute and
20356 relative file names in a common subfile.
20358 Using the `list' example from the GDB testsuite, which resides in
20359 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20360 of /srcdir/list0.c yields the following debugging information for list0.c:
20362 DW_AT_name: /srcdir/list0.c
20363 DW_AT_comp_dir: /compdir
20364 files.files[0].name: list0.h
20365 files.files[0].dir: /srcdir
20366 files.files[1].name: list0.c
20367 files.files[1].dir: /srcdir
20369 The line number information for list0.c has to end up in a single
20370 subfile, so that `break /srcdir/list0.c:1' works as expected.
20371 start_subfile will ensure that this happens provided that we pass the
20372 concatenation of files.files[1].dir and files.files[1].name as the
20376 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20377 const char *dirname
)
20379 gdb::unique_xmalloc_ptr
<char> copy
;
20381 /* In order not to lose the line information directory,
20382 we concatenate it to the filename when it makes sense.
20383 Note that the Dwarf3 standard says (speaking of filenames in line
20384 information): ``The directory index is ignored for file names
20385 that represent full path names''. Thus ignoring dirname in the
20386 `else' branch below isn't an issue. */
20388 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20390 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20391 filename
= copy
.get ();
20394 cu
->get_builder ()->start_subfile (filename
);
20397 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20398 buildsym_compunit constructor. */
20400 struct compunit_symtab
*
20401 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20404 gdb_assert (m_builder
== nullptr);
20406 m_builder
.reset (new struct buildsym_compunit
20407 (per_cu
->dwarf2_per_objfile
->objfile
,
20408 name
, comp_dir
, language
, low_pc
));
20410 list_in_scope
= get_builder ()->get_file_symbols ();
20412 get_builder ()->record_debugformat ("DWARF 2");
20413 get_builder ()->record_producer (producer
);
20415 processing_has_namespace_info
= false;
20417 return get_builder ()->get_compunit_symtab ();
20421 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20422 struct dwarf2_cu
*cu
)
20424 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20425 struct comp_unit_head
*cu_header
= &cu
->header
;
20427 /* NOTE drow/2003-01-30: There used to be a comment and some special
20428 code here to turn a symbol with DW_AT_external and a
20429 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20430 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20431 with some versions of binutils) where shared libraries could have
20432 relocations against symbols in their debug information - the
20433 minimal symbol would have the right address, but the debug info
20434 would not. It's no longer necessary, because we will explicitly
20435 apply relocations when we read in the debug information now. */
20437 /* A DW_AT_location attribute with no contents indicates that a
20438 variable has been optimized away. */
20439 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20441 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20445 /* Handle one degenerate form of location expression specially, to
20446 preserve GDB's previous behavior when section offsets are
20447 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20448 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20450 if (attr
->form_is_block ()
20451 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20452 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20453 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20454 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20455 && (DW_BLOCK (attr
)->size
20456 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20458 unsigned int dummy
;
20460 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20461 SET_SYMBOL_VALUE_ADDRESS
20462 (sym
, cu
->header
.read_address (objfile
->obfd
,
20463 DW_BLOCK (attr
)->data
+ 1,
20466 SET_SYMBOL_VALUE_ADDRESS
20467 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20469 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20470 fixup_symbol_section (sym
, objfile
);
20471 SET_SYMBOL_VALUE_ADDRESS
20473 SYMBOL_VALUE_ADDRESS (sym
)
20474 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20478 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20479 expression evaluator, and use LOC_COMPUTED only when necessary
20480 (i.e. when the value of a register or memory location is
20481 referenced, or a thread-local block, etc.). Then again, it might
20482 not be worthwhile. I'm assuming that it isn't unless performance
20483 or memory numbers show me otherwise. */
20485 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20487 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20488 cu
->has_loclist
= true;
20491 /* Given a pointer to a DWARF information entry, figure out if we need
20492 to make a symbol table entry for it, and if so, create a new entry
20493 and return a pointer to it.
20494 If TYPE is NULL, determine symbol type from the die, otherwise
20495 used the passed type.
20496 If SPACE is not NULL, use it to hold the new symbol. If it is
20497 NULL, allocate a new symbol on the objfile's obstack. */
20499 static struct symbol
*
20500 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20501 struct symbol
*space
)
20503 struct dwarf2_per_objfile
*dwarf2_per_objfile
20504 = cu
->per_cu
->dwarf2_per_objfile
;
20505 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20506 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20507 struct symbol
*sym
= NULL
;
20509 struct attribute
*attr
= NULL
;
20510 struct attribute
*attr2
= NULL
;
20511 CORE_ADDR baseaddr
;
20512 struct pending
**list_to_add
= NULL
;
20514 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20516 baseaddr
= objfile
->text_section_offset ();
20518 name
= dwarf2_name (die
, cu
);
20521 const char *linkagename
;
20522 int suppress_add
= 0;
20527 sym
= allocate_symbol (objfile
);
20528 OBJSTAT (objfile
, n_syms
++);
20530 /* Cache this symbol's name and the name's demangled form (if any). */
20531 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20532 linkagename
= dwarf2_physname (name
, die
, cu
);
20533 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20535 /* Fortran does not have mangling standard and the mangling does differ
20536 between gfortran, iFort etc. */
20537 if (cu
->language
== language_fortran
20538 && symbol_get_demangled_name (sym
) == NULL
)
20539 symbol_set_demangled_name (sym
,
20540 dwarf2_full_name (name
, die
, cu
),
20543 /* Default assumptions.
20544 Use the passed type or decode it from the die. */
20545 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20546 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20548 SYMBOL_TYPE (sym
) = type
;
20550 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20551 attr
= dwarf2_attr (die
,
20552 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20554 if (attr
!= nullptr)
20556 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20559 attr
= dwarf2_attr (die
,
20560 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20562 if (attr
!= nullptr)
20564 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20565 struct file_entry
*fe
;
20567 if (cu
->line_header
!= NULL
)
20568 fe
= cu
->line_header
->file_name_at (file_index
);
20573 complaint (_("file index out of range"));
20575 symbol_set_symtab (sym
, fe
->symtab
);
20581 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20582 if (attr
!= nullptr)
20586 addr
= attr
->value_as_address ();
20587 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20588 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20590 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20591 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20592 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20593 add_symbol_to_list (sym
, cu
->list_in_scope
);
20595 case DW_TAG_subprogram
:
20596 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20598 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20599 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20600 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20601 || cu
->language
== language_ada
20602 || cu
->language
== language_fortran
)
20604 /* Subprograms marked external are stored as a global symbol.
20605 Ada and Fortran subprograms, whether marked external or
20606 not, are always stored as a global symbol, because we want
20607 to be able to access them globally. For instance, we want
20608 to be able to break on a nested subprogram without having
20609 to specify the context. */
20610 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20614 list_to_add
= cu
->list_in_scope
;
20617 case DW_TAG_inlined_subroutine
:
20618 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20620 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20621 SYMBOL_INLINED (sym
) = 1;
20622 list_to_add
= cu
->list_in_scope
;
20624 case DW_TAG_template_value_param
:
20626 /* Fall through. */
20627 case DW_TAG_constant
:
20628 case DW_TAG_variable
:
20629 case DW_TAG_member
:
20630 /* Compilation with minimal debug info may result in
20631 variables with missing type entries. Change the
20632 misleading `void' type to something sensible. */
20633 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20634 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20636 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20637 /* In the case of DW_TAG_member, we should only be called for
20638 static const members. */
20639 if (die
->tag
== DW_TAG_member
)
20641 /* dwarf2_add_field uses die_is_declaration,
20642 so we do the same. */
20643 gdb_assert (die_is_declaration (die
, cu
));
20646 if (attr
!= nullptr)
20648 dwarf2_const_value (attr
, sym
, cu
);
20649 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20652 if (attr2
&& (DW_UNSND (attr2
) != 0))
20653 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20655 list_to_add
= cu
->list_in_scope
;
20659 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20660 if (attr
!= nullptr)
20662 var_decode_location (attr
, sym
, cu
);
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
)
20671 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20672 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20673 && !dwarf2_per_objfile
->has_section_at_zero
)
20675 /* When a static variable is eliminated by the linker,
20676 the corresponding debug information is not stripped
20677 out, but the variable address is set to null;
20678 do not add such variables into symbol table. */
20680 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20682 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20683 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20684 && dwarf2_per_objfile
->can_copy
)
20686 /* A global static variable might be subject to
20687 copy relocation. We first check for a local
20688 minsym, though, because maybe the symbol was
20689 marked hidden, in which case this would not
20691 bound_minimal_symbol found
20692 = (lookup_minimal_symbol_linkage
20693 (sym
->linkage_name (), objfile
));
20694 if (found
.minsym
!= nullptr)
20695 sym
->maybe_copied
= 1;
20698 /* A variable with DW_AT_external is never static,
20699 but it may be block-scoped. */
20701 = ((cu
->list_in_scope
20702 == cu
->get_builder ()->get_file_symbols ())
20703 ? cu
->get_builder ()->get_global_symbols ()
20704 : cu
->list_in_scope
);
20707 list_to_add
= cu
->list_in_scope
;
20711 /* We do not know the address of this symbol.
20712 If it is an external symbol and we have type information
20713 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20714 The address of the variable will then be determined from
20715 the minimal symbol table whenever the variable is
20717 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20719 /* Fortran explicitly imports any global symbols to the local
20720 scope by DW_TAG_common_block. */
20721 if (cu
->language
== language_fortran
&& die
->parent
20722 && die
->parent
->tag
== DW_TAG_common_block
)
20724 /* SYMBOL_CLASS doesn't matter here because
20725 read_common_block is going to reset it. */
20727 list_to_add
= cu
->list_in_scope
;
20729 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20730 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20732 /* A variable with DW_AT_external is never static, but it
20733 may be block-scoped. */
20735 = ((cu
->list_in_scope
20736 == cu
->get_builder ()->get_file_symbols ())
20737 ? cu
->get_builder ()->get_global_symbols ()
20738 : cu
->list_in_scope
);
20740 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20742 else if (!die_is_declaration (die
, cu
))
20744 /* Use the default LOC_OPTIMIZED_OUT class. */
20745 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20747 list_to_add
= cu
->list_in_scope
;
20751 case DW_TAG_formal_parameter
:
20753 /* If we are inside a function, mark this as an argument. If
20754 not, we might be looking at an argument to an inlined function
20755 when we do not have enough information to show inlined frames;
20756 pretend it's a local variable in that case so that the user can
20758 struct context_stack
*curr
20759 = cu
->get_builder ()->get_current_context_stack ();
20760 if (curr
!= nullptr && curr
->name
!= nullptr)
20761 SYMBOL_IS_ARGUMENT (sym
) = 1;
20762 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20763 if (attr
!= nullptr)
20765 var_decode_location (attr
, sym
, cu
);
20767 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20768 if (attr
!= nullptr)
20770 dwarf2_const_value (attr
, sym
, cu
);
20773 list_to_add
= cu
->list_in_scope
;
20776 case DW_TAG_unspecified_parameters
:
20777 /* From varargs functions; gdb doesn't seem to have any
20778 interest in this information, so just ignore it for now.
20781 case DW_TAG_template_type_param
:
20783 /* Fall through. */
20784 case DW_TAG_class_type
:
20785 case DW_TAG_interface_type
:
20786 case DW_TAG_structure_type
:
20787 case DW_TAG_union_type
:
20788 case DW_TAG_set_type
:
20789 case DW_TAG_enumeration_type
:
20790 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20791 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20794 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20795 really ever be static objects: otherwise, if you try
20796 to, say, break of a class's method and you're in a file
20797 which doesn't mention that class, it won't work unless
20798 the check for all static symbols in lookup_symbol_aux
20799 saves you. See the OtherFileClass tests in
20800 gdb.c++/namespace.exp. */
20804 buildsym_compunit
*builder
= cu
->get_builder ();
20806 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20807 && cu
->language
== language_cplus
20808 ? builder
->get_global_symbols ()
20809 : cu
->list_in_scope
);
20811 /* The semantics of C++ state that "struct foo {
20812 ... }" also defines a typedef for "foo". */
20813 if (cu
->language
== language_cplus
20814 || cu
->language
== language_ada
20815 || cu
->language
== language_d
20816 || cu
->language
== language_rust
)
20818 /* The symbol's name is already allocated along
20819 with this objfile, so we don't need to
20820 duplicate it for the type. */
20821 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20822 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20827 case DW_TAG_typedef
:
20828 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20829 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20830 list_to_add
= cu
->list_in_scope
;
20832 case DW_TAG_base_type
:
20833 case DW_TAG_subrange_type
:
20834 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20835 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20836 list_to_add
= cu
->list_in_scope
;
20838 case DW_TAG_enumerator
:
20839 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20840 if (attr
!= nullptr)
20842 dwarf2_const_value (attr
, sym
, cu
);
20845 /* NOTE: carlton/2003-11-10: See comment above in the
20846 DW_TAG_class_type, etc. block. */
20849 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20850 && cu
->language
== language_cplus
20851 ? cu
->get_builder ()->get_global_symbols ()
20852 : cu
->list_in_scope
);
20855 case DW_TAG_imported_declaration
:
20856 case DW_TAG_namespace
:
20857 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20858 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20860 case DW_TAG_module
:
20861 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20862 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20863 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20865 case DW_TAG_common_block
:
20866 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20867 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20868 add_symbol_to_list (sym
, cu
->list_in_scope
);
20871 /* Not a tag we recognize. Hopefully we aren't processing
20872 trash data, but since we must specifically ignore things
20873 we don't recognize, there is nothing else we should do at
20875 complaint (_("unsupported tag: '%s'"),
20876 dwarf_tag_name (die
->tag
));
20882 sym
->hash_next
= objfile
->template_symbols
;
20883 objfile
->template_symbols
= sym
;
20884 list_to_add
= NULL
;
20887 if (list_to_add
!= NULL
)
20888 add_symbol_to_list (sym
, list_to_add
);
20890 /* For the benefit of old versions of GCC, check for anonymous
20891 namespaces based on the demangled name. */
20892 if (!cu
->processing_has_namespace_info
20893 && cu
->language
== language_cplus
)
20894 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20899 /* Given an attr with a DW_FORM_dataN value in host byte order,
20900 zero-extend it as appropriate for the symbol's type. The DWARF
20901 standard (v4) is not entirely clear about the meaning of using
20902 DW_FORM_dataN for a constant with a signed type, where the type is
20903 wider than the data. The conclusion of a discussion on the DWARF
20904 list was that this is unspecified. We choose to always zero-extend
20905 because that is the interpretation long in use by GCC. */
20908 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20909 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20911 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20912 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20913 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20914 LONGEST l
= DW_UNSND (attr
);
20916 if (bits
< sizeof (*value
) * 8)
20918 l
&= ((LONGEST
) 1 << bits
) - 1;
20921 else if (bits
== sizeof (*value
) * 8)
20925 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20926 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20933 /* Read a constant value from an attribute. Either set *VALUE, or if
20934 the value does not fit in *VALUE, set *BYTES - either already
20935 allocated on the objfile obstack, or newly allocated on OBSTACK,
20936 or, set *BATON, if we translated the constant to a location
20940 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20941 const char *name
, struct obstack
*obstack
,
20942 struct dwarf2_cu
*cu
,
20943 LONGEST
*value
, const gdb_byte
**bytes
,
20944 struct dwarf2_locexpr_baton
**baton
)
20946 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20947 struct comp_unit_head
*cu_header
= &cu
->header
;
20948 struct dwarf_block
*blk
;
20949 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20950 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20956 switch (attr
->form
)
20959 case DW_FORM_addrx
:
20960 case DW_FORM_GNU_addr_index
:
20964 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20965 dwarf2_const_value_length_mismatch_complaint (name
,
20966 cu_header
->addr_size
,
20967 TYPE_LENGTH (type
));
20968 /* Symbols of this form are reasonably rare, so we just
20969 piggyback on the existing location code rather than writing
20970 a new implementation of symbol_computed_ops. */
20971 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20972 (*baton
)->per_cu
= cu
->per_cu
;
20973 gdb_assert ((*baton
)->per_cu
);
20975 (*baton
)->size
= 2 + cu_header
->addr_size
;
20976 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20977 (*baton
)->data
= data
;
20979 data
[0] = DW_OP_addr
;
20980 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20981 byte_order
, DW_ADDR (attr
));
20982 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20985 case DW_FORM_string
:
20988 case DW_FORM_GNU_str_index
:
20989 case DW_FORM_GNU_strp_alt
:
20990 /* DW_STRING is already allocated on the objfile obstack, point
20992 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20994 case DW_FORM_block1
:
20995 case DW_FORM_block2
:
20996 case DW_FORM_block4
:
20997 case DW_FORM_block
:
20998 case DW_FORM_exprloc
:
20999 case DW_FORM_data16
:
21000 blk
= DW_BLOCK (attr
);
21001 if (TYPE_LENGTH (type
) != blk
->size
)
21002 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21003 TYPE_LENGTH (type
));
21004 *bytes
= blk
->data
;
21007 /* The DW_AT_const_value attributes are supposed to carry the
21008 symbol's value "represented as it would be on the target
21009 architecture." By the time we get here, it's already been
21010 converted to host endianness, so we just need to sign- or
21011 zero-extend it as appropriate. */
21012 case DW_FORM_data1
:
21013 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21015 case DW_FORM_data2
:
21016 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21018 case DW_FORM_data4
:
21019 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21021 case DW_FORM_data8
:
21022 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21025 case DW_FORM_sdata
:
21026 case DW_FORM_implicit_const
:
21027 *value
= DW_SND (attr
);
21030 case DW_FORM_udata
:
21031 *value
= DW_UNSND (attr
);
21035 complaint (_("unsupported const value attribute form: '%s'"),
21036 dwarf_form_name (attr
->form
));
21043 /* Copy constant value from an attribute to a symbol. */
21046 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21047 struct dwarf2_cu
*cu
)
21049 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21051 const gdb_byte
*bytes
;
21052 struct dwarf2_locexpr_baton
*baton
;
21054 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21055 sym
->print_name (),
21056 &objfile
->objfile_obstack
, cu
,
21057 &value
, &bytes
, &baton
);
21061 SYMBOL_LOCATION_BATON (sym
) = baton
;
21062 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21064 else if (bytes
!= NULL
)
21066 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21067 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21071 SYMBOL_VALUE (sym
) = value
;
21072 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21076 /* Return the type of the die in question using its DW_AT_type attribute. */
21078 static struct type
*
21079 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21081 struct attribute
*type_attr
;
21083 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21086 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21087 /* A missing DW_AT_type represents a void type. */
21088 return objfile_type (objfile
)->builtin_void
;
21091 return lookup_die_type (die
, type_attr
, cu
);
21094 /* True iff CU's producer generates GNAT Ada auxiliary information
21095 that allows to find parallel types through that information instead
21096 of having to do expensive parallel lookups by type name. */
21099 need_gnat_info (struct dwarf2_cu
*cu
)
21101 /* Assume that the Ada compiler was GNAT, which always produces
21102 the auxiliary information. */
21103 return (cu
->language
== language_ada
);
21106 /* Return the auxiliary type of the die in question using its
21107 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21108 attribute is not present. */
21110 static struct type
*
21111 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21113 struct attribute
*type_attr
;
21115 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21119 return lookup_die_type (die
, type_attr
, cu
);
21122 /* If DIE has a descriptive_type attribute, then set the TYPE's
21123 descriptive type accordingly. */
21126 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21127 struct dwarf2_cu
*cu
)
21129 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21131 if (descriptive_type
)
21133 ALLOCATE_GNAT_AUX_TYPE (type
);
21134 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21138 /* Return the containing type of the die in question using its
21139 DW_AT_containing_type attribute. */
21141 static struct type
*
21142 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21144 struct attribute
*type_attr
;
21145 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21147 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21149 error (_("Dwarf Error: Problem turning containing type into gdb type "
21150 "[in module %s]"), objfile_name (objfile
));
21152 return lookup_die_type (die
, type_attr
, cu
);
21155 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21157 static struct type
*
21158 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21160 struct dwarf2_per_objfile
*dwarf2_per_objfile
21161 = cu
->per_cu
->dwarf2_per_objfile
;
21162 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21165 std::string message
21166 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21167 objfile_name (objfile
),
21168 sect_offset_str (cu
->header
.sect_off
),
21169 sect_offset_str (die
->sect_off
));
21170 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21172 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21175 /* Look up the type of DIE in CU using its type attribute ATTR.
21176 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21177 DW_AT_containing_type.
21178 If there is no type substitute an error marker. */
21180 static struct type
*
21181 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21182 struct dwarf2_cu
*cu
)
21184 struct dwarf2_per_objfile
*dwarf2_per_objfile
21185 = cu
->per_cu
->dwarf2_per_objfile
;
21186 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21187 struct type
*this_type
;
21189 gdb_assert (attr
->name
== DW_AT_type
21190 || attr
->name
== DW_AT_GNAT_descriptive_type
21191 || attr
->name
== DW_AT_containing_type
);
21193 /* First see if we have it cached. */
21195 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21197 struct dwarf2_per_cu_data
*per_cu
;
21198 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21200 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21201 dwarf2_per_objfile
);
21202 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21204 else if (attr
->form_is_ref ())
21206 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21208 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21210 else if (attr
->form
== DW_FORM_ref_sig8
)
21212 ULONGEST signature
= DW_SIGNATURE (attr
);
21214 return get_signatured_type (die
, signature
, cu
);
21218 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21219 " at %s [in module %s]"),
21220 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21221 objfile_name (objfile
));
21222 return build_error_marker_type (cu
, die
);
21225 /* If not cached we need to read it in. */
21227 if (this_type
== NULL
)
21229 struct die_info
*type_die
= NULL
;
21230 struct dwarf2_cu
*type_cu
= cu
;
21232 if (attr
->form_is_ref ())
21233 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21234 if (type_die
== NULL
)
21235 return build_error_marker_type (cu
, die
);
21236 /* If we find the type now, it's probably because the type came
21237 from an inter-CU reference and the type's CU got expanded before
21239 this_type
= read_type_die (type_die
, type_cu
);
21242 /* If we still don't have a type use an error marker. */
21244 if (this_type
== NULL
)
21245 return build_error_marker_type (cu
, die
);
21250 /* Return the type in DIE, CU.
21251 Returns NULL for invalid types.
21253 This first does a lookup in die_type_hash,
21254 and only reads the die in if necessary.
21256 NOTE: This can be called when reading in partial or full symbols. */
21258 static struct type
*
21259 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21261 struct type
*this_type
;
21263 this_type
= get_die_type (die
, cu
);
21267 return read_type_die_1 (die
, cu
);
21270 /* Read the type in DIE, CU.
21271 Returns NULL for invalid types. */
21273 static struct type
*
21274 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21276 struct type
*this_type
= NULL
;
21280 case DW_TAG_class_type
:
21281 case DW_TAG_interface_type
:
21282 case DW_TAG_structure_type
:
21283 case DW_TAG_union_type
:
21284 this_type
= read_structure_type (die
, cu
);
21286 case DW_TAG_enumeration_type
:
21287 this_type
= read_enumeration_type (die
, cu
);
21289 case DW_TAG_subprogram
:
21290 case DW_TAG_subroutine_type
:
21291 case DW_TAG_inlined_subroutine
:
21292 this_type
= read_subroutine_type (die
, cu
);
21294 case DW_TAG_array_type
:
21295 this_type
= read_array_type (die
, cu
);
21297 case DW_TAG_set_type
:
21298 this_type
= read_set_type (die
, cu
);
21300 case DW_TAG_pointer_type
:
21301 this_type
= read_tag_pointer_type (die
, cu
);
21303 case DW_TAG_ptr_to_member_type
:
21304 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21306 case DW_TAG_reference_type
:
21307 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21309 case DW_TAG_rvalue_reference_type
:
21310 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21312 case DW_TAG_const_type
:
21313 this_type
= read_tag_const_type (die
, cu
);
21315 case DW_TAG_volatile_type
:
21316 this_type
= read_tag_volatile_type (die
, cu
);
21318 case DW_TAG_restrict_type
:
21319 this_type
= read_tag_restrict_type (die
, cu
);
21321 case DW_TAG_string_type
:
21322 this_type
= read_tag_string_type (die
, cu
);
21324 case DW_TAG_typedef
:
21325 this_type
= read_typedef (die
, cu
);
21327 case DW_TAG_subrange_type
:
21328 this_type
= read_subrange_type (die
, cu
);
21330 case DW_TAG_base_type
:
21331 this_type
= read_base_type (die
, cu
);
21333 case DW_TAG_unspecified_type
:
21334 this_type
= read_unspecified_type (die
, cu
);
21336 case DW_TAG_namespace
:
21337 this_type
= read_namespace_type (die
, cu
);
21339 case DW_TAG_module
:
21340 this_type
= read_module_type (die
, cu
);
21342 case DW_TAG_atomic_type
:
21343 this_type
= read_tag_atomic_type (die
, cu
);
21346 complaint (_("unexpected tag in read_type_die: '%s'"),
21347 dwarf_tag_name (die
->tag
));
21354 /* See if we can figure out if the class lives in a namespace. We do
21355 this by looking for a member function; its demangled name will
21356 contain namespace info, if there is any.
21357 Return the computed name or NULL.
21358 Space for the result is allocated on the objfile's obstack.
21359 This is the full-die version of guess_partial_die_structure_name.
21360 In this case we know DIE has no useful parent. */
21362 static const char *
21363 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21365 struct die_info
*spec_die
;
21366 struct dwarf2_cu
*spec_cu
;
21367 struct die_info
*child
;
21368 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21371 spec_die
= die_specification (die
, &spec_cu
);
21372 if (spec_die
!= NULL
)
21378 for (child
= die
->child
;
21380 child
= child
->sibling
)
21382 if (child
->tag
== DW_TAG_subprogram
)
21384 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21386 if (linkage_name
!= NULL
)
21388 gdb::unique_xmalloc_ptr
<char> actual_name
21389 (language_class_name_from_physname (cu
->language_defn
,
21391 const char *name
= NULL
;
21393 if (actual_name
!= NULL
)
21395 const char *die_name
= dwarf2_name (die
, cu
);
21397 if (die_name
!= NULL
21398 && strcmp (die_name
, actual_name
.get ()) != 0)
21400 /* Strip off the class name from the full name.
21401 We want the prefix. */
21402 int die_name_len
= strlen (die_name
);
21403 int actual_name_len
= strlen (actual_name
.get ());
21404 const char *ptr
= actual_name
.get ();
21406 /* Test for '::' as a sanity check. */
21407 if (actual_name_len
> die_name_len
+ 2
21408 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21409 name
= obstack_strndup (
21410 &objfile
->per_bfd
->storage_obstack
,
21411 ptr
, actual_name_len
- die_name_len
- 2);
21422 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21423 prefix part in such case. See
21424 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21426 static const char *
21427 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21429 struct attribute
*attr
;
21432 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21433 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21436 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21439 attr
= dw2_linkage_name_attr (die
, cu
);
21440 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21443 /* dwarf2_name had to be already called. */
21444 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21446 /* Strip the base name, keep any leading namespaces/classes. */
21447 base
= strrchr (DW_STRING (attr
), ':');
21448 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21451 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21452 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21454 &base
[-1] - DW_STRING (attr
));
21457 /* Return the name of the namespace/class that DIE is defined within,
21458 or "" if we can't tell. The caller should not xfree the result.
21460 For example, if we're within the method foo() in the following
21470 then determine_prefix on foo's die will return "N::C". */
21472 static const char *
21473 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21475 struct dwarf2_per_objfile
*dwarf2_per_objfile
21476 = cu
->per_cu
->dwarf2_per_objfile
;
21477 struct die_info
*parent
, *spec_die
;
21478 struct dwarf2_cu
*spec_cu
;
21479 struct type
*parent_type
;
21480 const char *retval
;
21482 if (cu
->language
!= language_cplus
21483 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21484 && cu
->language
!= language_rust
)
21487 retval
= anonymous_struct_prefix (die
, cu
);
21491 /* We have to be careful in the presence of DW_AT_specification.
21492 For example, with GCC 3.4, given the code
21496 // Definition of N::foo.
21500 then we'll have a tree of DIEs like this:
21502 1: DW_TAG_compile_unit
21503 2: DW_TAG_namespace // N
21504 3: DW_TAG_subprogram // declaration of N::foo
21505 4: DW_TAG_subprogram // definition of N::foo
21506 DW_AT_specification // refers to die #3
21508 Thus, when processing die #4, we have to pretend that we're in
21509 the context of its DW_AT_specification, namely the contex of die
21512 spec_die
= die_specification (die
, &spec_cu
);
21513 if (spec_die
== NULL
)
21514 parent
= die
->parent
;
21517 parent
= spec_die
->parent
;
21521 if (parent
== NULL
)
21523 else if (parent
->building_fullname
)
21526 const char *parent_name
;
21528 /* It has been seen on RealView 2.2 built binaries,
21529 DW_TAG_template_type_param types actually _defined_ as
21530 children of the parent class:
21533 template class <class Enum> Class{};
21534 Class<enum E> class_e;
21536 1: DW_TAG_class_type (Class)
21537 2: DW_TAG_enumeration_type (E)
21538 3: DW_TAG_enumerator (enum1:0)
21539 3: DW_TAG_enumerator (enum2:1)
21541 2: DW_TAG_template_type_param
21542 DW_AT_type DW_FORM_ref_udata (E)
21544 Besides being broken debug info, it can put GDB into an
21545 infinite loop. Consider:
21547 When we're building the full name for Class<E>, we'll start
21548 at Class, and go look over its template type parameters,
21549 finding E. We'll then try to build the full name of E, and
21550 reach here. We're now trying to build the full name of E,
21551 and look over the parent DIE for containing scope. In the
21552 broken case, if we followed the parent DIE of E, we'd again
21553 find Class, and once again go look at its template type
21554 arguments, etc., etc. Simply don't consider such parent die
21555 as source-level parent of this die (it can't be, the language
21556 doesn't allow it), and break the loop here. */
21557 name
= dwarf2_name (die
, cu
);
21558 parent_name
= dwarf2_name (parent
, cu
);
21559 complaint (_("template param type '%s' defined within parent '%s'"),
21560 name
? name
: "<unknown>",
21561 parent_name
? parent_name
: "<unknown>");
21565 switch (parent
->tag
)
21567 case DW_TAG_namespace
:
21568 parent_type
= read_type_die (parent
, cu
);
21569 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21570 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21571 Work around this problem here. */
21572 if (cu
->language
== language_cplus
21573 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21575 /* We give a name to even anonymous namespaces. */
21576 return TYPE_NAME (parent_type
);
21577 case DW_TAG_class_type
:
21578 case DW_TAG_interface_type
:
21579 case DW_TAG_structure_type
:
21580 case DW_TAG_union_type
:
21581 case DW_TAG_module
:
21582 parent_type
= read_type_die (parent
, cu
);
21583 if (TYPE_NAME (parent_type
) != NULL
)
21584 return TYPE_NAME (parent_type
);
21586 /* An anonymous structure is only allowed non-static data
21587 members; no typedefs, no member functions, et cetera.
21588 So it does not need a prefix. */
21590 case DW_TAG_compile_unit
:
21591 case DW_TAG_partial_unit
:
21592 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21593 if (cu
->language
== language_cplus
21594 && !dwarf2_per_objfile
->types
.empty ()
21595 && die
->child
!= NULL
21596 && (die
->tag
== DW_TAG_class_type
21597 || die
->tag
== DW_TAG_structure_type
21598 || die
->tag
== DW_TAG_union_type
))
21600 const char *name
= guess_full_die_structure_name (die
, cu
);
21605 case DW_TAG_subprogram
:
21606 /* Nested subroutines in Fortran get a prefix with the name
21607 of the parent's subroutine. */
21608 if (cu
->language
== language_fortran
)
21610 if ((die
->tag
== DW_TAG_subprogram
)
21611 && (dwarf2_name (parent
, cu
) != NULL
))
21612 return dwarf2_name (parent
, cu
);
21614 return determine_prefix (parent
, cu
);
21615 case DW_TAG_enumeration_type
:
21616 parent_type
= read_type_die (parent
, cu
);
21617 if (TYPE_DECLARED_CLASS (parent_type
))
21619 if (TYPE_NAME (parent_type
) != NULL
)
21620 return TYPE_NAME (parent_type
);
21623 /* Fall through. */
21625 return determine_prefix (parent
, cu
);
21629 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21630 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21631 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21632 an obconcat, otherwise allocate storage for the result. The CU argument is
21633 used to determine the language and hence, the appropriate separator. */
21635 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21638 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21639 int physname
, struct dwarf2_cu
*cu
)
21641 const char *lead
= "";
21644 if (suffix
== NULL
|| suffix
[0] == '\0'
21645 || prefix
== NULL
|| prefix
[0] == '\0')
21647 else if (cu
->language
== language_d
)
21649 /* For D, the 'main' function could be defined in any module, but it
21650 should never be prefixed. */
21651 if (strcmp (suffix
, "D main") == 0)
21659 else if (cu
->language
== language_fortran
&& physname
)
21661 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21662 DW_AT_MIPS_linkage_name is preferred and used instead. */
21670 if (prefix
== NULL
)
21672 if (suffix
== NULL
)
21679 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21681 strcpy (retval
, lead
);
21682 strcat (retval
, prefix
);
21683 strcat (retval
, sep
);
21684 strcat (retval
, suffix
);
21689 /* We have an obstack. */
21690 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21694 /* Return sibling of die, NULL if no sibling. */
21696 static struct die_info
*
21697 sibling_die (struct die_info
*die
)
21699 return die
->sibling
;
21702 /* Get name of a die, return NULL if not found. */
21704 static const char *
21705 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21706 struct objfile
*objfile
)
21708 if (name
&& cu
->language
== language_cplus
)
21710 std::string canon_name
= cp_canonicalize_string (name
);
21712 if (!canon_name
.empty ())
21714 if (canon_name
!= name
)
21715 name
= objfile
->intern (canon_name
);
21722 /* Get name of a die, return NULL if not found.
21723 Anonymous namespaces are converted to their magic string. */
21725 static const char *
21726 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21728 struct attribute
*attr
;
21729 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21731 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21732 if ((!attr
|| !DW_STRING (attr
))
21733 && die
->tag
!= DW_TAG_namespace
21734 && die
->tag
!= DW_TAG_class_type
21735 && die
->tag
!= DW_TAG_interface_type
21736 && die
->tag
!= DW_TAG_structure_type
21737 && die
->tag
!= DW_TAG_union_type
)
21742 case DW_TAG_compile_unit
:
21743 case DW_TAG_partial_unit
:
21744 /* Compilation units have a DW_AT_name that is a filename, not
21745 a source language identifier. */
21746 case DW_TAG_enumeration_type
:
21747 case DW_TAG_enumerator
:
21748 /* These tags always have simple identifiers already; no need
21749 to canonicalize them. */
21750 return DW_STRING (attr
);
21752 case DW_TAG_namespace
:
21753 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21754 return DW_STRING (attr
);
21755 return CP_ANONYMOUS_NAMESPACE_STR
;
21757 case DW_TAG_class_type
:
21758 case DW_TAG_interface_type
:
21759 case DW_TAG_structure_type
:
21760 case DW_TAG_union_type
:
21761 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21762 structures or unions. These were of the form "._%d" in GCC 4.1,
21763 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21764 and GCC 4.4. We work around this problem by ignoring these. */
21765 if (attr
&& DW_STRING (attr
)
21766 && (startswith (DW_STRING (attr
), "._")
21767 || startswith (DW_STRING (attr
), "<anonymous")))
21770 /* GCC might emit a nameless typedef that has a linkage name. See
21771 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21772 if (!attr
|| DW_STRING (attr
) == NULL
)
21774 attr
= dw2_linkage_name_attr (die
, cu
);
21775 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21778 /* Avoid demangling DW_STRING (attr) the second time on a second
21779 call for the same DIE. */
21780 if (!DW_STRING_IS_CANONICAL (attr
))
21782 gdb::unique_xmalloc_ptr
<char> demangled
21783 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21784 if (demangled
== nullptr)
21787 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21788 DW_STRING_IS_CANONICAL (attr
) = 1;
21791 /* Strip any leading namespaces/classes, keep only the base name.
21792 DW_AT_name for named DIEs does not contain the prefixes. */
21793 const char *base
= strrchr (DW_STRING (attr
), ':');
21794 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21797 return DW_STRING (attr
);
21805 if (!DW_STRING_IS_CANONICAL (attr
))
21807 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21809 DW_STRING_IS_CANONICAL (attr
) = 1;
21811 return DW_STRING (attr
);
21814 /* Return the die that this die in an extension of, or NULL if there
21815 is none. *EXT_CU is the CU containing DIE on input, and the CU
21816 containing the return value on output. */
21818 static struct die_info
*
21819 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21821 struct attribute
*attr
;
21823 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21827 return follow_die_ref (die
, attr
, ext_cu
);
21830 /* A convenience function that returns an "unknown" DWARF name,
21831 including the value of V. STR is the name of the entity being
21832 printed, e.g., "TAG". */
21834 static const char *
21835 dwarf_unknown (const char *str
, unsigned v
)
21837 char *cell
= get_print_cell ();
21838 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21842 /* Convert a DIE tag into its string name. */
21844 static const char *
21845 dwarf_tag_name (unsigned tag
)
21847 const char *name
= get_DW_TAG_name (tag
);
21850 return dwarf_unknown ("TAG", tag
);
21855 /* Convert a DWARF attribute code into its string name. */
21857 static const char *
21858 dwarf_attr_name (unsigned attr
)
21862 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21863 if (attr
== DW_AT_MIPS_fde
)
21864 return "DW_AT_MIPS_fde";
21866 if (attr
== DW_AT_HP_block_index
)
21867 return "DW_AT_HP_block_index";
21870 name
= get_DW_AT_name (attr
);
21873 return dwarf_unknown ("AT", attr
);
21878 /* Convert a DWARF value form code into its string name. */
21880 static const char *
21881 dwarf_form_name (unsigned form
)
21883 const char *name
= get_DW_FORM_name (form
);
21886 return dwarf_unknown ("FORM", form
);
21891 static const char *
21892 dwarf_bool_name (unsigned mybool
)
21900 /* Convert a DWARF type code into its string name. */
21902 static const char *
21903 dwarf_type_encoding_name (unsigned enc
)
21905 const char *name
= get_DW_ATE_name (enc
);
21908 return dwarf_unknown ("ATE", enc
);
21914 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21918 print_spaces (indent
, f
);
21919 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21920 dwarf_tag_name (die
->tag
), die
->abbrev
,
21921 sect_offset_str (die
->sect_off
));
21923 if (die
->parent
!= NULL
)
21925 print_spaces (indent
, f
);
21926 fprintf_unfiltered (f
, " parent at offset: %s\n",
21927 sect_offset_str (die
->parent
->sect_off
));
21930 print_spaces (indent
, f
);
21931 fprintf_unfiltered (f
, " has children: %s\n",
21932 dwarf_bool_name (die
->child
!= NULL
));
21934 print_spaces (indent
, f
);
21935 fprintf_unfiltered (f
, " attributes:\n");
21937 for (i
= 0; i
< die
->num_attrs
; ++i
)
21939 print_spaces (indent
, f
);
21940 fprintf_unfiltered (f
, " %s (%s) ",
21941 dwarf_attr_name (die
->attrs
[i
].name
),
21942 dwarf_form_name (die
->attrs
[i
].form
));
21944 switch (die
->attrs
[i
].form
)
21947 case DW_FORM_addrx
:
21948 case DW_FORM_GNU_addr_index
:
21949 fprintf_unfiltered (f
, "address: ");
21950 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21952 case DW_FORM_block2
:
21953 case DW_FORM_block4
:
21954 case DW_FORM_block
:
21955 case DW_FORM_block1
:
21956 fprintf_unfiltered (f
, "block: size %s",
21957 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21959 case DW_FORM_exprloc
:
21960 fprintf_unfiltered (f
, "expression: size %s",
21961 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21963 case DW_FORM_data16
:
21964 fprintf_unfiltered (f
, "constant of 16 bytes");
21966 case DW_FORM_ref_addr
:
21967 fprintf_unfiltered (f
, "ref address: ");
21968 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21970 case DW_FORM_GNU_ref_alt
:
21971 fprintf_unfiltered (f
, "alt ref address: ");
21972 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21978 case DW_FORM_ref_udata
:
21979 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21980 (long) (DW_UNSND (&die
->attrs
[i
])));
21982 case DW_FORM_data1
:
21983 case DW_FORM_data2
:
21984 case DW_FORM_data4
:
21985 case DW_FORM_data8
:
21986 case DW_FORM_udata
:
21987 case DW_FORM_sdata
:
21988 fprintf_unfiltered (f
, "constant: %s",
21989 pulongest (DW_UNSND (&die
->attrs
[i
])));
21991 case DW_FORM_sec_offset
:
21992 fprintf_unfiltered (f
, "section offset: %s",
21993 pulongest (DW_UNSND (&die
->attrs
[i
])));
21995 case DW_FORM_ref_sig8
:
21996 fprintf_unfiltered (f
, "signature: %s",
21997 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21999 case DW_FORM_string
:
22001 case DW_FORM_line_strp
:
22003 case DW_FORM_GNU_str_index
:
22004 case DW_FORM_GNU_strp_alt
:
22005 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22006 DW_STRING (&die
->attrs
[i
])
22007 ? DW_STRING (&die
->attrs
[i
]) : "",
22008 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22011 if (DW_UNSND (&die
->attrs
[i
]))
22012 fprintf_unfiltered (f
, "flag: TRUE");
22014 fprintf_unfiltered (f
, "flag: FALSE");
22016 case DW_FORM_flag_present
:
22017 fprintf_unfiltered (f
, "flag: TRUE");
22019 case DW_FORM_indirect
:
22020 /* The reader will have reduced the indirect form to
22021 the "base form" so this form should not occur. */
22022 fprintf_unfiltered (f
,
22023 "unexpected attribute form: DW_FORM_indirect");
22025 case DW_FORM_implicit_const
:
22026 fprintf_unfiltered (f
, "constant: %s",
22027 plongest (DW_SND (&die
->attrs
[i
])));
22030 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22031 die
->attrs
[i
].form
);
22034 fprintf_unfiltered (f
, "\n");
22039 dump_die_for_error (struct die_info
*die
)
22041 dump_die_shallow (gdb_stderr
, 0, die
);
22045 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22047 int indent
= level
* 4;
22049 gdb_assert (die
!= NULL
);
22051 if (level
>= max_level
)
22054 dump_die_shallow (f
, indent
, die
);
22056 if (die
->child
!= NULL
)
22058 print_spaces (indent
, f
);
22059 fprintf_unfiltered (f
, " Children:");
22060 if (level
+ 1 < max_level
)
22062 fprintf_unfiltered (f
, "\n");
22063 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22067 fprintf_unfiltered (f
,
22068 " [not printed, max nesting level reached]\n");
22072 if (die
->sibling
!= NULL
&& level
> 0)
22074 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22078 /* This is called from the pdie macro in gdbinit.in.
22079 It's not static so gcc will keep a copy callable from gdb. */
22082 dump_die (struct die_info
*die
, int max_level
)
22084 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22088 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22092 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22093 to_underlying (die
->sect_off
),
22099 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22103 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22105 if (attr
->form_is_ref ())
22106 return (sect_offset
) DW_UNSND (attr
);
22108 complaint (_("unsupported die ref attribute form: '%s'"),
22109 dwarf_form_name (attr
->form
));
22113 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22114 * the value held by the attribute is not constant. */
22117 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22119 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22120 return DW_SND (attr
);
22121 else if (attr
->form
== DW_FORM_udata
22122 || attr
->form
== DW_FORM_data1
22123 || attr
->form
== DW_FORM_data2
22124 || attr
->form
== DW_FORM_data4
22125 || attr
->form
== DW_FORM_data8
)
22126 return DW_UNSND (attr
);
22129 /* For DW_FORM_data16 see attribute::form_is_constant. */
22130 complaint (_("Attribute value is not a constant (%s)"),
22131 dwarf_form_name (attr
->form
));
22132 return default_value
;
22136 /* Follow reference or signature attribute ATTR of SRC_DIE.
22137 On entry *REF_CU is the CU of SRC_DIE.
22138 On exit *REF_CU is the CU of the result. */
22140 static struct die_info
*
22141 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22142 struct dwarf2_cu
**ref_cu
)
22144 struct die_info
*die
;
22146 if (attr
->form_is_ref ())
22147 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22148 else if (attr
->form
== DW_FORM_ref_sig8
)
22149 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22152 dump_die_for_error (src_die
);
22153 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22154 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22160 /* Follow reference OFFSET.
22161 On entry *REF_CU is the CU of the source die referencing OFFSET.
22162 On exit *REF_CU is the CU of the result.
22163 Returns NULL if OFFSET is invalid. */
22165 static struct die_info
*
22166 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22167 struct dwarf2_cu
**ref_cu
)
22169 struct die_info temp_die
;
22170 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22171 struct dwarf2_per_objfile
*dwarf2_per_objfile
22172 = cu
->per_cu
->dwarf2_per_objfile
;
22174 gdb_assert (cu
->per_cu
!= NULL
);
22178 if (cu
->per_cu
->is_debug_types
)
22180 /* .debug_types CUs cannot reference anything outside their CU.
22181 If they need to, they have to reference a signatured type via
22182 DW_FORM_ref_sig8. */
22183 if (!cu
->header
.offset_in_cu_p (sect_off
))
22186 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22187 || !cu
->header
.offset_in_cu_p (sect_off
))
22189 struct dwarf2_per_cu_data
*per_cu
;
22191 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22192 dwarf2_per_objfile
);
22194 /* If necessary, add it to the queue and load its DIEs. */
22195 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22196 load_full_comp_unit (per_cu
, false, cu
->language
);
22198 target_cu
= per_cu
->cu
;
22200 else if (cu
->dies
== NULL
)
22202 /* We're loading full DIEs during partial symbol reading. */
22203 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22204 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22207 *ref_cu
= target_cu
;
22208 temp_die
.sect_off
= sect_off
;
22210 if (target_cu
!= cu
)
22211 target_cu
->ancestor
= cu
;
22213 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22215 to_underlying (sect_off
));
22218 /* Follow reference attribute ATTR of SRC_DIE.
22219 On entry *REF_CU is the CU of SRC_DIE.
22220 On exit *REF_CU is the CU of the result. */
22222 static struct die_info
*
22223 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22224 struct dwarf2_cu
**ref_cu
)
22226 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22227 struct dwarf2_cu
*cu
= *ref_cu
;
22228 struct die_info
*die
;
22230 die
= follow_die_offset (sect_off
,
22231 (attr
->form
== DW_FORM_GNU_ref_alt
22232 || cu
->per_cu
->is_dwz
),
22235 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22236 "at %s [in module %s]"),
22237 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22238 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22245 struct dwarf2_locexpr_baton
22246 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22247 dwarf2_per_cu_data
*per_cu
,
22248 CORE_ADDR (*get_frame_pc
) (void *baton
),
22249 void *baton
, bool resolve_abstract_p
)
22251 struct dwarf2_cu
*cu
;
22252 struct die_info
*die
;
22253 struct attribute
*attr
;
22254 struct dwarf2_locexpr_baton retval
;
22255 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22256 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22258 if (per_cu
->cu
== NULL
)
22259 load_cu (per_cu
, false);
22263 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22264 Instead just throw an error, not much else we can do. */
22265 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22266 sect_offset_str (sect_off
), objfile_name (objfile
));
22269 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22271 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22272 sect_offset_str (sect_off
), objfile_name (objfile
));
22274 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22275 if (!attr
&& resolve_abstract_p
22276 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22277 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22279 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22280 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22281 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22283 for (const auto &cand_off
22284 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22286 struct dwarf2_cu
*cand_cu
= cu
;
22287 struct die_info
*cand
22288 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22291 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22294 CORE_ADDR pc_low
, pc_high
;
22295 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22296 if (pc_low
== ((CORE_ADDR
) -1))
22298 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22299 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22300 if (!(pc_low
<= pc
&& pc
< pc_high
))
22304 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22311 /* DWARF: "If there is no such attribute, then there is no effect.".
22312 DATA is ignored if SIZE is 0. */
22314 retval
.data
= NULL
;
22317 else if (attr
->form_is_section_offset ())
22319 struct dwarf2_loclist_baton loclist_baton
;
22320 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22323 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22325 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22327 retval
.size
= size
;
22331 if (!attr
->form_is_block ())
22332 error (_("Dwarf Error: DIE at %s referenced in module %s "
22333 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22334 sect_offset_str (sect_off
), objfile_name (objfile
));
22336 retval
.data
= DW_BLOCK (attr
)->data
;
22337 retval
.size
= DW_BLOCK (attr
)->size
;
22339 retval
.per_cu
= cu
->per_cu
;
22341 age_cached_comp_units (dwarf2_per_objfile
);
22348 struct dwarf2_locexpr_baton
22349 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22350 dwarf2_per_cu_data
*per_cu
,
22351 CORE_ADDR (*get_frame_pc
) (void *baton
),
22354 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22356 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22359 /* Write a constant of a given type as target-ordered bytes into
22362 static const gdb_byte
*
22363 write_constant_as_bytes (struct obstack
*obstack
,
22364 enum bfd_endian byte_order
,
22371 *len
= TYPE_LENGTH (type
);
22372 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22373 store_unsigned_integer (result
, *len
, byte_order
, value
);
22381 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22382 dwarf2_per_cu_data
*per_cu
,
22386 struct dwarf2_cu
*cu
;
22387 struct die_info
*die
;
22388 struct attribute
*attr
;
22389 const gdb_byte
*result
= NULL
;
22392 enum bfd_endian byte_order
;
22393 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22395 if (per_cu
->cu
== NULL
)
22396 load_cu (per_cu
, false);
22400 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22401 Instead just throw an error, not much else we can do. */
22402 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22403 sect_offset_str (sect_off
), objfile_name (objfile
));
22406 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22408 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22409 sect_offset_str (sect_off
), objfile_name (objfile
));
22411 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22415 byte_order
= (bfd_big_endian (objfile
->obfd
)
22416 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22418 switch (attr
->form
)
22421 case DW_FORM_addrx
:
22422 case DW_FORM_GNU_addr_index
:
22426 *len
= cu
->header
.addr_size
;
22427 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22428 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22432 case DW_FORM_string
:
22435 case DW_FORM_GNU_str_index
:
22436 case DW_FORM_GNU_strp_alt
:
22437 /* DW_STRING is already allocated on the objfile obstack, point
22439 result
= (const gdb_byte
*) DW_STRING (attr
);
22440 *len
= strlen (DW_STRING (attr
));
22442 case DW_FORM_block1
:
22443 case DW_FORM_block2
:
22444 case DW_FORM_block4
:
22445 case DW_FORM_block
:
22446 case DW_FORM_exprloc
:
22447 case DW_FORM_data16
:
22448 result
= DW_BLOCK (attr
)->data
;
22449 *len
= DW_BLOCK (attr
)->size
;
22452 /* The DW_AT_const_value attributes are supposed to carry the
22453 symbol's value "represented as it would be on the target
22454 architecture." By the time we get here, it's already been
22455 converted to host endianness, so we just need to sign- or
22456 zero-extend it as appropriate. */
22457 case DW_FORM_data1
:
22458 type
= die_type (die
, cu
);
22459 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22460 if (result
== NULL
)
22461 result
= write_constant_as_bytes (obstack
, byte_order
,
22464 case DW_FORM_data2
:
22465 type
= die_type (die
, cu
);
22466 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22467 if (result
== NULL
)
22468 result
= write_constant_as_bytes (obstack
, byte_order
,
22471 case DW_FORM_data4
:
22472 type
= die_type (die
, cu
);
22473 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22474 if (result
== NULL
)
22475 result
= write_constant_as_bytes (obstack
, byte_order
,
22478 case DW_FORM_data8
:
22479 type
= die_type (die
, cu
);
22480 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22481 if (result
== NULL
)
22482 result
= write_constant_as_bytes (obstack
, byte_order
,
22486 case DW_FORM_sdata
:
22487 case DW_FORM_implicit_const
:
22488 type
= die_type (die
, cu
);
22489 result
= write_constant_as_bytes (obstack
, byte_order
,
22490 type
, DW_SND (attr
), len
);
22493 case DW_FORM_udata
:
22494 type
= die_type (die
, cu
);
22495 result
= write_constant_as_bytes (obstack
, byte_order
,
22496 type
, DW_UNSND (attr
), len
);
22500 complaint (_("unsupported const value attribute form: '%s'"),
22501 dwarf_form_name (attr
->form
));
22511 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22512 dwarf2_per_cu_data
*per_cu
)
22514 struct dwarf2_cu
*cu
;
22515 struct die_info
*die
;
22517 if (per_cu
->cu
== NULL
)
22518 load_cu (per_cu
, false);
22523 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22527 return die_type (die
, cu
);
22533 dwarf2_get_die_type (cu_offset die_offset
,
22534 struct dwarf2_per_cu_data
*per_cu
)
22536 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22537 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22540 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22541 On entry *REF_CU is the CU of SRC_DIE.
22542 On exit *REF_CU is the CU of the result.
22543 Returns NULL if the referenced DIE isn't found. */
22545 static struct die_info
*
22546 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22547 struct dwarf2_cu
**ref_cu
)
22549 struct die_info temp_die
;
22550 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22551 struct die_info
*die
;
22553 /* While it might be nice to assert sig_type->type == NULL here,
22554 we can get here for DW_AT_imported_declaration where we need
22555 the DIE not the type. */
22557 /* If necessary, add it to the queue and load its DIEs. */
22559 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22560 read_signatured_type (sig_type
);
22562 sig_cu
= sig_type
->per_cu
.cu
;
22563 gdb_assert (sig_cu
!= NULL
);
22564 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22565 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22566 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22567 to_underlying (temp_die
.sect_off
));
22570 struct dwarf2_per_objfile
*dwarf2_per_objfile
22571 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22573 /* For .gdb_index version 7 keep track of included TUs.
22574 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22575 if (dwarf2_per_objfile
->index_table
!= NULL
22576 && dwarf2_per_objfile
->index_table
->version
<= 7)
22578 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22583 sig_cu
->ancestor
= cu
;
22591 /* Follow signatured type referenced by ATTR in SRC_DIE.
22592 On entry *REF_CU is the CU of SRC_DIE.
22593 On exit *REF_CU is the CU of the result.
22594 The result is the DIE of the type.
22595 If the referenced type cannot be found an error is thrown. */
22597 static struct die_info
*
22598 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22599 struct dwarf2_cu
**ref_cu
)
22601 ULONGEST signature
= DW_SIGNATURE (attr
);
22602 struct signatured_type
*sig_type
;
22603 struct die_info
*die
;
22605 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22607 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22608 /* sig_type will be NULL if the signatured type is missing from
22610 if (sig_type
== NULL
)
22612 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22613 " from DIE at %s [in module %s]"),
22614 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22615 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22618 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22621 dump_die_for_error (src_die
);
22622 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22623 " from DIE at %s [in module %s]"),
22624 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22625 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22631 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22632 reading in and processing the type unit if necessary. */
22634 static struct type
*
22635 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22636 struct dwarf2_cu
*cu
)
22638 struct dwarf2_per_objfile
*dwarf2_per_objfile
22639 = cu
->per_cu
->dwarf2_per_objfile
;
22640 struct signatured_type
*sig_type
;
22641 struct dwarf2_cu
*type_cu
;
22642 struct die_info
*type_die
;
22645 sig_type
= lookup_signatured_type (cu
, signature
);
22646 /* sig_type will be NULL if the signatured type is missing from
22648 if (sig_type
== NULL
)
22650 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22651 " from DIE at %s [in module %s]"),
22652 hex_string (signature
), sect_offset_str (die
->sect_off
),
22653 objfile_name (dwarf2_per_objfile
->objfile
));
22654 return build_error_marker_type (cu
, die
);
22657 /* If we already know the type we're done. */
22658 if (sig_type
->type
!= NULL
)
22659 return sig_type
->type
;
22662 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22663 if (type_die
!= NULL
)
22665 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22666 is created. This is important, for example, because for c++ classes
22667 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22668 type
= read_type_die (type_die
, type_cu
);
22671 complaint (_("Dwarf Error: Cannot build signatured type %s"
22672 " referenced from DIE at %s [in module %s]"),
22673 hex_string (signature
), sect_offset_str (die
->sect_off
),
22674 objfile_name (dwarf2_per_objfile
->objfile
));
22675 type
= build_error_marker_type (cu
, die
);
22680 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22681 " from DIE at %s [in module %s]"),
22682 hex_string (signature
), sect_offset_str (die
->sect_off
),
22683 objfile_name (dwarf2_per_objfile
->objfile
));
22684 type
= build_error_marker_type (cu
, die
);
22686 sig_type
->type
= type
;
22691 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22692 reading in and processing the type unit if necessary. */
22694 static struct type
*
22695 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22696 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22698 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22699 if (attr
->form_is_ref ())
22701 struct dwarf2_cu
*type_cu
= cu
;
22702 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22704 return read_type_die (type_die
, type_cu
);
22706 else if (attr
->form
== DW_FORM_ref_sig8
)
22708 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22712 struct dwarf2_per_objfile
*dwarf2_per_objfile
22713 = cu
->per_cu
->dwarf2_per_objfile
;
22715 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22716 " at %s [in module %s]"),
22717 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22718 objfile_name (dwarf2_per_objfile
->objfile
));
22719 return build_error_marker_type (cu
, die
);
22723 /* Load the DIEs associated with type unit PER_CU into memory. */
22726 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22728 struct signatured_type
*sig_type
;
22730 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22731 gdb_assert (! per_cu
->type_unit_group_p ());
22733 /* We have the per_cu, but we need the signatured_type.
22734 Fortunately this is an easy translation. */
22735 gdb_assert (per_cu
->is_debug_types
);
22736 sig_type
= (struct signatured_type
*) per_cu
;
22738 gdb_assert (per_cu
->cu
== NULL
);
22740 read_signatured_type (sig_type
);
22742 gdb_assert (per_cu
->cu
!= NULL
);
22745 /* Read in a signatured type and build its CU and DIEs.
22746 If the type is a stub for the real type in a DWO file,
22747 read in the real type from the DWO file as well. */
22750 read_signatured_type (struct signatured_type
*sig_type
)
22752 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22754 gdb_assert (per_cu
->is_debug_types
);
22755 gdb_assert (per_cu
->cu
== NULL
);
22757 cutu_reader
reader (per_cu
, NULL
, 0, false);
22759 if (!reader
.dummy_p
)
22761 struct dwarf2_cu
*cu
= reader
.cu
;
22762 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22764 gdb_assert (cu
->die_hash
== NULL
);
22766 htab_create_alloc_ex (cu
->header
.length
/ 12,
22770 &cu
->comp_unit_obstack
,
22771 hashtab_obstack_allocate
,
22772 dummy_obstack_deallocate
);
22774 if (reader
.comp_unit_die
->has_children
)
22775 reader
.comp_unit_die
->child
22776 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22777 reader
.comp_unit_die
);
22778 cu
->dies
= reader
.comp_unit_die
;
22779 /* comp_unit_die is not stored in die_hash, no need. */
22781 /* We try not to read any attributes in this function, because
22782 not all CUs needed for references have been loaded yet, and
22783 symbol table processing isn't initialized. But we have to
22784 set the CU language, or we won't be able to build types
22785 correctly. Similarly, if we do not read the producer, we can
22786 not apply producer-specific interpretation. */
22787 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22792 sig_type
->per_cu
.tu_read
= 1;
22795 /* Decode simple location descriptions.
22796 Given a pointer to a dwarf block that defines a location, compute
22797 the location and return the value.
22799 NOTE drow/2003-11-18: This function is called in two situations
22800 now: for the address of static or global variables (partial symbols
22801 only) and for offsets into structures which are expected to be
22802 (more or less) constant. The partial symbol case should go away,
22803 and only the constant case should remain. That will let this
22804 function complain more accurately. A few special modes are allowed
22805 without complaint for global variables (for instance, global
22806 register values and thread-local values).
22808 A location description containing no operations indicates that the
22809 object is optimized out. The return value is 0 for that case.
22810 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22811 callers will only want a very basic result and this can become a
22814 Note that stack[0] is unused except as a default error return. */
22817 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22819 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22821 size_t size
= blk
->size
;
22822 const gdb_byte
*data
= blk
->data
;
22823 CORE_ADDR stack
[64];
22825 unsigned int bytes_read
, unsnd
;
22831 stack
[++stacki
] = 0;
22870 stack
[++stacki
] = op
- DW_OP_lit0
;
22905 stack
[++stacki
] = op
- DW_OP_reg0
;
22907 dwarf2_complex_location_expr_complaint ();
22911 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22913 stack
[++stacki
] = unsnd
;
22915 dwarf2_complex_location_expr_complaint ();
22919 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22924 case DW_OP_const1u
:
22925 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22929 case DW_OP_const1s
:
22930 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22934 case DW_OP_const2u
:
22935 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22939 case DW_OP_const2s
:
22940 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22944 case DW_OP_const4u
:
22945 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22949 case DW_OP_const4s
:
22950 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22954 case DW_OP_const8u
:
22955 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22960 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22966 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22971 stack
[stacki
+ 1] = stack
[stacki
];
22976 stack
[stacki
- 1] += stack
[stacki
];
22980 case DW_OP_plus_uconst
:
22981 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22987 stack
[stacki
- 1] -= stack
[stacki
];
22992 /* If we're not the last op, then we definitely can't encode
22993 this using GDB's address_class enum. This is valid for partial
22994 global symbols, although the variable's address will be bogus
22997 dwarf2_complex_location_expr_complaint ();
23000 case DW_OP_GNU_push_tls_address
:
23001 case DW_OP_form_tls_address
:
23002 /* The top of the stack has the offset from the beginning
23003 of the thread control block at which the variable is located. */
23004 /* Nothing should follow this operator, so the top of stack would
23006 /* This is valid for partial global symbols, but the variable's
23007 address will be bogus in the psymtab. Make it always at least
23008 non-zero to not look as a variable garbage collected by linker
23009 which have DW_OP_addr 0. */
23011 dwarf2_complex_location_expr_complaint ();
23015 case DW_OP_GNU_uninit
:
23019 case DW_OP_GNU_addr_index
:
23020 case DW_OP_GNU_const_index
:
23021 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23028 const char *name
= get_DW_OP_name (op
);
23031 complaint (_("unsupported stack op: '%s'"),
23034 complaint (_("unsupported stack op: '%02x'"),
23038 return (stack
[stacki
]);
23041 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23042 outside of the allocated space. Also enforce minimum>0. */
23043 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23045 complaint (_("location description stack overflow"));
23051 complaint (_("location description stack underflow"));
23055 return (stack
[stacki
]);
23058 /* memory allocation interface */
23060 static struct dwarf_block
*
23061 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23063 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23066 static struct die_info
*
23067 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23069 struct die_info
*die
;
23070 size_t size
= sizeof (struct die_info
);
23073 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23075 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23076 memset (die
, 0, sizeof (struct die_info
));
23081 /* Macro support. */
23083 static struct macro_source_file
*
23084 macro_start_file (buildsym_compunit
*builder
,
23085 int file
, int line
,
23086 struct macro_source_file
*current_file
,
23087 struct line_header
*lh
)
23089 /* File name relative to the compilation directory of this source file. */
23090 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23092 if (! current_file
)
23094 /* Note: We don't create a macro table for this compilation unit
23095 at all until we actually get a filename. */
23096 struct macro_table
*macro_table
= builder
->get_macro_table ();
23098 /* If we have no current file, then this must be the start_file
23099 directive for the compilation unit's main source file. */
23100 current_file
= macro_set_main (macro_table
, file_name
.get ());
23101 macro_define_special (macro_table
);
23104 current_file
= macro_include (current_file
, line
, file_name
.get ());
23106 return current_file
;
23109 static const char *
23110 consume_improper_spaces (const char *p
, const char *body
)
23114 complaint (_("macro definition contains spaces "
23115 "in formal argument list:\n`%s'"),
23127 parse_macro_definition (struct macro_source_file
*file
, int line
,
23132 /* The body string takes one of two forms. For object-like macro
23133 definitions, it should be:
23135 <macro name> " " <definition>
23137 For function-like macro definitions, it should be:
23139 <macro name> "() " <definition>
23141 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23143 Spaces may appear only where explicitly indicated, and in the
23146 The Dwarf 2 spec says that an object-like macro's name is always
23147 followed by a space, but versions of GCC around March 2002 omit
23148 the space when the macro's definition is the empty string.
23150 The Dwarf 2 spec says that there should be no spaces between the
23151 formal arguments in a function-like macro's formal argument list,
23152 but versions of GCC around March 2002 include spaces after the
23156 /* Find the extent of the macro name. The macro name is terminated
23157 by either a space or null character (for an object-like macro) or
23158 an opening paren (for a function-like macro). */
23159 for (p
= body
; *p
; p
++)
23160 if (*p
== ' ' || *p
== '(')
23163 if (*p
== ' ' || *p
== '\0')
23165 /* It's an object-like macro. */
23166 int name_len
= p
- body
;
23167 std::string
name (body
, name_len
);
23168 const char *replacement
;
23171 replacement
= body
+ name_len
+ 1;
23174 dwarf2_macro_malformed_definition_complaint (body
);
23175 replacement
= body
+ name_len
;
23178 macro_define_object (file
, line
, name
.c_str (), replacement
);
23180 else if (*p
== '(')
23182 /* It's a function-like macro. */
23183 std::string
name (body
, p
- body
);
23186 char **argv
= XNEWVEC (char *, argv_size
);
23190 p
= consume_improper_spaces (p
, body
);
23192 /* Parse the formal argument list. */
23193 while (*p
&& *p
!= ')')
23195 /* Find the extent of the current argument name. */
23196 const char *arg_start
= p
;
23198 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23201 if (! *p
|| p
== arg_start
)
23202 dwarf2_macro_malformed_definition_complaint (body
);
23205 /* Make sure argv has room for the new argument. */
23206 if (argc
>= argv_size
)
23209 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23212 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23215 p
= consume_improper_spaces (p
, body
);
23217 /* Consume the comma, if present. */
23222 p
= consume_improper_spaces (p
, body
);
23231 /* Perfectly formed definition, no complaints. */
23232 macro_define_function (file
, line
, name
.c_str (),
23233 argc
, (const char **) argv
,
23235 else if (*p
== '\0')
23237 /* Complain, but do define it. */
23238 dwarf2_macro_malformed_definition_complaint (body
);
23239 macro_define_function (file
, line
, name
.c_str (),
23240 argc
, (const char **) argv
,
23244 /* Just complain. */
23245 dwarf2_macro_malformed_definition_complaint (body
);
23248 /* Just complain. */
23249 dwarf2_macro_malformed_definition_complaint (body
);
23254 for (i
= 0; i
< argc
; i
++)
23260 dwarf2_macro_malformed_definition_complaint (body
);
23263 /* Skip some bytes from BYTES according to the form given in FORM.
23264 Returns the new pointer. */
23266 static const gdb_byte
*
23267 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23268 enum dwarf_form form
,
23269 unsigned int offset_size
,
23270 struct dwarf2_section_info
*section
)
23272 unsigned int bytes_read
;
23276 case DW_FORM_data1
:
23281 case DW_FORM_data2
:
23285 case DW_FORM_data4
:
23289 case DW_FORM_data8
:
23293 case DW_FORM_data16
:
23297 case DW_FORM_string
:
23298 read_direct_string (abfd
, bytes
, &bytes_read
);
23299 bytes
+= bytes_read
;
23302 case DW_FORM_sec_offset
:
23304 case DW_FORM_GNU_strp_alt
:
23305 bytes
+= offset_size
;
23308 case DW_FORM_block
:
23309 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23310 bytes
+= bytes_read
;
23313 case DW_FORM_block1
:
23314 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23316 case DW_FORM_block2
:
23317 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23319 case DW_FORM_block4
:
23320 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23323 case DW_FORM_addrx
:
23324 case DW_FORM_sdata
:
23326 case DW_FORM_udata
:
23327 case DW_FORM_GNU_addr_index
:
23328 case DW_FORM_GNU_str_index
:
23329 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23332 dwarf2_section_buffer_overflow_complaint (section
);
23337 case DW_FORM_implicit_const
:
23342 complaint (_("invalid form 0x%x in `%s'"),
23343 form
, section
->get_name ());
23351 /* A helper for dwarf_decode_macros that handles skipping an unknown
23352 opcode. Returns an updated pointer to the macro data buffer; or,
23353 on error, issues a complaint and returns NULL. */
23355 static const gdb_byte
*
23356 skip_unknown_opcode (unsigned int opcode
,
23357 const gdb_byte
**opcode_definitions
,
23358 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23360 unsigned int offset_size
,
23361 struct dwarf2_section_info
*section
)
23363 unsigned int bytes_read
, i
;
23365 const gdb_byte
*defn
;
23367 if (opcode_definitions
[opcode
] == NULL
)
23369 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23374 defn
= opcode_definitions
[opcode
];
23375 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23376 defn
+= bytes_read
;
23378 for (i
= 0; i
< arg
; ++i
)
23380 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23381 (enum dwarf_form
) defn
[i
], offset_size
,
23383 if (mac_ptr
== NULL
)
23385 /* skip_form_bytes already issued the complaint. */
23393 /* A helper function which parses the header of a macro section.
23394 If the macro section is the extended (for now called "GNU") type,
23395 then this updates *OFFSET_SIZE. Returns a pointer to just after
23396 the header, or issues a complaint and returns NULL on error. */
23398 static const gdb_byte
*
23399 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23401 const gdb_byte
*mac_ptr
,
23402 unsigned int *offset_size
,
23403 int section_is_gnu
)
23405 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23407 if (section_is_gnu
)
23409 unsigned int version
, flags
;
23411 version
= read_2_bytes (abfd
, mac_ptr
);
23412 if (version
!= 4 && version
!= 5)
23414 complaint (_("unrecognized version `%d' in .debug_macro section"),
23420 flags
= read_1_byte (abfd
, mac_ptr
);
23422 *offset_size
= (flags
& 1) ? 8 : 4;
23424 if ((flags
& 2) != 0)
23425 /* We don't need the line table offset. */
23426 mac_ptr
+= *offset_size
;
23428 /* Vendor opcode descriptions. */
23429 if ((flags
& 4) != 0)
23431 unsigned int i
, count
;
23433 count
= read_1_byte (abfd
, mac_ptr
);
23435 for (i
= 0; i
< count
; ++i
)
23437 unsigned int opcode
, bytes_read
;
23440 opcode
= read_1_byte (abfd
, mac_ptr
);
23442 opcode_definitions
[opcode
] = mac_ptr
;
23443 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23444 mac_ptr
+= bytes_read
;
23453 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23454 including DW_MACRO_import. */
23457 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
23458 buildsym_compunit
*builder
,
23460 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23461 struct macro_source_file
*current_file
,
23462 struct line_header
*lh
,
23463 struct dwarf2_section_info
*section
,
23464 int section_is_gnu
, int section_is_dwz
,
23465 unsigned int offset_size
,
23466 htab_t include_hash
)
23468 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23469 enum dwarf_macro_record_type macinfo_type
;
23470 int at_commandline
;
23471 const gdb_byte
*opcode_definitions
[256];
23473 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23474 &offset_size
, section_is_gnu
);
23475 if (mac_ptr
== NULL
)
23477 /* We already issued a complaint. */
23481 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23482 GDB is still reading the definitions from command line. First
23483 DW_MACINFO_start_file will need to be ignored as it was already executed
23484 to create CURRENT_FILE for the main source holding also the command line
23485 definitions. On first met DW_MACINFO_start_file this flag is reset to
23486 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23488 at_commandline
= 1;
23492 /* Do we at least have room for a macinfo type byte? */
23493 if (mac_ptr
>= mac_end
)
23495 dwarf2_section_buffer_overflow_complaint (section
);
23499 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23502 /* Note that we rely on the fact that the corresponding GNU and
23503 DWARF constants are the same. */
23505 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23506 switch (macinfo_type
)
23508 /* A zero macinfo type indicates the end of the macro
23513 case DW_MACRO_define
:
23514 case DW_MACRO_undef
:
23515 case DW_MACRO_define_strp
:
23516 case DW_MACRO_undef_strp
:
23517 case DW_MACRO_define_sup
:
23518 case DW_MACRO_undef_sup
:
23520 unsigned int bytes_read
;
23525 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23526 mac_ptr
+= bytes_read
;
23528 if (macinfo_type
== DW_MACRO_define
23529 || macinfo_type
== DW_MACRO_undef
)
23531 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23532 mac_ptr
+= bytes_read
;
23536 LONGEST str_offset
;
23538 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23539 mac_ptr
+= offset_size
;
23541 if (macinfo_type
== DW_MACRO_define_sup
23542 || macinfo_type
== DW_MACRO_undef_sup
23545 struct dwz_file
*dwz
23546 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23548 body
= dwz
->read_string (objfile
, str_offset
);
23551 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
23555 is_define
= (macinfo_type
== DW_MACRO_define
23556 || macinfo_type
== DW_MACRO_define_strp
23557 || macinfo_type
== DW_MACRO_define_sup
);
23558 if (! current_file
)
23560 /* DWARF violation as no main source is present. */
23561 complaint (_("debug info with no main source gives macro %s "
23563 is_define
? _("definition") : _("undefinition"),
23567 if ((line
== 0 && !at_commandline
)
23568 || (line
!= 0 && at_commandline
))
23569 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
23570 at_commandline
? _("command-line") : _("in-file"),
23571 is_define
? _("definition") : _("undefinition"),
23572 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
23576 /* Fedora's rpm-build's "debugedit" binary
23577 corrupted .debug_macro sections.
23580 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
23581 complaint (_("debug info gives %s invalid macro %s "
23582 "without body (corrupted?) at line %d "
23584 at_commandline
? _("command-line") : _("in-file"),
23585 is_define
? _("definition") : _("undefinition"),
23586 line
, current_file
->filename
);
23588 else if (is_define
)
23589 parse_macro_definition (current_file
, line
, body
);
23592 gdb_assert (macinfo_type
== DW_MACRO_undef
23593 || macinfo_type
== DW_MACRO_undef_strp
23594 || macinfo_type
== DW_MACRO_undef_sup
);
23595 macro_undef (current_file
, line
, body
);
23600 case DW_MACRO_start_file
:
23602 unsigned int bytes_read
;
23605 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23606 mac_ptr
+= bytes_read
;
23607 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23608 mac_ptr
+= bytes_read
;
23610 if ((line
== 0 && !at_commandline
)
23611 || (line
!= 0 && at_commandline
))
23612 complaint (_("debug info gives source %d included "
23613 "from %s at %s line %d"),
23614 file
, at_commandline
? _("command-line") : _("file"),
23615 line
== 0 ? _("zero") : _("non-zero"), line
);
23617 if (at_commandline
)
23619 /* This DW_MACRO_start_file was executed in the
23621 at_commandline
= 0;
23624 current_file
= macro_start_file (builder
, file
, line
,
23629 case DW_MACRO_end_file
:
23630 if (! current_file
)
23631 complaint (_("macro debug info has an unmatched "
23632 "`close_file' directive"));
23635 current_file
= current_file
->included_by
;
23636 if (! current_file
)
23638 enum dwarf_macro_record_type next_type
;
23640 /* GCC circa March 2002 doesn't produce the zero
23641 type byte marking the end of the compilation
23642 unit. Complain if it's not there, but exit no
23645 /* Do we at least have room for a macinfo type byte? */
23646 if (mac_ptr
>= mac_end
)
23648 dwarf2_section_buffer_overflow_complaint (section
);
23652 /* We don't increment mac_ptr here, so this is just
23655 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
23657 if (next_type
!= 0)
23658 complaint (_("no terminating 0-type entry for "
23659 "macros in `.debug_macinfo' section"));
23666 case DW_MACRO_import
:
23667 case DW_MACRO_import_sup
:
23671 bfd
*include_bfd
= abfd
;
23672 struct dwarf2_section_info
*include_section
= section
;
23673 const gdb_byte
*include_mac_end
= mac_end
;
23674 int is_dwz
= section_is_dwz
;
23675 const gdb_byte
*new_mac_ptr
;
23677 offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23678 mac_ptr
+= offset_size
;
23680 if (macinfo_type
== DW_MACRO_import_sup
)
23682 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
23684 dwz
->macro
.read (objfile
);
23686 include_section
= &dwz
->macro
;
23687 include_bfd
= include_section
->get_bfd_owner ();
23688 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
23692 new_mac_ptr
= include_section
->buffer
+ offset
;
23693 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
23697 /* This has actually happened; see
23698 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
23699 complaint (_("recursive DW_MACRO_import in "
23700 ".debug_macro section"));
23704 *slot
= (void *) new_mac_ptr
;
23706 dwarf_decode_macro_bytes (dwarf2_per_objfile
, builder
,
23707 include_bfd
, new_mac_ptr
,
23708 include_mac_end
, current_file
, lh
,
23709 section
, section_is_gnu
, is_dwz
,
23710 offset_size
, include_hash
);
23712 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
23717 case DW_MACINFO_vendor_ext
:
23718 if (!section_is_gnu
)
23720 unsigned int bytes_read
;
23722 /* This reads the constant, but since we don't recognize
23723 any vendor extensions, we ignore it. */
23724 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23725 mac_ptr
+= bytes_read
;
23726 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23727 mac_ptr
+= bytes_read
;
23729 /* We don't recognize any vendor extensions. */
23735 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23736 mac_ptr
, mac_end
, abfd
, offset_size
,
23738 if (mac_ptr
== NULL
)
23743 } while (macinfo_type
!= 0);
23747 dwarf_decode_macros (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
23748 buildsym_compunit
*builder
, dwarf2_section_info
*section
,
23749 struct line_header
*lh
, unsigned int offset_size
,
23750 unsigned int offset
, int section_is_gnu
)
23753 const gdb_byte
*mac_ptr
, *mac_end
;
23754 struct macro_source_file
*current_file
= 0;
23755 enum dwarf_macro_record_type macinfo_type
;
23756 const gdb_byte
*opcode_definitions
[256];
23759 abfd
= section
->get_bfd_owner ();
23761 /* First pass: Find the name of the base filename.
23762 This filename is needed in order to process all macros whose definition
23763 (or undefinition) comes from the command line. These macros are defined
23764 before the first DW_MACINFO_start_file entry, and yet still need to be
23765 associated to the base file.
23767 To determine the base file name, we scan the macro definitions until we
23768 reach the first DW_MACINFO_start_file entry. We then initialize
23769 CURRENT_FILE accordingly so that any macro definition found before the
23770 first DW_MACINFO_start_file can still be associated to the base file. */
23772 mac_ptr
= section
->buffer
+ offset
;
23773 mac_end
= section
->buffer
+ section
->size
;
23775 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23776 &offset_size
, section_is_gnu
);
23777 if (mac_ptr
== NULL
)
23779 /* We already issued a complaint. */
23785 /* Do we at least have room for a macinfo type byte? */
23786 if (mac_ptr
>= mac_end
)
23788 /* Complaint is printed during the second pass as GDB will probably
23789 stop the first pass earlier upon finding
23790 DW_MACINFO_start_file. */
23794 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23797 /* Note that we rely on the fact that the corresponding GNU and
23798 DWARF constants are the same. */
23800 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23801 switch (macinfo_type
)
23803 /* A zero macinfo type indicates the end of the macro
23808 case DW_MACRO_define
:
23809 case DW_MACRO_undef
:
23810 /* Only skip the data by MAC_PTR. */
23812 unsigned int bytes_read
;
23814 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23815 mac_ptr
+= bytes_read
;
23816 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23817 mac_ptr
+= bytes_read
;
23821 case DW_MACRO_start_file
:
23823 unsigned int bytes_read
;
23826 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23827 mac_ptr
+= bytes_read
;
23828 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23829 mac_ptr
+= bytes_read
;
23831 current_file
= macro_start_file (builder
, file
, line
,
23836 case DW_MACRO_end_file
:
23837 /* No data to skip by MAC_PTR. */
23840 case DW_MACRO_define_strp
:
23841 case DW_MACRO_undef_strp
:
23842 case DW_MACRO_define_sup
:
23843 case DW_MACRO_undef_sup
:
23845 unsigned int bytes_read
;
23847 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23848 mac_ptr
+= bytes_read
;
23849 mac_ptr
+= offset_size
;
23853 case DW_MACRO_import
:
23854 case DW_MACRO_import_sup
:
23855 /* Note that, according to the spec, a transparent include
23856 chain cannot call DW_MACRO_start_file. So, we can just
23857 skip this opcode. */
23858 mac_ptr
+= offset_size
;
23861 case DW_MACINFO_vendor_ext
:
23862 /* Only skip the data by MAC_PTR. */
23863 if (!section_is_gnu
)
23865 unsigned int bytes_read
;
23867 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23868 mac_ptr
+= bytes_read
;
23869 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23870 mac_ptr
+= bytes_read
;
23875 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23876 mac_ptr
, mac_end
, abfd
, offset_size
,
23878 if (mac_ptr
== NULL
)
23883 } while (macinfo_type
!= 0 && current_file
== NULL
);
23885 /* Second pass: Process all entries.
23887 Use the AT_COMMAND_LINE flag to determine whether we are still processing
23888 command-line macro definitions/undefinitions. This flag is unset when we
23889 reach the first DW_MACINFO_start_file entry. */
23891 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
23893 NULL
, xcalloc
, xfree
));
23894 mac_ptr
= section
->buffer
+ offset
;
23895 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
23896 *slot
= (void *) mac_ptr
;
23897 dwarf_decode_macro_bytes (dwarf2_per_objfile
, builder
,
23898 abfd
, mac_ptr
, mac_end
,
23899 current_file
, lh
, section
,
23900 section_is_gnu
, 0, offset_size
,
23901 include_hash
.get ());
23904 /* An overload of dwarf_decode_macros that finds the correct section
23905 and ensures it is read in before calling the other overload. */
23908 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23909 int section_is_gnu
)
23911 struct dwarf2_per_objfile
*dwarf2_per_objfile
23912 = cu
->per_cu
->dwarf2_per_objfile
;
23913 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23914 struct line_header
*lh
= cu
->line_header
;
23915 unsigned int offset_size
= cu
->header
.offset_size
;
23916 struct dwarf2_section_info
*section
;
23917 const char *section_name
;
23919 if (cu
->dwo_unit
!= nullptr)
23921 if (section_is_gnu
)
23923 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23924 section_name
= ".debug_macro.dwo";
23928 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23929 section_name
= ".debug_macinfo.dwo";
23934 if (section_is_gnu
)
23936 section
= &dwarf2_per_objfile
->macro
;
23937 section_name
= ".debug_macro";
23941 section
= &dwarf2_per_objfile
->macinfo
;
23942 section_name
= ".debug_macinfo";
23946 section
->read (objfile
);
23947 if (section
->buffer
== nullptr)
23949 complaint (_("missing %s section"), section_name
);
23953 buildsym_compunit
*builder
= cu
->get_builder ();
23955 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23956 offset_size
, offset
, section_is_gnu
);
23959 /* Return the .debug_loc section to use for CU.
23960 For DWO files use .debug_loc.dwo. */
23962 static struct dwarf2_section_info
*
23963 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23965 struct dwarf2_per_objfile
*dwarf2_per_objfile
23966 = cu
->per_cu
->dwarf2_per_objfile
;
23970 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23972 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23974 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23975 : &dwarf2_per_objfile
->loc
);
23978 /* A helper function that fills in a dwarf2_loclist_baton. */
23981 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23982 struct dwarf2_loclist_baton
*baton
,
23983 const struct attribute
*attr
)
23985 struct dwarf2_per_objfile
*dwarf2_per_objfile
23986 = cu
->per_cu
->dwarf2_per_objfile
;
23987 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23989 section
->read (dwarf2_per_objfile
->objfile
);
23991 baton
->per_cu
= cu
->per_cu
;
23992 gdb_assert (baton
->per_cu
);
23993 /* We don't know how long the location list is, but make sure we
23994 don't run off the edge of the section. */
23995 baton
->size
= section
->size
- DW_UNSND (attr
);
23996 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23997 baton
->base_address
= cu
->base_address
;
23998 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24002 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24003 struct dwarf2_cu
*cu
, int is_block
)
24005 struct dwarf2_per_objfile
*dwarf2_per_objfile
24006 = cu
->per_cu
->dwarf2_per_objfile
;
24007 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24008 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24010 if (attr
->form_is_section_offset ()
24011 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24012 the section. If so, fall through to the complaint in the
24014 && DW_UNSND (attr
) < section
->get_size (objfile
))
24016 struct dwarf2_loclist_baton
*baton
;
24018 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24020 fill_in_loclist_baton (cu
, baton
, attr
);
24022 if (cu
->base_known
== 0)
24023 complaint (_("Location list used without "
24024 "specifying the CU base address."));
24026 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24027 ? dwarf2_loclist_block_index
24028 : dwarf2_loclist_index
);
24029 SYMBOL_LOCATION_BATON (sym
) = baton
;
24033 struct dwarf2_locexpr_baton
*baton
;
24035 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24036 baton
->per_cu
= cu
->per_cu
;
24037 gdb_assert (baton
->per_cu
);
24039 if (attr
->form_is_block ())
24041 /* Note that we're just copying the block's data pointer
24042 here, not the actual data. We're still pointing into the
24043 info_buffer for SYM's objfile; right now we never release
24044 that buffer, but when we do clean up properly this may
24046 baton
->size
= DW_BLOCK (attr
)->size
;
24047 baton
->data
= DW_BLOCK (attr
)->data
;
24051 dwarf2_invalid_attrib_class_complaint ("location description",
24052 sym
->natural_name ());
24056 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24057 ? dwarf2_locexpr_block_index
24058 : dwarf2_locexpr_index
);
24059 SYMBOL_LOCATION_BATON (sym
) = baton
;
24066 dwarf2_per_cu_data::objfile () const
24068 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24070 /* Return the master objfile, so that we can report and look up the
24071 correct file containing this variable. */
24072 if (objfile
->separate_debug_objfile_backlink
)
24073 objfile
= objfile
->separate_debug_objfile_backlink
;
24078 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24079 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24080 CU_HEADERP first. */
24082 static const struct comp_unit_head
*
24083 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24084 const struct dwarf2_per_cu_data
*per_cu
)
24086 const gdb_byte
*info_ptr
;
24089 return &per_cu
->cu
->header
;
24091 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24093 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24094 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24095 rcuh_kind::COMPILE
);
24103 dwarf2_per_cu_data::addr_size () const
24105 struct comp_unit_head cu_header_local
;
24106 const struct comp_unit_head
*cu_headerp
;
24108 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24110 return cu_headerp
->addr_size
;
24116 dwarf2_per_cu_data::offset_size () const
24118 struct comp_unit_head cu_header_local
;
24119 const struct comp_unit_head
*cu_headerp
;
24121 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24123 return cu_headerp
->offset_size
;
24129 dwarf2_per_cu_data::ref_addr_size () const
24131 struct comp_unit_head cu_header_local
;
24132 const struct comp_unit_head
*cu_headerp
;
24134 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24136 if (cu_headerp
->version
== 2)
24137 return cu_headerp
->addr_size
;
24139 return cu_headerp
->offset_size
;
24145 dwarf2_per_cu_data::text_offset () const
24147 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24149 return objfile
->text_section_offset ();
24155 dwarf2_per_cu_data::addr_type () const
24157 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24158 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24159 struct type
*addr_type
= lookup_pointer_type (void_type
);
24160 int addr_size
= this->addr_size ();
24162 if (TYPE_LENGTH (addr_type
) == addr_size
)
24165 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
24169 /* A helper function for dwarf2_find_containing_comp_unit that returns
24170 the index of the result, and that searches a vector. It will
24171 return a result even if the offset in question does not actually
24172 occur in any CU. This is separate so that it can be unit
24176 dwarf2_find_containing_comp_unit
24177 (sect_offset sect_off
,
24178 unsigned int offset_in_dwz
,
24179 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24184 high
= all_comp_units
.size () - 1;
24187 struct dwarf2_per_cu_data
*mid_cu
;
24188 int mid
= low
+ (high
- low
) / 2;
24190 mid_cu
= all_comp_units
[mid
];
24191 if (mid_cu
->is_dwz
> offset_in_dwz
24192 || (mid_cu
->is_dwz
== offset_in_dwz
24193 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24198 gdb_assert (low
== high
);
24202 /* Locate the .debug_info compilation unit from CU's objfile which contains
24203 the DIE at OFFSET. Raises an error on failure. */
24205 static struct dwarf2_per_cu_data
*
24206 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24207 unsigned int offset_in_dwz
,
24208 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24211 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
24212 dwarf2_per_objfile
->all_comp_units
);
24213 struct dwarf2_per_cu_data
*this_cu
24214 = dwarf2_per_objfile
->all_comp_units
[low
];
24216 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24218 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24219 error (_("Dwarf Error: could not find partial DIE containing "
24220 "offset %s [in module %s]"),
24221 sect_offset_str (sect_off
),
24222 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24224 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24226 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24230 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24231 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24232 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24233 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24240 namespace selftests
{
24241 namespace find_containing_comp_unit
{
24246 struct dwarf2_per_cu_data one
{};
24247 struct dwarf2_per_cu_data two
{};
24248 struct dwarf2_per_cu_data three
{};
24249 struct dwarf2_per_cu_data four
{};
24252 two
.sect_off
= sect_offset (one
.length
);
24257 four
.sect_off
= sect_offset (three
.length
);
24261 std::vector
<dwarf2_per_cu_data
*> units
;
24262 units
.push_back (&one
);
24263 units
.push_back (&two
);
24264 units
.push_back (&three
);
24265 units
.push_back (&four
);
24269 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24270 SELF_CHECK (units
[result
] == &one
);
24271 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24272 SELF_CHECK (units
[result
] == &one
);
24273 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24274 SELF_CHECK (units
[result
] == &two
);
24276 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24277 SELF_CHECK (units
[result
] == &three
);
24278 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24279 SELF_CHECK (units
[result
] == &three
);
24280 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24281 SELF_CHECK (units
[result
] == &four
);
24287 #endif /* GDB_SELF_TEST */
24289 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24291 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24292 : per_cu (per_cu_
),
24294 has_loclist (false),
24295 checked_producer (false),
24296 producer_is_gxx_lt_4_6 (false),
24297 producer_is_gcc_lt_4_3 (false),
24298 producer_is_icc (false),
24299 producer_is_icc_lt_14 (false),
24300 producer_is_codewarrior (false),
24301 processing_has_namespace_info (false)
24306 /* Destroy a dwarf2_cu. */
24308 dwarf2_cu::~dwarf2_cu ()
24313 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24316 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24317 enum language pretend_language
)
24319 struct attribute
*attr
;
24321 /* Set the language we're debugging. */
24322 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24323 if (attr
!= nullptr)
24324 set_cu_language (DW_UNSND (attr
), cu
);
24327 cu
->language
= pretend_language
;
24328 cu
->language_defn
= language_def (cu
->language
);
24331 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24334 /* Increase the age counter on each cached compilation unit, and free
24335 any that are too old. */
24338 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24340 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24342 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24343 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24344 while (per_cu
!= NULL
)
24346 per_cu
->cu
->last_used
++;
24347 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24348 dwarf2_mark (per_cu
->cu
);
24349 per_cu
= per_cu
->cu
->read_in_chain
;
24352 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24353 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24354 while (per_cu
!= NULL
)
24356 struct dwarf2_per_cu_data
*next_cu
;
24358 next_cu
= per_cu
->cu
->read_in_chain
;
24360 if (!per_cu
->cu
->mark
)
24363 *last_chain
= next_cu
;
24366 last_chain
= &per_cu
->cu
->read_in_chain
;
24372 /* Remove a single compilation unit from the cache. */
24375 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24377 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24378 struct dwarf2_per_objfile
*dwarf2_per_objfile
24379 = target_per_cu
->dwarf2_per_objfile
;
24381 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24382 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24383 while (per_cu
!= NULL
)
24385 struct dwarf2_per_cu_data
*next_cu
;
24387 next_cu
= per_cu
->cu
->read_in_chain
;
24389 if (per_cu
== target_per_cu
)
24393 *last_chain
= next_cu
;
24397 last_chain
= &per_cu
->cu
->read_in_chain
;
24403 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24404 We store these in a hash table separate from the DIEs, and preserve them
24405 when the DIEs are flushed out of cache.
24407 The CU "per_cu" pointer is needed because offset alone is not enough to
24408 uniquely identify the type. A file may have multiple .debug_types sections,
24409 or the type may come from a DWO file. Furthermore, while it's more logical
24410 to use per_cu->section+offset, with Fission the section with the data is in
24411 the DWO file but we don't know that section at the point we need it.
24412 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24413 because we can enter the lookup routine, get_die_type_at_offset, from
24414 outside this file, and thus won't necessarily have PER_CU->cu.
24415 Fortunately, PER_CU is stable for the life of the objfile. */
24417 struct dwarf2_per_cu_offset_and_type
24419 const struct dwarf2_per_cu_data
*per_cu
;
24420 sect_offset sect_off
;
24424 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24427 per_cu_offset_and_type_hash (const void *item
)
24429 const struct dwarf2_per_cu_offset_and_type
*ofs
24430 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24432 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24435 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24438 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24440 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24441 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24442 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24443 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24445 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24446 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24449 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24450 table if necessary. For convenience, return TYPE.
24452 The DIEs reading must have careful ordering to:
24453 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24454 reading current DIE.
24455 * Not trying to dereference contents of still incompletely read in types
24456 while reading in other DIEs.
24457 * Enable referencing still incompletely read in types just by a pointer to
24458 the type without accessing its fields.
24460 Therefore caller should follow these rules:
24461 * Try to fetch any prerequisite types we may need to build this DIE type
24462 before building the type and calling set_die_type.
24463 * After building type call set_die_type for current DIE as soon as
24464 possible before fetching more types to complete the current type.
24465 * Make the type as complete as possible before fetching more types. */
24467 static struct type
*
24468 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24470 struct dwarf2_per_objfile
*dwarf2_per_objfile
24471 = cu
->per_cu
->dwarf2_per_objfile
;
24472 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24473 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24474 struct attribute
*attr
;
24475 struct dynamic_prop prop
;
24477 /* For Ada types, make sure that the gnat-specific data is always
24478 initialized (if not already set). There are a few types where
24479 we should not be doing so, because the type-specific area is
24480 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24481 where the type-specific area is used to store the floatformat).
24482 But this is not a problem, because the gnat-specific information
24483 is actually not needed for these types. */
24484 if (need_gnat_info (cu
)
24485 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24486 && TYPE_CODE (type
) != TYPE_CODE_FLT
24487 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24488 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24489 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24490 && !HAVE_GNAT_AUX_INFO (type
))
24491 INIT_GNAT_SPECIFIC (type
);
24493 /* Read DW_AT_allocated and set in type. */
24494 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24495 if (attr
!= NULL
&& attr
->form_is_block ())
24497 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24498 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24499 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24501 else if (attr
!= NULL
)
24503 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24504 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24505 sect_offset_str (die
->sect_off
));
24508 /* Read DW_AT_associated and set in type. */
24509 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24510 if (attr
!= NULL
&& attr
->form_is_block ())
24512 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24513 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24514 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24516 else if (attr
!= NULL
)
24518 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24519 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24520 sect_offset_str (die
->sect_off
));
24523 /* Read DW_AT_data_location and set in type. */
24524 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24525 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24526 cu
->per_cu
->addr_type ()))
24527 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24529 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24530 dwarf2_per_objfile
->die_type_hash
24531 = htab_up (htab_create_alloc (127,
24532 per_cu_offset_and_type_hash
,
24533 per_cu_offset_and_type_eq
,
24534 NULL
, xcalloc
, xfree
));
24536 ofs
.per_cu
= cu
->per_cu
;
24537 ofs
.sect_off
= die
->sect_off
;
24539 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24540 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24542 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24543 sect_offset_str (die
->sect_off
));
24544 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24545 struct dwarf2_per_cu_offset_and_type
);
24550 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24551 or return NULL if the die does not have a saved type. */
24553 static struct type
*
24554 get_die_type_at_offset (sect_offset sect_off
,
24555 struct dwarf2_per_cu_data
*per_cu
)
24557 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24558 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24560 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24563 ofs
.per_cu
= per_cu
;
24564 ofs
.sect_off
= sect_off
;
24565 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24566 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24573 /* Look up the type for DIE in CU in die_type_hash,
24574 or return NULL if DIE does not have a saved type. */
24576 static struct type
*
24577 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24579 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24582 /* Add a dependence relationship from CU to REF_PER_CU. */
24585 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24586 struct dwarf2_per_cu_data
*ref_per_cu
)
24590 if (cu
->dependencies
== NULL
)
24592 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24593 NULL
, &cu
->comp_unit_obstack
,
24594 hashtab_obstack_allocate
,
24595 dummy_obstack_deallocate
);
24597 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24599 *slot
= ref_per_cu
;
24602 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24603 Set the mark field in every compilation unit in the
24604 cache that we must keep because we are keeping CU. */
24607 dwarf2_mark_helper (void **slot
, void *data
)
24609 struct dwarf2_per_cu_data
*per_cu
;
24611 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24613 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24614 reading of the chain. As such dependencies remain valid it is not much
24615 useful to track and undo them during QUIT cleanups. */
24616 if (per_cu
->cu
== NULL
)
24619 if (per_cu
->cu
->mark
)
24621 per_cu
->cu
->mark
= true;
24623 if (per_cu
->cu
->dependencies
!= NULL
)
24624 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24629 /* Set the mark field in CU and in every other compilation unit in the
24630 cache that we must keep because we are keeping CU. */
24633 dwarf2_mark (struct dwarf2_cu
*cu
)
24638 if (cu
->dependencies
!= NULL
)
24639 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24643 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24647 per_cu
->cu
->mark
= false;
24648 per_cu
= per_cu
->cu
->read_in_chain
;
24652 /* Trivial hash function for partial_die_info: the hash value of a DIE
24653 is its offset in .debug_info for this objfile. */
24656 partial_die_hash (const void *item
)
24658 const struct partial_die_info
*part_die
24659 = (const struct partial_die_info
*) item
;
24661 return to_underlying (part_die
->sect_off
);
24664 /* Trivial comparison function for partial_die_info structures: two DIEs
24665 are equal if they have the same offset. */
24668 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24670 const struct partial_die_info
*part_die_lhs
24671 = (const struct partial_die_info
*) item_lhs
;
24672 const struct partial_die_info
*part_die_rhs
24673 = (const struct partial_die_info
*) item_rhs
;
24675 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24678 struct cmd_list_element
*set_dwarf_cmdlist
;
24679 struct cmd_list_element
*show_dwarf_cmdlist
;
24682 set_dwarf_cmd (const char *args
, int from_tty
)
24684 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24689 show_dwarf_cmd (const char *args
, int from_tty
)
24691 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24695 show_check_physname (struct ui_file
*file
, int from_tty
,
24696 struct cmd_list_element
*c
, const char *value
)
24698 fprintf_filtered (file
,
24699 _("Whether to check \"physname\" is %s.\n"),
24703 void _initialize_dwarf2_read ();
24705 _initialize_dwarf2_read ()
24707 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24708 Set DWARF specific variables.\n\
24709 Configure DWARF variables such as the cache size."),
24710 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24711 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24713 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24714 Show DWARF specific variables.\n\
24715 Show DWARF variables such as the cache size."),
24716 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24717 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24719 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24720 &dwarf_max_cache_age
, _("\
24721 Set the upper bound on the age of cached DWARF compilation units."), _("\
24722 Show the upper bound on the age of cached DWARF compilation units."), _("\
24723 A higher limit means that cached compilation units will be stored\n\
24724 in memory longer, and more total memory will be used. Zero disables\n\
24725 caching, which can slow down startup."),
24727 show_dwarf_max_cache_age
,
24728 &set_dwarf_cmdlist
,
24729 &show_dwarf_cmdlist
);
24731 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24732 Set debugging of the DWARF reader."), _("\
24733 Show debugging of the DWARF reader."), _("\
24734 When enabled (non-zero), debugging messages are printed during DWARF\n\
24735 reading and symtab expansion. A value of 1 (one) provides basic\n\
24736 information. A value greater than 1 provides more verbose information."),
24739 &setdebuglist
, &showdebuglist
);
24741 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24742 Set debugging of the DWARF DIE reader."), _("\
24743 Show debugging of the DWARF DIE reader."), _("\
24744 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24745 The value is the maximum depth to print."),
24748 &setdebuglist
, &showdebuglist
);
24750 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24751 Set debugging of the dwarf line reader."), _("\
24752 Show debugging of the dwarf line reader."), _("\
24753 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24754 A value of 1 (one) provides basic information.\n\
24755 A value greater than 1 provides more verbose information."),
24758 &setdebuglist
, &showdebuglist
);
24760 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24761 Set cross-checking of \"physname\" code against demangler."), _("\
24762 Show cross-checking of \"physname\" code against demangler."), _("\
24763 When enabled, GDB's internal \"physname\" code is checked against\n\
24765 NULL
, show_check_physname
,
24766 &setdebuglist
, &showdebuglist
);
24768 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24769 no_class
, &use_deprecated_index_sections
, _("\
24770 Set whether to use deprecated gdb_index sections."), _("\
24771 Show whether to use deprecated gdb_index sections."), _("\
24772 When enabled, deprecated .gdb_index sections are used anyway.\n\
24773 Normally they are ignored either because of a missing feature or\n\
24774 performance issue.\n\
24775 Warning: This option must be enabled before gdb reads the file."),
24778 &setlist
, &showlist
);
24780 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24781 &dwarf2_locexpr_funcs
);
24782 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24783 &dwarf2_loclist_funcs
);
24785 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24786 &dwarf2_block_frame_base_locexpr_funcs
);
24787 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24788 &dwarf2_block_frame_base_loclist_funcs
);
24791 selftests::register_test ("dw2_expand_symtabs_matching",
24792 selftests::dw2_expand_symtabs_matching::run_test
);
24793 selftests::register_test ("dwarf2_find_containing_comp_unit",
24794 selftests::find_containing_comp_unit::run_test
);